Newegg cart to post converter for eggxpert.com

Converts the cart in to postable html that has been patched for the forums

  1. // ==UserScript==
  2. // @name Newegg cart to post converter for eggxpert.com
  3. // @namespace http://userscripts.org/users/62850
  4. // @description Converts the cart in to postable html that has been patched for the forums
  5. // @include http://secure.newegg.com/Shopping/ShoppingCart.aspx*
  6. // @include http://secure.newegg.ca/Shopping/ShoppingCart.aspx*
  7. // @include https://secure.newegg.com/Shopping/ShoppingCart.aspx*
  8. // @include https://secure.newegg.ca/Shopping/ShoppingCart.aspx*
  9. // @version 3.7.2
  10. // @grant none
  11. // ==/UserScript==
  12. function addCommas(nStr){//http://www.mredkj.com/javascript/nfbasic.html
  13. nStr += '';
  14. x = nStr.split('.');
  15. x1 = x[0];
  16. x2 = x.length > 1 ? '.' + x[1] : '';
  17. var rgx = /(\d+)(\d{3})/;
  18. while (rgx.test(x1)) {
  19. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  20. }
  21. return x1 + x2;
  22. }
  23. function getURL(findMe,txt=location.search){
  24. if(txt){
  25. txt=txt.slice(txt.indexOf('?')+1);
  26. var l=txt.indexOf('#');
  27. if(l>-1)
  28. txt=txt.slice(0,l);
  29. txt=txt.slice(txt.indexOf(findMe+'='));
  30. l=txt.indexOf('&');
  31. txt=txt.slice(findMe.length+1,l!=-1?l:void(0));
  32. return decodeURIComponent(txt.replace(/\+/g,'%20'));
  33. }
  34. return false;
  35. }
  36. function findEle(target,i,e){
  37. if(i==9)
  38. return document.evaluate(target, e?e:document, null, i, null).singleNodeValue;
  39. else
  40. return document.evaluate(target, e?e:document, null, i, null);
  41. }
  42. function make(tag){
  43. return document.createElement(tag);
  44. }
  45. function makeTXT(txt){
  46. return document.createTextNode(txt);
  47. }
  48. function genDivBox(table){
  49. var div=make('div'),
  50. child=make('div');
  51. child2=make('a');
  52. div.style.height=findEle('.//body/div[@id="container"]',9,false).offsetHeight+'px';
  53. div.id="GM_alert";
  54. child.addEventListener('click',function(){
  55. document.body.removeChild(findEle('.//body/div[@id="GM_alert"]',9,false));
  56. },false);
  57. child.textContent="X";
  58. child.className="close";
  59. child.title="Close";
  60. div.appendChild(child);
  61. child=make('div');
  62. child.appendChild(makeTXT('If you would like to readable HTML code, paste it in the '));
  63. child2.href="http://tools.arantius.com/tabifier";
  64. child2.textContent='Tabifier';
  65. child2.target="_blank";
  66. child.appendChild(child2);
  67. child.appendChild(makeTXT('.'));
  68. child.appendChild(make('br'));
  69. child2=make('input');
  70. child2.setAttribute('readonly','readonly');
  71. child2.setAttribute('onclick','this.select();');
  72. child2.value=table.outerHTML;
  73. child.appendChild(child2);
  74. child.appendChild(makeTXT('Copy & Paste the above code.'));
  75. child.appendChild(make('br'));
  76. child2=make('fieldset');
  77. child2.innerHTML='<legend>Preview</legend>';
  78. child.appendChild(make('center'));
  79. child.childNodes[child.childNodes.length-1].appendChild(child2);
  80. div.appendChild(child);
  81. child2.appendChild(table);
  82. document.body.appendChild(div);
  83. }
  84. var holder=findEle('.//table[@class="head"]/thead/tr/th[@align="right"]',9,false),btn,style;
  85. if(holder){
  86. btn=make('a');
  87. btn.className='button button-mini button-tertiary';
  88. btn.href="javascript:void(false)";
  89. btn.textContent='Generate HTML Code';
  90. btn.title="HTML code for posting on forums";
  91. btn.addEventListener('click',function(){
  92. var table,tbody,tr,td,div,img,uri,
  93. i,cart,item,val,a,txt,IMG,price,
  94. items=Array(),mir=Array(),
  95. redirect='evilkitty.duckdns.org/neweggAdd2Cart.php?i=',//ITEM|Qty
  96. direct='secure.newegg.com/Shopping/AddToCart.aspx?Submit=ADD&ItemList=',//ITEM|Qty,ITEM|Qty
  97. workaround=confirm("Re-write 'add to cart link' to make them work on community.newegg.com?\nLinks will run through 3ed party server.");
  98. table=make('table');
  99. table.border=1;
  100. table.appendChild(make('tbody'));
  101. tbody=table.childNodes[0];
  102. tr=make('tr');
  103. tr.align="center";
  104. td=make('th');
  105. td.textContent='Item';
  106. td.setAttribute('colspan',2);
  107. tr.appendChild(td);
  108. td=make('th');
  109. td.textContent='Quantity';
  110. tr.appendChild(td);
  111. td=make('th');
  112. td.textContent='Price';
  113. tr.appendChild(td);
  114. tbody.appendChild(tr);
  115. cart=findEle('.//table[contains(@class,"shipping-group")]/tbody/tr',6);
  116. for(i=0;i<cart.snapshotLength;i++){
  117. item=cart.snapshotItem(i);
  118. tr=make('tr');
  119.  
  120. td=make('td');
  121. img=make('img');
  122. IMG=findEle('./td/div/a/img[@class="l-block product-image"]',9,item);
  123. img.src=IMG.src;
  124. td.appendChild(img);
  125. tr.appendChild(td);
  126.  
  127. td=make('td');
  128. a=make('a');
  129. a.href=IMG.parentNode.href;
  130. a.target="_blank";
  131. a.textContent=IMG.parentNode.title;
  132. td.appendChild(a);
  133. tr.appendChild(td);
  134.  
  135. td=make('td');
  136. td.align='center';
  137. txt=findEle('./td[@width="50px"]/input',9,item);
  138. td.textContent=txt?txt.value:findEle('./td[@width="50px"]/div',9,item).textContent;
  139. tr.appendChild(td);
  140.  
  141. txt=td.textContent;
  142.  
  143. td=make('td');
  144. td.align="right";
  145. price=findEle('./td[@align="right"]//li[starts-with(@class,"price-current")]',9,item);
  146. if(price){
  147. uri=getURL('Item',a.href);
  148. if(!uri){
  149. uri=getURL('ItemList',a.href);
  150. }
  151. a=uri;
  152. items.push(a+(workaround?',':'|')+txt);
  153.  
  154. td.textContent=price.textContent.replace(/(\s|\t|\n)/g,'');
  155. a=make('a');
  156. a.target="_blank";
  157. a.textContent='Add to cart';
  158. a.href='http://'+(workaround?redirect:direct)+items[items.length-1];
  159. td.appendChild(make('br'));
  160. td.appendChild(a);
  161. }
  162. else{
  163. txt=findEle('./td[@align="right"]//li[starts-with(@class,"price-current")]',9,item);
  164. if(txt){
  165. td.textContent=txt.textContent.replace(/(\s|\t|\n)/g,'');
  166. td.appendChild(make('br'));
  167. }
  168. td.appendChild(makeTXT("Combo Item"));
  169. }
  170. tr.appendChild(td);
  171.  
  172. txt=findEle('./td[@align="right"]//li[starts-with(@class,"price-note")]//a[contains(@title,"Mail In Rebate")]',9,item);
  173. if(txt){
  174. a=make('a');
  175. a.target="_blank";
  176. a.href=txt.href;
  177. a.title=a.href.slice(a.href.lastIndexOf('/')+1);
  178. txt=txt.textContent+' Rebate';
  179. txt=txt.slice(0,txt.indexOf(' '));
  180. a.textContent=txt;
  181. mir.push(a);
  182. }
  183.  
  184. tbody.appendChild(tr);
  185. }
  186. tr=make('tr');
  187.  
  188. td=make('td');
  189. td.setAttribute('colspan',3);
  190. td.textContent="Subtotal:";
  191. tr.appendChild(td);
  192. txt=findEle('.//table[contains(@class,"shipping-group")]/tfoot//span[@class="amount"]',6,false);
  193. td=make('td');
  194. val=0;
  195. for(i=0;i<txt.snapshotLength;i=i+2){
  196. val+=Number(txt.snapshotItem(i).textContent.replace(/(\$|\s|\t|\n|,)/g,''));
  197. }
  198. td.textContent='$'+addCommas(val.toFixed(2));
  199. td.align="right";
  200. tr.appendChild(td);
  201.  
  202. tbody.appendChild(tr);
  203. tr=make('tr');
  204.  
  205. td=make('td');
  206. td.setAttribute('colspan',3);
  207. td.textContent="Shipping + Tax:";
  208. tr.appendChild(td);
  209.  
  210. td=make('td');
  211. td.align="right";
  212. val=0;
  213. for(i=1;i<txt.snapshotLength;i=i+2){
  214. val+=Number(txt.snapshotItem(i).textContent.replace(/(\$|\s|\t|\n|,)/g,''));
  215. }
  216. td.textContent='$'+addCommas(val.toFixed(2));
  217. tr.appendChild(td);
  218. tbody.appendChild(tr);
  219.  
  220. cart=findEle('.//table[@class="applied-code"]/tbody/tr',6,false);
  221. for(i=0;i<cart.snapshotLength;i++){
  222. try{
  223. tr=make('tr');
  224. item=cart.snapshotItem(i);
  225. td=make('td');
  226. td.setAttribute('colspan',3);
  227. td.textContent='Promo Code: '+findEle('./td/strong',9,item).textContent;
  228. tr.appendChild(td);
  229. td=make('td');
  230. td.align='right';
  231. td.textContent=findEle('./td[@class="discount"]',9,item).textContent;
  232. tr.appendChild(td);
  233. tbody.appendChild(tr);
  234. }
  235. catch(e){
  236. continue;
  237. }
  238. }
  239. tr=make('tr');
  240.  
  241. td=make('td');
  242. td.setAttribute('colspan',3);
  243. td.textContent="Grand Total:";
  244. tr.appendChild(td);
  245.  
  246. td=make('td');
  247. td.align="right";
  248. td.textContent=findEle('.//td[@class="grand-total"]/span[@class="amount"]',9,false).textContent.replace(/(\s|\t|\n)/g,'');
  249. tr.appendChild(td);
  250.  
  251. tbody.appendChild(tr);
  252. tr=make('tr');
  253. if(mir.length>0){
  254. td=make('td');
  255. td.setAttribute('colspan',2);
  256. td.appendChild(makeTXT(mir.length>1?'There are '+mir.length+' Mail-in Rebates: ':'There is '+mir.length+' Mail-in Rebate: '));
  257. for(i=0;i<mir.length;i++){
  258. td.appendChild(mir[i]);
  259. if(i+1<mir.length){
  260. td.appendChild(makeTXT(" | "));
  261. }
  262. }
  263. tr.appendChild(td);
  264. }
  265.  
  266. a=make('a');
  267. a.target="_blank";
  268. a.href='http://'+(workaround?redirect:direct)+items.join(',');
  269. a.textContent='Add all to cart';
  270. td=make('td');
  271. td.align='right';
  272. td.setAttribute('colspan',mir.length>0?2:4);
  273. td.appendChild(a)
  274. tr.appendChild(td);
  275. tbody.appendChild(tr);
  276.  
  277. genDivBox(table);
  278. window.scrollTo(0,0);
  279. },false);
  280. holder.insertBefore(btn,holder.childNodes[0]);
  281. }
  282. style=make('style');
  283. style.type="text/css";
  284. style.textContent='\
  285. #GM_alert{\
  286. position:absolute;\
  287. top:0;\
  288. left:0;\
  289. width:calc(100% - 60px);\
  290. background-color:rgba(0,0,0,0.5);\
  291. padding:30px;\
  292. z-index:9001;\
  293. }\
  294. #GM_alert a{\
  295. color:blue;\
  296. }\
  297. #GM_alert .close{\
  298. background-color:red;\
  299. width:24px;\
  300. height:24px;\
  301. position:absolute;\
  302. right:3px;\
  303. top:3px;\
  304. border:1px solid white;\
  305. color:white;\
  306. border-radius:5px;\
  307. font-family:monospace;\
  308. font-size:21px;\
  309. text-align:center;\
  310. cursor:pointer;\
  311. }\
  312. #GM_alert > div:not(.close){\
  313. border-radius:5px;\
  314. background-color:#FFF;\
  315. padding:10px;\
  316. }\
  317. #GM_alert fieldset{\
  318. display:inline;\
  319. border-radius:5px;\
  320. text-align:left;\
  321. }\
  322. #GM_alert > div > input{\
  323. width:calc(100% - 9px);\
  324. }\
  325. #GM_alert table{\
  326. margin:0;\
  327. border:1px outset;\
  328. }\
  329. #GM_alert td, #GM_alert th{\
  330. border:1px inset;\
  331. padding:0;\
  332. }';
  333. document.head.appendChild(style);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址