Amazon Global Price Comparator

It shows global prices in amazon item page

目前为 2021-06-19 提交的版本。查看 最新版本

// ==UserScript==
// @name        Amazon Global Price Comparator
// @description It shows global prices in amazon item page
// @match       https://www.amazon.it/*
// @match       https://www.amazon.de/*
// @match       https://www.amazon.co.uk/*
// @match       https://www.amazon.fr/*
// @match       https://www.amazon.es/*
// @match       https://www.amazon.com/*
// @grant       none
// @version     1.0
// @author      SH3LL
// @grant       GM_xmlhttpRequest
// @namespace https://gf.qytechs.cn/users/762057
// ==/UserScript==

function get_price(url) {
    return new Promise(function (resolve, reject) {
        GM_xmlhttpRequest({
            method: 'GET',
            responseType: 'document',
            synchronous: false,
            url: url,
            onload: (resp) => {
                  const doc = document.implementation.createHTMLDocument().documentElement;
                  doc.innerHTML = resp.responseText;
              
                  let price_block = doc.querySelector('#priceblock_ourprice');
              
                  if(price_block !== null) {
                    price_block=price_block.innerText;
                    resolve(price_block);
                  }
                  resolve("error");
           }
        });
    });
}

async function main(){
    let location="it";
    if(window.location.href.includes(".it")){location="it";}
    if(window.location.href.includes(".de")){location="de";}
    if(window.location.href.includes(".fr")){location="fr";}
    if(window.location.href.includes(".es")){location="es";}
    if(window.location.href.includes(".co.uk")){location="uk";}
    if(window.location.href.includes(".com")){location="us";}
  
  
    if(window.location.href.includes("/dp/")){
         
      let amz_code; //get amazon product code
      if(window.location.href.includes("?")){
         amz_code=(window.location.href).split("?")[0].split('/dp/')[1].split('/')[0];
      }else{ 
         amz_code=(window.location.href).split('/dp/')[1].split('/')[0];
      }
      
      
      let price_block = document.querySelector('#price'); //HOOK
      if(price_block===null) price_block = document.querySelector('#productOverview_feature_div').children[0];
      
      let tr1 = document.createElement("tr");
      
      let div1 = document.createElement("div");
      div1.style.position = "relative";
      div1.style.left="100%";
      
      let message1= document.createElement("label");
      message1.innerText="Loading Prices...";
      message1.style.color="firebrick";
      
      tr1.append(div1);
      div1.append(message1);
      price_block.children[0].children[0].append(tr1);
      
      
      let locations = ["it","de","fr","es","co.uk","com"];
      let prices=[],link,min_price=999999999999999999999999999;
      
      for(let curr_location of locations){
        let curr_price = await get_price("https://www.amazon."+curr_location+"/dp/"+amz_code);
        
        if(curr_price!=="error"){
          //get min price
          let cleaned_price=curr_price.replace(",",".");
          cleaned_price=cleaned_price.replace("$","");
          cleaned_price=cleaned_price.replace("£","");
          cleaned_price=cleaned_price.replace("€","");
          cleaned_price=cleaned_price.trim();//remove spaces
          
          if(parseFloat(cleaned_price)<parseFloat(min_price)){min_price=cleaned_price}
          
          link= document.createElement("a");
          link.innerText= "["+curr_location.toUpperCase() + " " + curr_price.replace(".",",")+"]";
          link.href="https://www.amazon."+curr_location+"/dp/"+amz_code;
          link.style.color="green";
          link.style.paddingLeft = "5px";
          link.style.paddingRight = "5px";
          
          prices.push(link);
          
        }else{
          
          link= document.createElement("a");
          link.innerText= "["+curr_location.toUpperCase() + " missing]";
          link.href="https://www.amazon."+curr_location+"/dp/"+amz_code;
          link.style.color="black";
          link.style.paddingLeft = "5px";
          link.style.paddingRight = "5px";
          //message.style.color="firebrick";
          
          prices.push(link);
          
        }
      }
      
      //REMOVE LOADING
      price_block.children[0].children[0].removeChild(price_block.children[0].children[0].lastElementChild);
      
      let tr2 = document.createElement("tr");
      let div2 = document.createElement("div");
      tr2.append(div2);
      
      for(let curr_price_link of prices){
        
        let cleaned_price=curr_price_link.innerText.replace("CO.UK","");
        cleaned_price=cleaned_price.replace("IT","");
        cleaned_price=cleaned_price.replace("COM","");
        cleaned_price=cleaned_price.replace("DE","");
        cleaned_price=cleaned_price.replace("FR","");
        cleaned_price=cleaned_price.replace("ES","");
        cleaned_price=cleaned_price.replace(",",".");
        cleaned_price=cleaned_price.replace("[","");
        cleaned_price=cleaned_price.replace("]","");
        cleaned_price=cleaned_price.replace("$","");
        cleaned_price=cleaned_price.replace("£","");
        cleaned_price=cleaned_price.replace("€","");
        cleaned_price=cleaned_price.trim();//remove spaces
        
        if(cleaned_price===min_price){curr_price_link.style.color="red"}
        div2.append(curr_price_link);
        
      }
      
      price_block.append(tr2);
    }
}

main();

QingJ © 2025

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