Amazon Global Price Comparator

It shows prices across amazon portals (IT,DE,FR,ES,UK,US,CA,AU)

  1. // ==UserScript==
  2. // @name Amazon Global Price Comparator
  3. // @description It shows prices across amazon portals (IT,DE,FR,ES,UK,US,CA,AU)
  4. // @match https://www.amazon.it/*
  5. // @match https://www.amazon.de/*
  6. // @match https://www.amazon.co.uk/*
  7. // @match https://www.amazon.fr/*
  8. // @match https://www.amazon.es/*
  9. // @match https://www.amazon.com/*
  10. // @match https://www.amazon.com.au/*
  11. // @match https://www.amazon.ca/*
  12. // @version 2.2
  13. // @author SH3LL
  14. // @grant GM_xmlhttpRequest
  15. // @namespace https://gf.qytechs.cn/users/762057
  16. // ==/UserScript==
  17.  
  18. function get_price(url,location) {
  19. return new Promise(function (resolve, reject) {
  20. GM_xmlhttpRequest({
  21. method: 'GET',
  22. responseType: 'document',
  23. synchronous: false,
  24. url: url,
  25. onload: (resp) => {
  26. const doc = document.implementation.createHTMLDocument().documentElement;
  27. doc.innerHTML = resp.responseText;
  28. let grabbed_price=null;
  29.  
  30. // ----------------------------- REGULAR ITEMS ALGORITHM -----------------------------
  31. // --- Latest amazon grabber ---
  32. if(grabbed_price === null) {
  33. grabbed_price = doc.querySelector('span.a-price.aok-align-center.reinventPricePriceToPayMargin.priceToPay'); // id prezzo
  34. if(grabbed_price!==null) grabbed_price=grabbed_price.children[1];
  35. }
  36. // --- PriceBlock of type: OURPRICE ---
  37. if(grabbed_price === null) grabbed_price = doc.querySelector('#priceblock_ourprice'); // id prezzo
  38. if(grabbed_price === null) {
  39. grabbed_price = doc.querySelector('#apexPriceToPay');
  40. if(grabbed_price!== null && grabbed_price.children[1]!==null) grabbed_price=grabbed_price.children[1];
  41. }// nuova classe id del prezzo
  42. if(grabbed_price === null) grabbed_price = doc.querySelector('#priceblock_saleprice') // id prezzo scontato
  43. if(grabbed_price === null) grabbed_price = doc.querySelector('#priceblock_dealprice') // id prezzo offerta flash
  44. if(grabbed_price === null) grabbed_price = doc.querySelector('#priceblock_pospromoprice') // id prezzo offerta flash
  45.  
  46. // --- PriceBlock of type: "New and Used From.." ---
  47. if(grabbed_price === null){
  48. let etichette = doc.getElementsByTagName("span"); //ottiene tutti i tag "span" della pagina
  49. for(let el of etichette){
  50. if( ( el.innerText.includes("Nuevos") && el.innerText.includes("desde") ) ||
  51. ( el.innerText.includes("Nuovo") && el.innerText.includes("da") ) ||
  52. ( el.innerText.includes("Neufs") && el.innerText.includes("occasions") ) ||
  53. ( el.innerText.includes("Neu") && el.innerText.includes("ab") ) ||
  54. ( el.innerText.includes("New") && el.innerText.includes("from") )
  55. ) {
  56. if(el.children[0]!==undefined && el.children[0].children[1]!==undefined){
  57. grabbed_price = el.children[0].children[1];
  58. }
  59. break;
  60.  
  61. }
  62. }
  63. }
  64.  
  65. // ----------------------------- BOOK ITEMS ALGORITHM -----------------------------
  66. // --- PriceBlock of type: APEX ---
  67. let price_block=doc.querySelector("#apex_desktop"); //id blocco del prezzo
  68. // --- PriceBlock of type: swatchElement (for Books)
  69. if(price_block===null && grabbed_price===null) price_block=doc.querySelector("#tmmSwatches");
  70. if(price_block!==null && grabbed_price===null){
  71. if(price_block.innerText.includes("€") || price_block.innerText.includes("£") || price_block.innerText.includes("$")){ // se il blocco c'è
  72. let etichette = price_block.getElementsByTagName("span");
  73. for(let el of etichette){
  74. if(el.className.includes("a-text-price") && el.getAttribute("data-a-color")==="price"){
  75. grabbed_price = el.firstChild;
  76. break;
  77. }
  78. if(el.className.includes("a-price") && el.className.includes("priceToPay")){
  79. grabbed_price = el.firstChild;
  80. break;
  81. }
  82.  
  83. if(el.className.includes("a-size-base") && el.className.includes("a-color-price")){// for books
  84. grabbed_price = el;
  85. break;
  86. }
  87. if(el.id==="priceblock_ourprice"){
  88. grabbed_price = el;
  89. break;
  90. }
  91. }
  92. }
  93. }
  94.  
  95.  
  96.  
  97. // PASS THE OUTPUT
  98. if(grabbed_price !== null && grabbed_price !== undefined && grabbed_price.innerText !== null && grabbed_price.innerText !== undefined && grabbed_price.innerText.trim()!== "" && grabbed_price.innerText.length < 10) {
  99. resolve(grabbed_price.innerText); return;
  100. }
  101. resolve("error"); return;
  102. }
  103. });
  104. });
  105. }
  106.  
  107. async function main(){
  108.  
  109. if(window.location.href.includes("/dp/") || window.location.href.includes("/gp/product/") ){
  110.  
  111. //get amazon country
  112. let my_location = (window.location.href).split("www.amazon.")[1].split("/")[0].trim();
  113.  
  114. let amz_code; //get amazon product code
  115. if(window.location.href.includes("/gp/product/") && window.location.href.includes("?") ){
  116. amz_code=(window.location.href).split("?")[0].split('/gp/product/')[1];
  117.  
  118. }else if(window.location.href.includes("/gp/product/") && !window.location.href.includes("?")){
  119. amz_code=(window.location.href).split('/gp/product/')[1];
  120.  
  121. }else if(window.location.href.includes("/dp/") && window.location.href.includes("?")){
  122. amz_code=(window.location.href).split("?")[0].split('/dp/')[1].split('/')[0];
  123.  
  124. }else if(window.location.href.includes("/dp/") && !window.location.href.includes("?")){
  125. amz_code=(window.location.href).split('/dp/')[1].split('/')[0];
  126.  
  127. }
  128.  
  129. //let price_block = document.querySelector('#price'); //VECCHIO HOOK (che non esiste quando il prezzo è fuori stock)
  130. let price_block = document.querySelector('#desktop_unifiedPrice'); //HOOK
  131. if(price_block===null || price_block===undefined ) {price_block = document.querySelector('#productOverview_feature_div'); if(price_block!==null && price_block!==undefined) price_block=price_block.children[0];}
  132. if(price_block===null || price_block===undefined ) {price_block = document.querySelector('#adoptedData');}
  133. console.log(price_block);
  134. let tr1 = document.createElement("tr");
  135.  
  136. let div1 = document.createElement("div");
  137. div1.style.position = "relative";
  138. div1.style.left="100%";
  139.  
  140. let message1= document.createElement("label");
  141. message1.innerText="⏳ Loading Prices..";
  142. message1.style.color="firebrick";
  143.  
  144. tr1.append(div1);
  145. div1.append(message1);
  146. //price_block.children[0].children[0].append(tr1); //VECCHIO HOOK (che non esiste quando il prezzo è fuori stock)
  147. price_block.append(tr1);
  148.  
  149. let locations = ["it","de","fr","es","co.uk","com","com.au","ca"];
  150. let flags = { "it":"🇮🇹", "de":"🇩🇪", "fr":"🇫🇷", "es":"🇪🇸", "co.uk":"🇬🇧", "com":"🇺🇸","ca": "🇨🇦", "com.au": "🇦🇺" };
  151. let prices=[],link,min_price=999999999999999999999999999;
  152.  
  153. console.log("My Location:"+my_location);
  154.  
  155. for(let curr_location of locations){
  156. let curr_price = await get_price("https://www.amazon."+curr_location+"/dp/"+amz_code , curr_location);
  157.  
  158. console.log(curr_location+": price-> " + curr_price)
  159.  
  160. if(curr_price!=="error"){
  161. //clean currency font in the right location
  162. if(curr_location=="it" || curr_location=="de" ||curr_location=="fr" ||curr_location=="es") {curr_price=curr_price.replace("€","").trim()+"€"}
  163. if(curr_location=="co.uk") {curr_price=curr_price.replace("£","").trim()+"£"}
  164. if(curr_location=="com" || curr_location=="com.au" || curr_location=="ca") {curr_price=curr_price.replace("$","").trim()+"$"}
  165.  
  166. //get min price
  167. let cleaned_price="";
  168. cleaned_price=curr_price.replace(",",".");
  169. cleaned_price=cleaned_price.replace("$","");
  170. cleaned_price=cleaned_price.replace("£","");
  171. cleaned_price=cleaned_price.replace("€","");
  172. cleaned_price=cleaned_price.trim();//remove spaces
  173.  
  174. //calcola minimo prezzo
  175. if(parseFloat(cleaned_price)< parseFloat(min_price)){ min_price=cleaned_price }
  176.  
  177. //creo link
  178. link= document.createElement("a");
  179. if(my_location.toString() === curr_location.toString()){
  180. link.innerText= "<"+ flags[curr_location] + " " + curr_price.replace(".",",")+">";
  181. }else{
  182. link.innerText= "["+ flags[curr_location] + " " + curr_price.replace(".",",")+"]";
  183. }
  184.  
  185. link.href="https://www.amazon."+curr_location+"/dp/"+amz_code;
  186. link.style.color="dodgerblue";
  187. link.style.paddingLeft = "5px";
  188. link.style.paddingRight = "5px";
  189.  
  190. prices.push(link);
  191.  
  192. }else{
  193.  
  194. //creo link
  195. link= document.createElement("a");
  196. if(my_location.toString() === curr_location.toString()){
  197. link.innerText= "<"+ flags[curr_location] + " stock-out>";
  198. }else{
  199. link.innerText= "["+ flags[curr_location] + " stock-out]";
  200. }
  201.  
  202. link.href="https://www.amazon."+curr_location+"/dp/"+amz_code;
  203. link.style.color="red";
  204. link.style.paddingLeft = "5px";
  205. link.style.paddingRight = "5px";
  206. //message.style.color="firebrick";
  207.  
  208. prices.push(link);
  209.  
  210. }
  211. }
  212.  
  213. //REMOVE LOADING
  214. //price_block.children[0].children[0].removeChild(price_block.children[0].children[0].lastElementChild); //VECCHIO HOOK (che non esiste quando il prezzo è fuori stock)
  215. price_block.removeChild(price_block.lastElementChild);
  216.  
  217. //Appen Price Block
  218. let tr2 = document.createElement("tr");
  219. let div2 = document.createElement("div");
  220. tr2.append(div2);
  221.  
  222. for(let curr_price_link of prices){
  223.  
  224. let cleaned_price=curr_price_link.innerText.replace("CO.UK","");
  225. cleaned_price=cleaned_price.replaceAll("🇮🇹","");
  226. cleaned_price=cleaned_price.replaceAll("🇩🇪","");
  227. cleaned_price=cleaned_price.replaceAll("🇫🇷","");
  228. cleaned_price=cleaned_price.replaceAll("🇪🇸","");
  229. cleaned_price=cleaned_price.replaceAll("🇬🇧","");
  230. cleaned_price=cleaned_price.replaceAll("🇺🇸","");
  231. cleaned_price=cleaned_price.replaceAll("🇦🇺","");
  232. cleaned_price=cleaned_price.replaceAll("🇨🇦","");
  233. cleaned_price=cleaned_price.replaceAll(",",".");
  234. cleaned_price=cleaned_price.replaceAll("[","");
  235. cleaned_price=cleaned_price.replaceAll("]","");
  236. cleaned_price=cleaned_price.replaceAll("<","");
  237. cleaned_price=cleaned_price.replaceAll(">","");
  238. cleaned_price=cleaned_price.replaceAll("$","");
  239. cleaned_price=cleaned_price.replaceAll("£","");
  240. cleaned_price=cleaned_price.replaceAll("€","");
  241. cleaned_price=cleaned_price.trim();//remove spaces
  242.  
  243. if(parseFloat(cleaned_price)===parseFloat(min_price)){curr_price_link.style.color="green"}
  244. div2.append(curr_price_link);
  245.  
  246. }
  247.  
  248. price_block.append(tr2);
  249.  
  250. /*Append "OTHER SELLERS" block
  251. let other_seller_link=document.createElement("a")
  252. let tr3 = document.createElement("tr");
  253. let div3 = document.createElement("div");
  254.  
  255. other_seller_link.href="https://www.amazon.it/gp/offer-listing/"+amz_code+"/ref=dp_olp_pn"
  256. other_seller_link.innerText="{Force Sellers List}"
  257. other_seller_link.style.textAlign = "center"
  258.  
  259. div3.append(other_seller_link);
  260. tr3.append(div3);
  261.  
  262. price_block.append(tr3);*/
  263. }
  264. }
  265.  
  266. main();

QingJ © 2025

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