Advertisement
KindDragon

Compare Steam Prices 2.3

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