Advertisement
KindDragon

Compare Steam Prices 2.2

Sep 13th, 2011
1,228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        SteamUnPowered.eu # Compare and convert Steam store prices on the fly!
  3. // @version     2.2
  4. // @namespace       http://steamunpowered.eu/comparison-script/
  5. // @description     Displays prices from all regions in the Steam store and convert them to your local currency
  6. // @copyright       2010+, Zuko (Original author: Tor (http://code.google.com/p/steam-prices/))
  7. // @homepage        https://gist.github.com/3767912
  8. // @license     MIT License; http://www.opensource.org/licenses/mit-license.php
  9. // @include     http://store.steampowered.com/app/*
  10. // @include     https://store.steampowered.com/app/*
  11. // @include     http://store.steampowered.com/sub/*
  12. // @include     https://store.steampowered.com/sub/*
  13. // @match       http://store.steampowered.com/app/*
  14. // @match       https://store.steampowered.com/app/*
  15. // @match       http://store.steampowered.com/sub/*
  16. // @match       https://store.steampowered.com/sub/*
  17. // @grant       none
  18. // ==/UserScript==
  19.  
  20. // To install script save to disk under name CompareSteamPrices.user.js and then on in this file Firefox
  21.  
  22. // Russian prices added by KindDragon (https://github.com/KindDragon)
  23.  
  24. /*
  25.  * Configuration
  26.  * If you want to modify the parameters of the script,
  27.  * please make your changes here.
  28.  */
  29.  
  30. //If set to true, your local currency will be displayed
  31. var showYourLocalCurrency = true;
  32. var yourLocalCurrency = "USD";
  33. //Set your base currency for DLC price conversion
  34. var yourDLCBaseCurrency = "USD";
  35.  
  36. //If set to true, UK prices will be displayed (in addition to US and EU and AU prices)
  37. var showUkPrice = true;
  38.  
  39. /*
  40.  * If set to true, the script will display prices from both of Valve's
  41.  * price regions, or "tiers". If false, the script will show only your
  42.  * country's prices. More details on the tiers can be found here:
  43.  * http://steamunpowered.eu/page.php?id=139
  44.  * For games where prices are equal in all regions, the script will display
  45.  * only one value no matter what this setting is configured to.
  46.  */
  47. var showTieredEuPrices = true;
  48.  
  49. //If set to true, AU prices will be displayed (in addition to US and EU and RU prices)
  50. var showAUPrice = true;
  51.  
  52. //If set to true, RUS prices will be displayed (in addition to US and EU and AU prices)
  53. var showRUPrice = true;
  54.  
  55. //These parameters contain one country code from each of the European tiers.
  56. var tier1cc = "se";
  57. var tier2cc = "pl";
  58. //Change this parameter to add VAT to the US price displayed.
  59. //E.g. if set to 19, the script will increase US prices by 19%.
  60. var usVat = 0;
  61.  
  62. /*
  63.  * End of configuration area
  64.  * Don't make changes below this line unless you know what you're doing.
  65.  */
  66.  
  67. var urlGamePattern = new RegExp(/^https?:\/\/store.steampowered.com\/app\/\d+\/?$/i);
  68. var urlPackagePattern = new RegExp(/^https?:\/\/store.steampowered.com\/sub\/\d+\/?$/i);
  69. //var urlGenrePattern = new RegExp(/^https?:\/\/store.steampowered.com\/genre\/.+\/?/i);
  70. var usHttp;
  71. var ukHttp;
  72. var eu1Http;
  73. var eu2Http;
  74. var auHttp;
  75. var ruHttp;
  76. var pricenodes = new Array();
  77. var pricenodes_conly = new Array();
  78. var originalprices = new Array();
  79. var originalprices_conly = new Array();
  80. var ukscript;
  81. var euscript;
  82. var auscript;
  83. var localeurscript;
  84. var localusdscript;
  85. var localgbpscript;
  86. var localrubscript;
  87. var someNode;
  88. var tier1text = "Albania, Andorra, Austria, Belgium, Denmark, Finland, " +
  89.                 "France, Germany, Ireland, Liechtenstein, Luxembourg, Macedonia, " +
  90.                 "Netherlands, Sweden, Switzerland";
  91. var tier2text = "Bosnia and Herzegovina, Bulgaria, Croatia, Cyprus, " +
  92.                 "Czech Republic, Estonia, Greece, Hungary, Italy, Latvia, Lithuania, " +
  93.                 "Malta, Monaco, Montenegro, Norway, Poland, Portugal, Romania, San Marino, " +
  94.                 "Serbia, Slovakia, Slovenia, Spain, Vatican City";
  95.  
  96. //Test the URL to see if we're on a game page
  97. if (urlGamePattern.test(document.documentURI) || urlPackagePattern.test(document.documentURI)) {
  98.     someNode = document.getElementById("global_header");
  99.  
  100.     //For security reasons, JavaScript code isn't allowed to fetch data from
  101.     //external websites. Instead, we insert a HTML <script> tag that fetches
  102.     //external javascript files. These will help with currency conversion.
  103.     if (showUkPrice) {
  104.         ukscript = document.createElement("script");
  105.         ukscript.setAttribute("type", "text/javascript");
  106.         ukscript.setAttribute("src",
  107.             "http://javascriptexchangerate.appspot.com/?from=USD&to=GBP");
  108.         document.body.insertBefore(ukscript, someNode);
  109.     }
  110.  
  111.     if (showYourLocalCurrency) {
  112.         localeurscript = document.createElement("script");
  113.         localeurscript.setAttribute("type", "text/javascript");
  114.         //localscript.setAttribute("src",
  115.             //"http://javascriptexchangerate.appspot.com/?from=" + yourDLCBaseCurrency + "&to=" + yourLocalCurrency);
  116.         localeurscript.setAttribute("src",
  117.             "http://javascriptexchangerate.appspot.com/?from=EUR&to="+yourLocalCurrency);
  118.         document.body.insertBefore(localeurscript, someNode);
  119.  
  120.         localusdscript = document.createElement("script");
  121.         localusdscript.setAttribute("type", "text/javascript");
  122.         localusdscript.setAttribute("src",
  123.             "http://javascriptexchangerate.appspot.com/?from=USD&to="+yourLocalCurrency);
  124.         document.body.insertBefore(localusdscript, someNode);
  125.  
  126.         localgbpscript = document.createElement("script");
  127.         localgbpscript.setAttribute("type", "text/javascript");
  128.         localgbpscript.setAttribute("src",
  129.             "http://javascriptexchangerate.appspot.com/?from=GBP&to="+yourLocalCurrency);
  130.         document.body.insertBefore(localgbpscript, someNode);
  131.  
  132.         localrubscript = document.createElement("script");
  133.         localrubscript.setAttribute("type", "text/javascript");
  134.         localrubscript.setAttribute("src",
  135.             "http://javascriptexchangerate.appspot.com/?from=RUB&to="+yourLocalCurrency);
  136.         document.body.insertBefore(localrubscript, someNode);
  137.     }
  138.  
  139.     euscript = document.createElement("script");
  140.     euscript.setAttribute("type", "text/javascript");
  141.     euscript.setAttribute("src",
  142.         "http://javascriptexchangerate.appspot.com/?from=USD&to=EUR");
  143.     document.body.insertBefore(euscript, someNode);
  144.  
  145.     /* not needed, since price is in USD for the Australian site
  146.      but converting to USD to USD will let us change the script easily
  147.      in case the Australian steam site moves to AUD */
  148.     /*
  149.     if (showAUPrice) {
  150.         auscript = document.createElement("script");
  151.         auscript.setAttribute("type", "text/javascript");
  152.         auscript.setAttribute("src",
  153.             "http://javascriptexchangerate.appspot.com/?from=USD&to=USD");
  154.         document.body.insertBefore(auscript, someNode);
  155.     }
  156.     */
  157.  
  158.     var wClass = "";
  159.     //Test to see if the game has a price
  160.     divnodes = document.getElementsByTagName("div");
  161.     for (i=0; i<divnodes.length; i++) {
  162.         if (divnodes[i].getAttribute("class") == "game_purchase_price price") {
  163.             wClass = "game_purchase_price";
  164.             pricenodes.push(divnodes[i]);
  165.             if (!showTieredEuPrices)
  166.                 originalprices.push(divnodes[i].innerHTML);
  167.             divnodes[i].innerHTML +=
  168.             "<br/><span style='color: rgb(136, 136, 136);'>Collecting data...</span>"
  169.             divnodes[i].style.textAlign = "left";
  170.         }
  171.         if ((divnodes[i].getAttribute("class") == "game_area_dlc_price") && (divnodes[i].innerHTML.indexOf("discount_final_price") == -1)) {
  172.             if (showYourLocalCurrency) {
  173.                 pricenodes_conly.push(divnodes[i]);
  174.                 originalprices_conly.push(divnodes[i].innerHTML);
  175.                 divnodes[i].innerHTML +=
  176.                 "<span style='color: rgb(136, 136, 136);'>Collecting data...</span>"
  177.                 divnodes[i].style.textAlign = "left";
  178.             }
  179.         } else if ((divnodes[i].getAttribute("class") == "discount_final_price") && (divnodes[i].innerHTML.indexOf("<") == -1)) {
  180.             if (divnodes[i-4].parentNode.className != 'game_area_dlc_price') {
  181.                 wClass = "discount_final_price";
  182.                 pricenodes.push(divnodes[i]);
  183.                 if (!showTieredEuPrices)
  184.                     originalprices.push(divnodes[i].innerHTML);
  185.                 divnodes[i].innerHTML +=
  186.                 "<br/><span style='color: rgb(136, 136, 136);'>Collecting data...</span>"
  187.                 divnodes[i].style.textAlign = "left";
  188.             } else if (showYourLocalCurrency) {
  189.                 pricenodes_conly.push(divnodes[i]);
  190.                 originalprices_conly.push(divnodes[i].innerHTML);
  191.                 divnodes[i].innerHTML +=
  192.                 "<span style='color: rgb(136, 136, 136);'> Collecting data...</span>"
  193.                 divnodes[i].style.textAlign = "right";
  194.             }
  195.         }
  196.     }
  197.  
  198.     //If the current page contains a price,
  199.     //start downloading regional versions of this page
  200.     if ((pricenodes.length > 0) || (pricenodesdlc.length > 0)) {
  201.     //Create cookie that prevents the age verification
  202.     //dialog from breaking the script
  203.         if (document.cookie.indexOf("birthtime") < 0) { //Check if cookie exists
  204.             var date = new Date();
  205.             date.setTime(date.getTime()+(365*24*60*60*1000));//Expires in 365 days
  206.             document.cookie = "birthtime=1; expires=" //birthtime is set to 1 Jan 1900
  207.             + date.toGMTString() + "; path=/"
  208.         }
  209.  
  210.         //Set up HTTP requests
  211.         usHttp = new XMLHttpRequest();
  212.         usHttp.onreadystatechange=stateChanged;
  213.         usHttp.open("GET",document.documentURI+"?cc=us",true);
  214.         usHttp.send(null);
  215.  
  216.         if (showUkPrice) {
  217.             ukHttp = new XMLHttpRequest();
  218.             ukHttp.onreadystatechange=stateChanged;
  219.             ukHttp.open("GET",document.documentURI+"?cc=uk",true);
  220.             ukHttp.send(null);
  221.         }
  222.  
  223.         if (showTieredEuPrices) {
  224.             eu1Http = new XMLHttpRequest();
  225.             eu1Http.onreadystatechange=stateChanged;
  226.             eu1Http.open("GET",document.documentURI+"?cc="+tier1cc,true);
  227.             eu1Http.send(null);
  228.             eu2Http = new XMLHttpRequest();
  229.             eu2Http.onreadystatechange=stateChanged;
  230.             eu2Http.open("GET",document.documentURI+"?cc="+tier2cc,true);
  231.             eu2Http.send(null);
  232.         }
  233.  
  234.         if (showAUPrice) {
  235.             auHttp = new XMLHttpRequest();
  236.             auHttp.onreadystatechange=stateChanged;
  237.             auHttp.open("GET",document.documentURI+"?cc=au",true);
  238.             auHttp.send(null);
  239.         }
  240.  
  241.         if (showRUPrice) {
  242.             ruHttp = new XMLHttpRequest();
  243.             ruHttp.onreadystatechange=stateChanged;
  244.             ruHttp.open("GET",document.documentURI+"?cc=ru",true);
  245.             ruHttp.send(null);
  246.         }
  247.  
  248.         var style = document.createElement("style");
  249.         style.type = "text/css";
  250.         document.getElementsByTagName('head')[0].appendChild(style);
  251.  
  252.         var s = document.styleSheets[document.styleSheets.length - 1];
  253.         if (wClass == "game_purchase_price")
  254.             s.insertRule(".game_area_purchase_game .game_purchase_action{height:auto;bottom:auto}", s.cssRules.length);
  255.         if (wClass == "discount_final_price")
  256.             s.insertRule(".game_purchase_action  .game_purchase_price, .game_purchase_discount{height:auto;padding-bottom:8px}", s.cssRules.length);
  257.         s.insertRule(".game_purchase_action_bg{height:auto}", s.cssRules.length);
  258.         s.insertRule(".game_purchase_action  .game_purchase_price{height:auto;padding-bottom:8px}", s.cssRules.length);
  259.  
  260.         var margin = 30;
  261.         if (showUkPrice) margin += 16;
  262.         if (showTieredEuPrices) margin += 16;
  263.         if (showAUPrice) margin += 16;
  264.         if (showRUPrice) margin += 16;
  265.         s.insertRule(".game_area_purchase_game{margin-bottom:"+margin+"px}", s.cssRules.length);
  266.     }
  267. }
  268.  
  269. function getConvFunction(currency, id)
  270. {
  271.     if (currency != yourLocalCurrency)
  272.         return "Math.round(" + currency + "to" + yourLocalCurrency + "(" + id + ".innerHTML * 100))/100";
  273.     else
  274.         return id + ".innerHTML";
  275. }
  276.  
  277. //Extracts prices from the downloaded HTML and displays them
  278. function stateChanged() {
  279.     //Check to see of all scripts have completed
  280.     if (usHttp.readyState != 4) return;
  281.     if (showUkPrice && ukHttp.readyState != 4) return;
  282.     if (showTieredEuPrices && (eu1Http.readyState != 4 || eu2Http.readyState != 4)) return;
  283.     if (showAUPrice && auHttp.readyState != 4) return;
  284.     if (showRUPrice && ruHttp.readyState != 4) return;
  285.     //All requests completed, good to go
  286.  
  287.     //The pattern variables can't be reused for some reason, so just duplicate
  288.     var pricepattern0 =
  289.         new RegExp(/<div class="game_purchase_price price">([^<]+?)<\/div>/gi);
  290.     var pricepattern01 =
  291.         new RegExp(/<div class="discount_final_price">([^<]+?)<\/div>/gi);
  292.     var pricepattern1 =
  293.         new RegExp(/<div class="game_purchase_price price">([^<]+?)<\/div>/gi);
  294.     var pricepattern11 =
  295.         new RegExp(/<div class="discount_final_price">([^<]+?)<\/div>/gi);
  296.     var pricepattern2 =
  297.         new RegExp(/<div class="game_purchase_price price">([^<]+?)<\/div>/gi);
  298.     var pricepattern21 =
  299.         new RegExp(/<div class="discount_final_price">([^<]+?)<\/div>/gi);
  300.     var pricepattern3 =
  301.         new RegExp(/<div class="game_purchase_price price">([^<]+?)<\/div>/gi);
  302.     var pricepattern31 =
  303.         new RegExp(/<div class="discount_final_price">([^<]+?)<\/div>/gi);
  304.     var pricepattern4 =
  305.         new RegExp(/<div class="game_purchase_price price">([^<]+?)<\/div>/gi);
  306.     var pricepattern41 =
  307.         new RegExp(/<div class="discount_final_price">([^<]+?)<\/div>/gi);
  308.     var pricepattern5 =
  309.         new RegExp(/<div class="game_purchase_price price">([^<]+?)<\/div>/gi);
  310.     var pricepattern51 =
  311.         new RegExp(/<div class="discount_final_price">([^<]+?)<\/div>/gi);
  312.     var pricepattern6 =
  313.         new RegExp(/<div class="game_purchase_price price">([^<]+?)<\/div>/gi);
  314.     var pricepattern61 =
  315.         new RegExp(/<div class="discount_final_price">([^<]+?)<\/div>/gi);
  316.  
  317.     var priceHtml = new Array(6);
  318.     var mypriceHtml;
  319.     var usvaluepattern = new RegExp(/&#36;([\d\.]+)/i);
  320.     var ukvaluepattern = new RegExp(/&#163;([\d\.]+)/i);
  321.     var euvaluepattern = new RegExp(/([\d,-]+)&#8364;/i);
  322.     var auvaluepattern = new RegExp(/&#36;([\d\.]+)[\s]USD/i);
  323.     var ruvaluepattern = new RegExp(/([\d\.]+)[\s]руб/i);
  324.     var localvaluepattern = new RegExp(/([\d,-]+)/i);
  325.     var price = new Array(6);
  326.     var myprice;
  327.  
  328.     var calcscript = "function getDifference(currency, usdPrice, localPrice) " +
  329.         "{\n" +
  330.         "  var usdConverted; var lessmore; var diff;\n" +
  331.         "  if (currency == 'GBP') {usdConverted = USDtoGBP(usdPrice);}\n" +
  332.         "  else if (currency == 'EUR') {usdConverted = USDtoEUR(usdPrice);}\n" +
  333.         "  else if (currency == 'RUB') {usdConverted = USDtoRUB(usdPrice);}\n" +
  334.         //"  else if (currency == 'USD') {usdConverted = USDtoUSD(usdPrice);}\n" +
  335.         "  else if (currency == 'USD') {usdConverted = usdPrice;}\n" +
  336.         "  diff = Math.abs((localPrice/usdConverted)*100-100);\n" +
  337.  
  338.         "  if (localPrice == usdConverted) {lessmore = '<img src=\"http://www.steamunpowered.eu/orangebar.png\" width=\"9\" height=\"5\" border=\"0\">';}\n" +
  339.         "  else if (localPrice > usdConverted) {lessmore = '<img src=\"http://www.steamunpowered.eu/uparrow.png\" width=\"7\" height=\"9\" border=\"0\">';}\n" +
  340.         "  else {lessmore = '<img src=\"http://www.steamunpowered.eu/downarrow.png\" width=\"7\" height=\"9\" border=\"0\">';}\n" +
  341.  
  342.         " if (localPrice == usdConverted) {return ' <span style=\"color: #ac9b09; font-weight: normal\">(' + lessmore + ')</span>';}\n" +
  343.         " else if (localPrice > usdConverted) {return '  <span style=\"color: #f00; font-weight: normal\">(' + Math.round(diff) + '% ' + lessmore + ')</span>'}\n" +
  344.         " else return ' <span style=\"color: #4fc20f; font-weight: normal\">(' + Math.round(diff) + '% ' + lessmore + ')</span>';}\n";
  345.  
  346.     var calcscript_opera = "function getDifference(currency, usdPrice, localPrice) " +
  347.         "{\n" +
  348.         "  var usdConverted; var lessmore; var diff;\n" +
  349.         "  if (currency == 'GBP') {usdConverted = USDtoGBP(usdPrice);}\n" +
  350.         "  else if (currency == 'EUR') {usdConverted = USDtoEUR(usdPrice);}\n" +
  351.         "  else if (currency == 'RUB') {usdConverted = USDtoRUB(usdPrice);}\n" +
  352.         //"  else if (currency == 'USD') {usdConverted = USDtoUSD(usdPrice);}\n" +
  353.         "  else if (currency == 'USD') {usdConverted = usdPrice;}\n" +
  354.         "  diff = Math.abs((localPrice/usdConverted)*100-100);\n" +
  355.  
  356.         "  if (localPrice == usdConverted) {lessmore = 'prices are equal'; return ' (' + lessmore + ')';} \n" +
  357.         "  else if (localPrice > usdConverted) {lessmore = 'higher';}\n" +
  358.         "  else {lessmore = 'lower';}\n" +
  359.         "  return ' (' + Math.round(diff) + '% ' + lessmore + ')';}\n";
  360.  
  361.     var calculatescript = document.createElement("script");
  362.     calculatescript.setAttribute("type", "text/javascript");
  363.     //Shitty Opera browser detection
  364.     if (navigator.appName == "Opera") {
  365.         calculatescript.innerHTML = calcscript_opera;
  366.     } else {
  367.         calculatescript.innerHTML = calcscript;
  368.     }
  369.     document.body.insertBefore(calculatescript, someNode);
  370.  
  371.     //For DLC
  372.     var mypriceHtml_conly;
  373.     var myprice_conly;
  374.  
  375.     for (i = 0; i < pricenodes_conly.length; i++) {
  376.         try {
  377.             var myvaluepattern_conly = new RegExp(/([\d,-]+)/i);
  378.             mypriceHtml_conly = originalprices_conly[i];
  379.             myprice_conly = parseFloat(myvaluepattern_conly.exec(originalprices_conly[i])[1].replace(",", ".").replace("--", "00"));
  380.         }
  381.         catch(err) {
  382.             if (!mypriceHtml_conly || mypriceHtml_conly.length == 0)
  383.                 mypriceHtml_conly = "N/A";
  384.             myprice_conly = null;
  385.         }
  386.         if (showYourLocalCurrency) {
  387.             pricenodes_conly[i].innerHTML = mypriceHtml_conly + " <span id='dlc" + i + "' style='font-weight: bold; color: rgb(136, 136, 136);'>" + myprice_conly + "</span>";   
  388.             var dlc00 = document.createElement("script");
  389.             dlc00.setAttribute("type", "text/javascript");
  390.             dlc00.innerHTML = "var dlc = document.getElementById('dlc" + i + "');" +
  391.             "dlc.innerHTML = \"(\" + " + getConvFunction(yourDLCBaseCurrency, "dlc") + " + \" " + yourLocalCurrency + ")\";";
  392.             document.body.insertBefore(dlc00, someNode);
  393.         }
  394.     }
  395.  
  396.     for (i=0; i<pricenodes.length; i++) {
  397.         if (!showTieredEuPrices) {
  398.             try {
  399.                 var myvaluepattern = new RegExp(/([\d,-]+)/i);
  400.                 mypriceHtml = originalprices[i];
  401.                 myprice = parseFloat(myvaluepattern.exec(originalprices[i])[1].replace(",", ".").replace("--", "00"));
  402.             }
  403.             catch(err) {
  404.                 if (!mypriceHtml || mypriceHtml.length == 0)
  405.                 mypriceHtml = "N/A";
  406.                 myprice = null;
  407.             }
  408.         }
  409.         //Search for the price information in the downloaded HTML documents
  410.         try {
  411.             if (wClass == "game_purchase_price") {
  412.                 priceHtml[0] = pricepattern1.exec(usHttp.responseText)[1];
  413.             }
  414.             if (wClass == "discount_final_price") {
  415.                 priceHtml[0] = pricepattern11.exec(usHttp.responseText)[1];
  416.             }
  417.             price[0] = parseFloat(usvaluepattern.exec(priceHtml[0])[1]);
  418.             if (usVat > 0) {
  419.                 price[0] = price[0] * (1 + (usVat / 100));
  420.                 priceHtml[0] = "$" + price[0].toFixed(2);
  421.             }
  422.         }
  423.         catch(err) {
  424.         //Prevent search from looping around and starting at the beginning
  425.             if (err.message.search("responseText\\) is null") != -1) {
  426.                 usHttp = null; priceHtml[0] = "N/A";
  427.             }
  428.             if (!priceHtml[0] || priceHtml[0].length == 0)
  429.                 priceHtml[0] = "N/A";
  430.                 price[0] = null;
  431.         }
  432.         if (showYourLocalCurrency && (price[0] != null)) {
  433.             if (usVat > 0) {
  434.                 pricenodes[i].innerHTML = "US: " + priceHtml[0] + " (inc. " + usVat + "% VAT)" + " <span id='us" + i + "' style='font-weight: bold;'>" + price[0] + "</span>"; 
  435.             } else {
  436.                 pricenodes[i].innerHTML = "US: " + priceHtml[0] + " <span id='us" + i + "' style='font-weight: bold;'>" + price[0] + "</span>";
  437.             }
  438.             var tmp00 = document.createElement("script");
  439.             tmp00.setAttribute("type", "text/javascript");
  440.             if (usVat > 0) {
  441.                 tmp00.innerHTML = "var us = document.getElementById('us" + i + "');" +
  442.                 "us.innerHTML = \"(\" + " + getConvFunction("USD", "us") + " + \" " + yourLocalCurrency + " inc. " + usVat + "% VAT)\";";
  443.             } else {
  444.                 tmp00.innerHTML = "var us = document.getElementById('us" + i + "');" +
  445.                 "us.innerHTML = \"(\" + " + getConvFunction("USD", "us") + " + \" " + yourLocalCurrency + ")\";";
  446.             }
  447.             document.body.insertBefore(tmp00, someNode);
  448.         } else {
  449.             pricenodes[i].innerHTML = "US: " + priceHtml[0];
  450.             if (usVat > 0)
  451.                 pricenodes[i].innerHTML += " (inc. " + usVat + "% VAT)";
  452.         }
  453.  
  454.             if (showUkPrice) {
  455.             try {
  456.                 if (wClass == "game_purchase_price") {
  457.                     priceHtml[1] = pricepattern2.exec(ukHttp.responseText)[1];
  458.                 }
  459.                 if (wClass == "discount_final_price") {
  460.                     priceHtml[1] = pricepattern21.exec(ukHttp.responseText)[1];
  461.                 }
  462.                 price[1] = parseFloat(ukvaluepattern.exec(priceHtml[1])[1]);
  463.             }
  464.             catch(err) {
  465.             //Prevent search from looping around and starting at the beginning
  466.                 if (err.message.search("responseText\\) is null") != -1) {
  467.                     ukHttp = null; priceHtml[1] = "N/A";
  468.                 }
  469.                 if (!priceHtml[1] || priceHtml[1].length == 0)
  470.                     priceHtml[1] = "N/A";
  471.                     price[1] = null;
  472.             }
  473.             if (showYourLocalCurrency && (price[1] != null)) {
  474.                 pricenodes[i].innerHTML += "<br>UK: " + priceHtml[1] + " <span id='gbp" + i + "' style='font-weight: bold;'>" + price[1] + "</span>";
  475.                 var tmp01 = document.createElement("script");
  476.                 tmp01.setAttribute("type", "text/javascript");
  477.                 tmp01.innerHTML = "var gbp = document.getElementById('gbp" + i + "');" +
  478.                 "gbp.innerHTML = \"(\" + " + getConvFunction("GBP", "gbp") + " + \" " + yourLocalCurrency + ")\";";
  479.                 document.body.insertBefore(tmp01, someNode);
  480.                 createGetDifferenceScript("gbp" + i, "GBP", price[0], price[1]);
  481.             } else {
  482.                 pricenodes[i].innerHTML += "<br>UK: " + priceHtml[1]
  483.                 + " <span id='gbp" + i + "'></span>"
  484.                 createGetDifferenceScript("gbp" + i, "GBP", price[0], price[1]);
  485.             }
  486.         }
  487.             if (showTieredEuPrices) {
  488.             try {
  489.                 if (wClass == "game_purchase_price") {
  490.                     priceHtml[2] = pricepattern3.exec(eu1Http.responseText)[1];
  491.                 }
  492.                 if (wClass == "discount_final_price") {
  493.                     priceHtml[2] = pricepattern31.exec(eu1Http.responseText)[1];
  494.                 }
  495.             }
  496.             catch(err) {
  497.                 //Prevent search from looping around and starting at the beginning
  498.                 if (err.message.search("responseText\\) is null") != -1) {
  499.                     eu1Http = null; priceHtml[2] = "N/A";
  500.                 }
  501.                 if (!priceHtml[2] || priceHtml[2].length == 0)
  502.                     priceHtml[2] = "N/A";
  503.             }
  504.             try {
  505.                 if (wClass == "game_purchase_price") {
  506.                     priceHtml[3] = pricepattern4.exec(eu2Http.responseText)[1];
  507.                 }
  508.                 if (wClass == "discount_final_price") {
  509.                     priceHtml[3] = pricepattern41.exec(eu2Http.responseText)[1];
  510.                 }
  511.             }
  512.             catch(err) {
  513.                 //Prevent search from looping around and starting at the beginning
  514.                 if (err.message.search("responseText\\) is null") != -1) {
  515.                     eu2Http = null; priceHtml[3] = "N/A";
  516.                 }
  517.             if (!priceHtml[3] || priceHtml[3].length == 0)
  518.                 priceHtml[3] = "N/A";
  519.             }
  520.                 var t;
  521.             for (t = 2; t < 4; t++) {
  522.                 try {price[t] = parseFloat(euvaluepattern.exec(priceHtml[t])[1].replace(",", ".").replace("--", "00"));}
  523.             catch(err) {price[t] = null;}
  524.             }
  525.                 //If tier 1 and 2 prices are equal, display only one EU price
  526.             if (price[2] == price[3]) {
  527.                 if (showYourLocalCurrency && (price[2] != null) && (price[3] != null)) {
  528.                     pricenodes[i].innerHTML += "<br>EU: " + priceHtml[2] + " <span id='eur1_" + i + "' style='font-weight: bold;'>" + price[2] + "</span>";
  529.                     var tmp01 = document.createElement("script");
  530.                     tmp01.setAttribute("type", "text/javascript");
  531.                     tmp01.innerHTML = "var eur1_ = document.getElementById('eur1_" + i + "');" +
  532.                     "eur1_.innerHTML = \"(\" + " + getConvFunction("EUR", "eur1_") + " + \" " + yourLocalCurrency + ")\";";
  533.                     document.body.insertBefore(tmp01, someNode);
  534.                     createGetDifferenceScript("eur1_" + i, "EUR", price[0], price[2]);
  535.                 } else {
  536.                     pricenodes[i].innerHTML += "<br>EU: " + priceHtml[2]
  537.                     + " <span id='eur1_" + i + "'></span>";
  538.                     createGetDifferenceScript("eur1_" + i, "EUR", price[0], price[2]);
  539.                 }
  540.             } else { //...but if they differ, display both
  541.                 if (showYourLocalCurrency && (price[2] != null)) {
  542.                     pricenodes[i].innerHTML += "<br>EU Tier 1: " + priceHtml[2] + " <span id='eur1_" + i + "' style='font-weight: bold;'>" + price[2] + "</span>";
  543.                     var tmp02 = document.createElement("script");
  544.                     tmp02.setAttribute("type", "text/javascript");
  545.                     tmp02.innerHTML = "var eur1_ = document.getElementById('eur1_" + i + "');" +
  546.                     "eur1_.innerHTML = \"(\" + " + getConvFunction("EUR", "eur1_") + " + \" " + yourLocalCurrency + ")\";";
  547.                     document.body.insertBefore(tmp02, someNode);
  548.                     createGetDifferenceScript("eur1_" + i, "EUR", price[0], price[2]);
  549.                 } else {
  550.                     pricenodes[i].innerHTML += "<br><span title='" + tier1text
  551.                     + "'>EU Tier 1: " + priceHtml[2]
  552.                     + " <span id='eur1_" + i + "'></span></span>";
  553.                     createGetDifferenceScript("eur1_" + i, "EUR", price[0], price[2]);
  554.                 }
  555.                 if (showYourLocalCurrency && (price[3] != null)) {
  556.                     pricenodes[i].innerHTML += "<br>EU Tier 2: " + priceHtml[3] + " <span id='eur2_" + i + "' style='font-weight: bold;'>" + price[3] + "</span>";
  557.                     var tmp03 = document.createElement("script");
  558.                     tmp03.setAttribute("type", "text/javascript");
  559.                     tmp03.innerHTML = "var eur2_ = document.getElementById('eur2_" + i + "');" +
  560.                     "eur2_.innerHTML = \"(\" + " + getConvFunction("EUR", "eur2_") + " + \" " + yourLocalCurrency + ")\";";
  561.                     document.body.insertBefore(tmp03, someNode);
  562.                     createGetDifferenceScript("eur2_" + i, "EUR", price[0], price[3]);
  563.                 } else {
  564.                     pricenodes[i].innerHTML += "<br><span title='" + tier2text
  565.                     + "'>EU Tier 2: " + priceHtml[3]
  566.                     + " <span id='eur2_" + i + "'></span></span>";
  567.                     createGetDifferenceScript("eur2_" + i, "EUR", price[0], price[3]);
  568.                 }
  569.             }
  570.         } else { //Ignore country codes, only display price for YOUR region
  571.             if (showYourLocalCurrency && (myprice != null)) {
  572.                 pricenodes[i].innerHTML += "<br>You: " + mypriceHtml + " <span id='myprice" + i + "' style='font-weight: bold;'>" + myprice + "</span>";
  573.                 var tmp04 = document.createElement("script");
  574.                 tmp04.setAttribute("type", "text/javascript");
  575.                 tmp04.innerHTML = "var myprice = document.getElementById('myprice" + i + "');" +
  576.                 "myprice.innerHTML = \"(\" + " + getConvFunction("EUR", "myprice") + " + \" " + yourLocalCurrency + ")\";";
  577.                 document.body.insertBefore(tmp04, someNode);
  578.                 createGetDifferenceScript("myprice" + i, "EUR", price[0], myprice);
  579.             } else {
  580.                 pricenodes[i].innerHTML += "<br>You: " + mypriceHtml
  581.                 + " <span id='myprice" + i + "'></span>";
  582.                 createGetDifferenceScript("myprice" + i, "EUR", price[0], myprice);
  583.             }
  584.         }
  585.             if (showAUPrice) {
  586.             try {
  587.                 if (wClass == "game_purchase_price") {
  588.                     priceHtml[4] = pricepattern5.exec(auHttp.responseText)[1];
  589.                 }
  590.                 if (wClass == "discount_final_price") {
  591.                     priceHtml[4] = pricepattern51.exec(auHttp.responseText)[1];
  592.                 }
  593.                 price[4] = parseFloat(auvaluepattern.exec(priceHtml[4])[1]);
  594.             }
  595.             catch(err) {
  596.                 //Prevent search from looping around and starting at the beginning
  597.                 if (err.message.search("responseText\\) is null") != -1) {
  598.                 auHttp = null; priceHtml[4] = "N/A";
  599.                 }
  600.                 if (!priceHtml[4] || priceHtml[4].length == 0)
  601.                     priceHtml[4] = "N/A";
  602.                     price[4] = null;
  603.             }  
  604.             if (showYourLocalCurrency && (price[4] != null)) {
  605.                 pricenodes[i].innerHTML += "<br>AU: " + priceHtml[4] + " <span id='aud" + i + "' style='font-weight: bold;'>" + price[4] + "</span>";
  606.                 var tmp05 = document.createElement("script");
  607.                 tmp05.setAttribute("type", "text/javascript");
  608.                 tmp05.innerHTML = "var aud = document.getElementById('aud" + i + "');" +
  609.                 "aud.innerHTML = \"(\" + " + getConvFunction("USD", "aud") + " + \" " + yourLocalCurrency + ")\";";
  610.                 document.body.insertBefore(tmp05, someNode);
  611.                 createGetDifferenceScript("aud" + i, "USD", price[0], price[4]);
  612.             } else {
  613.                 pricenodes[i].innerHTML += "<br>AU: " + priceHtml[4]
  614.                 + " <span id='aud" + i + "'></span>"
  615.                 createGetDifferenceScript("aud" + i, "USD", price[0], price[4]);
  616.             }
  617.         }
  618.             if (showRUPrice) {
  619.             try {
  620.                 if (wClass == "game_purchase_price") {
  621.                     priceHtml[5] = pricepattern6.exec(ruHttp.responseText)[1];
  622.                 }
  623.                 if (wClass == "discount_final_price") {
  624.                     priceHtml[5] = pricepattern61.exec(ruHttp.responseText)[1];
  625.                 }
  626.                 price[5] = parseFloat(ruvaluepattern.exec(priceHtml[5])[1]);
  627.             }
  628.             catch(err) {
  629.                 //Prevent search from looping around and starting at the beginning
  630.                 if (err.message.search("responseText\\) is null") != -1) {
  631.                 ruHttp = null; priceHtml[5] = "N/A";
  632.                 }
  633.                 if (!priceHtml[5] || priceHtml[5].length == 0)
  634.                     priceHtml[5] = "N/A";
  635.                     price[5] = null;
  636.             }  
  637.  
  638.             if (showYourLocalCurrency && (price[5] != null)) {
  639.                 pricenodes[i].innerHTML += "<br>RU: " + priceHtml[5] + " <span id='rub" + i + "' style='font-weight: bold;'>" + price[5] + "</span>";
  640.                 var tmp06 = document.createElement("script");
  641.                 tmp06.setAttribute("type", "text/javascript");
  642.                 tmp06.innerHTML = "var rub = document.getElementById('rub" + i + "');" +
  643.                 "rub.innerHTML = \"(\" + " + getConvFunction("RUB", "rub") + " + \" " + yourLocalCurrency + ")\";";
  644.                 document.body.insertBefore(tmp06, someNode);
  645.                 createGetDifferenceScript("rub" + i, "RUB", price[0], price[5]);
  646.             } else {
  647.                 pricenodes[i].innerHTML += "<br>RU: " + priceHtml[5]
  648.                 + " <span id='rub" + i + "'></span>"
  649.                 createGetDifferenceScript("rub" + i, "RUB", price[0], price[5]);
  650.             }
  651.         }
  652.     }
  653.  
  654.     //Remove cookie that may store the wrong currency for this region
  655.     document.cookie = "fakeCC=; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/";
  656. }
  657.  
  658. function createGetDifferenceScript(elementid, currencystring, usdPrice, localPrice) {
  659.     if (usdPrice && localPrice) {
  660.         var getdiff = document.createElement("script");
  661.         getdiff.setAttribute("type", "text/javascript");
  662.         getdiff.innerHTML += "var node = document.getElementById('" + elementid
  663.         + "');" + "if (node)"
  664.         + "node.innerHTML += getDifference('" + currencystring + "', " + usdPrice +
  665.         ", " + localPrice + ");";
  666.         document.body.insertBefore(getdiff, someNode);
  667.     }
  668. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement