Newegg.com: Show the Hidden Prices

Never be annoyed with hidden prices on newegg.com again :)

  1. // ==UserScript==
  2. // @name Newegg.com: Show the Hidden Prices
  3. // @description Never be annoyed with hidden prices on newegg.com again :)
  4. // @version 3.3.1
  5. // @include http://www.newegg.tld/*
  6. // @namespace https://gf.qytechs.cn/users/2178
  7. // ==/UserScript==
  8. /* Script badly broken, working of fix this contains what I have so far, better than nothing, the old awesome version is commended out if you want to work on fixing it
  9. function getURL(findMe,txt){
  10. if(txt){
  11. txt=txt.slice(1);
  12. txt=txt.slice(txt.indexOf(findMe+'='));
  13. var l=txt.indexOf('&');
  14. if(l!=-1){
  15. return txt.slice(findMe.length+1,l);
  16. }
  17. else{
  18. return txt.slice(findMe.length+1);
  19. }
  20. }
  21. return null;
  22. }*/
  23. function addCommas(nStr){// http://www.mredkj.com/javascript/nfbasic.html
  24. nStr += '';
  25. x = nStr.split('.');
  26. x1 = x[0];
  27. x2 = x.length > 1 ? '.' + x[1] : '';
  28. var rgx = /(\d+)(\d{3})/;
  29. while (rgx.test(x1)) {
  30. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  31. }
  32. return x1 + x2;
  33. }/*
  34. function roundNumber(num, dec){// http://forums.devarticles.com/showpost.php?p=71368&postcount=2
  35. return Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
  36. }
  37. function comboPriceInCart(e,combo){
  38. GM_xmlhttpRequest({
  39. method: "GET",
  40. url: 'http://www.newegg.com/Product/MappingPrice.aspx?ComboID='+combo,
  41. onload: function(r){
  42. var save=r.responseText;
  43. save=save.substr(save.indexOf('<dd class="rebate">You Save: ')+29);
  44. save=save.substr(0,save.indexOf('</dd>'));
  45. e.parentNode.previousElementSibling.textContent='Discount: '+save;
  46. var price=r.responseText;
  47. price=price.substr(price.indexOf('<h3 class="zmp">')+16);
  48. price=price.slice(0,price.indexOf('</h3>')).replace(/[(\t\r\n\ ]/g,'');
  49. e.parentNode.innerHTML='<strong>Combo Price: '+price+'</strong>';
  50. }
  51. });
  52. }
  53. function comboPriceFinder(ele){
  54. if(document.evaluate("//table[@class='comboOverview']/tbody/tr/td[@class='price']/em",document,null,9,null).singleNodeValue){
  55. setTimeout(function(){
  56. comboPriceFinder(ele);
  57. },2000);
  58. }
  59. else{
  60. var prices=document.evaluate("//table[@class='comboOverview']/tbody/tr/td[@class='price']",document,null,6,null);
  61. var is=0;
  62. for(var i=prices.snapshotLength-1;i>-1;i--){
  63. is+=Number(prices.snapshotItem(i).textContent.replace(/[( \n\r\t\$,]/g,''));
  64. }
  65. insertComboPageHTML(roundNumber(is,2).toString(),ele);
  66. }
  67. }
  68. function fetchPrice(ITEM,ele,bool,comboList){
  69. if(bool){
  70. GM_xmlhttpRequest({
  71. method: "GET",
  72. url: 'http://www.newegg.com/Common/Ajax/RelationItemInfo.aspx?item='+ITEM+'&type=Newegg&_='+(new Date().getTime().toString().substring(0,10)),
  73. onload: function(price){
  74. price=price.responseText;
  75. price=price.substr(price.indexOf(ITEM+'$')+ITEM.length+1);
  76. price=price.slice(0,price.indexOf('">')).replace(/[(\n\r\t \$,]/g,'');
  77. if(Number(price)==price){
  78. if(comboList){
  79. ele.innerHTML='$'+addCommas(price);
  80. }
  81. else{
  82. insertProductPageHTML(ele,price.split('.'));
  83. }
  84. }
  85. else{
  86. GM_log('No price for '+ITEM+' advailable');
  87. }
  88. }
  89. });
  90. }
  91. else{
  92. if(ITEM.indexOf('Combo')!=-1){
  93. ITEM='ComboID='+ITEM;
  94. }
  95. else{
  96. ITEM='Item='+ITEM;
  97. }
  98. GM_xmlhttpRequest({// price in cart
  99. method: "GET",
  100. url: 'http://www.newegg.com/Product/MappingPrice.aspx?'+ITEM,
  101. onload: function(price){
  102. price=price.responseText;
  103. price=price.substr(price.indexOf('<h3 class="zmp">')+16);
  104. price=price.slice(0,price.indexOf('</h3>')).replace(/[(\t\r\n\$, ]/g,'');
  105. if(comboList){
  106. ele.innerHTML='$'+addCommas(price);
  107. }
  108. else{
  109. insertComboPageHTML(price,ele);
  110. }
  111. }
  112. });
  113. }
  114. }
  115. function insertComboPageHTML(is,ele){
  116. var tmp=document.getElementById('singleFinalPrice').nextElementSibling.cloneNode(true);
  117. insertProductPageHTML(ele,is.split('.'));
  118. ele.appendChild(tmp);
  119. tmp=tmp.innerHTML;
  120. var save=Number(tmp.replace(/,/g,'').substr(tmp.indexOf('$')+1));
  121. var was=addCommas(roundNumber(Number(is)+save,2));
  122. ele.previousElementSibling.innerHTML='<span class="label">Was: </span><span>$'+was+'</span>';
  123. var comboFoot=document.evaluate("//tfoot/tr[@class='grand_total']/td[@class='price']",document,null,9,null).singleNodeValue;
  124. comboFoot.innerHTML='$'+addCommas(is.indexOf('.')==-1?is+'.00':is);
  125. comboFoot=comboFoot.parentNode.parentNode;
  126. tmp=document.createElement('tr');
  127. tmp.innerHTML='<td colspan="2">Combo Discounts:</td><td class="price">-$'+addCommas(save.toString().indexOf('.')==-1?save+'.00':save)+'</td>';
  128. comboFoot.insertBefore(tmp,comboFoot.childNodes[0]);
  129. tmp=document.createElement('tr');
  130. tmp.innerHTML='<td colspan="2">Combined Total:</td><td class="price">$'+(was.indexOf('.')==-1?was+'.00':was)+'</td>';
  131. comboFoot.insertBefore(tmp,comboFoot.childNodes[0]);
  132. }
  133. function insertProductPageHTML(ele,item){
  134. var html='',ele2=ele.parentNode.childNodes[0];
  135. if(ele2.className=='original'){
  136. var p=Number(ele2.childNodes[1].textContent.substr(1).replace(/,/g,''))-Number(item[0].replace(/,/g,'')+'.'+item[1]);
  137. p=addCommas(roundNumber(p,2));
  138. html='<div class="original"><span class="label">Save: </span>$'+(p.indexOf('.')==-1?p+'.00':p)+'</div>';
  139. }
  140. ele.innerHTML='<div id="singleFinalPrice" class="current"><span class="label">Now: </span><span>$</span>'+addCommas(item[0])+'<sup>.'+item[1]+'</sup></div>'+html;
  141. }
  142. function showPrice(target){
  143. var price,eles=document.evaluate('//ul/li[@class="'+target+'"]',document,null,6,null);
  144. for(var i=eles.snapshotLength-1;i>-1;i--){
  145. price=eles.snapshotItem(i).parentNode;
  146. price=price.nextElementSibling.value.substr(1).split('.');
  147. eles.snapshotItem(i).innerHTML='<span class="label">Now: </span>$<strong>'+price[0]+'</strong><sup>.'+price[1]+'</sup>';
  148. eles.snapshotItem(i).className='priceFinal';
  149. }
  150. }
  151. function showPriceLoop(){// Timed loop is used cause DOMSubtreeModified will fire hundreds of times a second which is hell on slow systems
  152. showPrice('priceMAP');
  153. setTimeout(function(){
  154. showPriceLoop();
  155. },3250);
  156. }
  157. showPrice('priceRange');
  158. showPriceLoop();
  159.  
  160. var Item=getURL('Item',location.search),ele;
  161. if(!Item)
  162. Item=getURL('ItemList',location.search);
  163. if(Item){// Product Pages
  164. setTimeout(function(){
  165. ele=document.evaluate("//div[@class='wrapper']/a[@class='blkLink map']/em",document,null,9,null).singleNodeValue;
  166. if(ele){// Normal Item
  167. try{// Check page for price
  168. insertProductPageHTML(ele.parentNode.parentNode,document.evaluate("//div[starts-with(@rel,'"+Item+"')]",document,null,9,null).singleNodeValue.getAttribute('rel').split('$')[1].split('.'));
  169. }
  170. catch(e){// Price did not load on page in time or will not be loading; Now getting price my self
  171. fetchPrice(Item,ele.parentNode.parentNode,ele.textContent=="Click for Details",false);
  172. }
  173. }
  174. else{// Combo Item
  175. ele=document.evaluate("//div[@id='singleFinalPrice']/h3/a/em",document,null,9,null).singleNodeValue;
  176. var products=document.evaluate("//tr/td[@class='price']/em/../../td[@class='desc']/a",document,null,6,null);
  177. var prices=document.evaluate("//tr/td[@class='price']/em/..",document,null,6,null);
  178. if(ele.textContent=='See price in cart'){// Slightly Hidden
  179. fetchPrice(Item,ele.parentNode.parentNode.parentNode.parentNode,false,false);
  180. for(var i=products.snapshotLength-1;i>-1;i--){
  181. var id=products.snapshotItem(i).href;
  182. fetchPrice(getURL('Item',id.substr(id.indexOf('?'))),prices.snapshotItem(i),false,true);
  183. }
  184. var prices=document.evaluate("//tr/td[@class='price']",document,null,6,null);
  185. }
  186. else{// Very Hidden
  187. setTimeout(function(){
  188. comboPriceFinder(ele.parentNode.parentNode.parentNode.parentNode);
  189. },3000);
  190. for(var i=products.snapshotLength-1;i>-1;i--){
  191. var id=products.snapshotItem(i).href;
  192. fetchPrice(getURL('Item',id.substr(id.indexOf('?'))),prices.snapshotItem(i),true,true);
  193. }
  194. }
  195. }
  196. },2550);
  197. }
  198. else{
  199. var eles=document.evaluate("//ul[@class='comboPrice map']/li[@class='comboFinal']/a[@class='priceAction']",document,null,6,null);
  200. for(var i=eles.snapshotLength-1;i>-1;i--){
  201. ele=eles.snapshotItem(i);
  202. if(ele.textContent=='See price in cart'){
  203. var combo=ele.getAttribute('onclick');
  204. combo=combo.slice(combo.indexOf('ComboID=')+8,combo.indexOf("','"));
  205. comboPriceInCart(ele,combo);
  206. }
  207. else{
  208. var url=ele.parentNode.nextElementSibling.getElementsByTagName('a')[0].href;
  209. ele.removeAttribute('onclick');
  210. ele.href="/Product/ComboDealDetails.aspx?ItemList="+url.substr(url.lastIndexOf('=')+1);
  211. ele.textContent='Click for Price';
  212. ele.removeAttribute('title');
  213. }
  214. }
  215. }*/
  216. function showPrice(){
  217. var paths=Array("//div[@class='itemCell']/div[@class='itemAction']/ul/li[@class='price-map']/a/../../li[@class='price-current ']",
  218. "//div/div[@class='wrap_inner']/div[@class='wrap_pitch']/ul/li[@class='price-map']/a/../../li[@class='price-current ']",
  219. "//div[@class='infoSideSell']/ul/li[@class='price-map']/*/../../li[@class='price-current ']");
  220. for(var x=0,stp=paths.length;x<stp;x++){
  221. eles=document.evaluate(paths[x],document,null,6,null);
  222. for(var i=eles.snapshotLength-1;i>-1;i--){
  223. ele=eles.snapshotItem(i);
  224. price=ele.parentNode.parentNode.getElementsByTagName('input')[0].value;
  225. GM_log(price+" == "+Number(price));
  226. if(!isNaN(price))
  227. price="$"+price;
  228. price=price.split(".");
  229. ele.innerHTML="<strong>"+price[0]+"</strong><sup>."+price[1]+"</sup>";
  230. ele.className+="patched";
  231. }
  232. }
  233. }
  234. function showPriceLoop(){// Timed loop is used cause DOMSubtreeModified will fire hundreds of times a second which is hell on slow systems
  235. showPrice();
  236. setTimeout(function(){
  237. showPriceLoop();
  238. },3250);
  239. }
  240.  
  241. GM_addStyle("#singleFinalPrice,.is-map .price-current.patched{display:block!important;}.is-map .price-map{display:none!important;}");
  242. var ele=document.evaluate("//li[@class='price-map']/a/../../li[@id='singleFinalPrice']",document,null,9,null).singleNodeValue,eles,price;
  243. if(ele){
  244. price=ele.getAttribute('content').split(".");
  245. ele.innerHTML="$<strong>"+addCommas(price[0])+"</strong><sup>."+price[1]+"</sup>";
  246. }
  247. showPriceLoop();

QingJ © 2025

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