Created
September 22, 2012 21:35
-
-
Save KindDragon/3767912 to your computer and use it in GitHub Desktop.
Compare Steam Prices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Steam Price Comparison - Unpowered edition | |
// @version 2.3.3 | |
// @namespace http://steamunpowered.eu/comparison-script/ | |
// @description Displays prices from all regions in the Steam store and convert them to your local currency | |
// @copyright 2011+, KindDragon; 2010+, Zuko; Original author: Tor (http://code.google.com/p/steam-prices/) | |
// @homepage http://userscripts.org/scripts/show/149928 | |
// @download http://userscripts.org/scripts/source/149928.user.js | |
// @update http://userscripts.org/scripts/source/149928.meta.js | |
// @license MIT License; http://www.opensource.org/licenses/mit-license.php | |
// @include http://store.steampowered.com/app/* | |
// @include https://store.steampowered.com/app/* | |
// @include http://store.steampowered.com/sub/* | |
// @include https://store.steampowered.com/sub/* | |
// @include http://store.steampowered.com/sale/* | |
// @include https://store.steampowered.com/sale/* | |
// @match http://store.steampowered.com/app/* | |
// @match https://store.steampowered.com/app/* | |
// @match http://store.steampowered.com/sub/* | |
// @match https://store.steampowered.com/sub/* | |
// @match http://store.steampowered.com/sale/* | |
// @match https://store.steampowered.com/sale/* | |
// @grant none | |
// ==/UserScript== | |
// To install save script to disk under name CompareSteamPrices.user.js and then open this file in Firefox | |
// Russian prices added by KindDragon (https://github.com/KindDragon) | |
/* | |
* Configuration | |
* If you want to modify the parameters of the script, | |
* please make your changes here. | |
*/ | |
//If set to true, prices converted to your local currency will be displayed | |
var showYourLocalCurrency = true; | |
var yourLocalCurrency = "USD"; | |
//Set your base currency for DLC price conversion | |
var yourDLCBaseCurrency = "USD"; | |
//If set to true, UK prices will be displayed (in addition to US and EU and AU prices) | |
var showUKPrice = true; | |
/* | |
* If set to true, the script will display prices from both of Valve's | |
* price regions, or "tiers". If false, the script will show only your | |
* country's prices. More details on the tiers can be found here: | |
* http://steamunpowered.eu/page.php?id=139 | |
* For games where prices are equal in all regions, the script will display | |
* only one value no matter what this setting is configured to. | |
*/ | |
var showTieredEuPrices = true; | |
//If set to true, AU prices will be displayed (in addition to US and EU and RU prices) | |
var showAUPrice = true; | |
//If set to true, RUS prices will be displayed (in addition to US and EU and AU prices) | |
var showRUPrice = true; | |
//If set to true, Brazillian prices will be displayed (in addition to US and EU and AU and RU prices) | |
var showBRPrice = true; | |
//These parameters contain one country code from each of the European tiers. | |
var tier1cc = "se"; | |
var tier2cc = "pl"; | |
//Change this parameter to add VAT to the US price displayed. | |
//E.g. if set to 19, the script will increase US prices by 19%. | |
var usVat = 0; | |
/* | |
* End of configuration area | |
* Don't make changes below this line unless you know what you're doing. | |
*/ | |
var urlGamePattern = new RegExp(/^https?:\/\/store.steampowered.com\/(?:app|sub)\/\d+\/?(?:\?(?:(?!cc)\w+=[^&]*&?)*)?$/i); | |
var urlSalePattern = new RegExp(/^https?:\/\/store.steampowered.com\/sale\/\w+\/?(?:\?(?:(?!cc)\w+=[^&]*&?)*)?$/i); | |
//var urlGenrePattern = new RegExp(/^https?:\/\/store.steampowered.com\/genre\/.+\/?/i); | |
var usHttp; | |
var ukHttp; | |
var eu1Http; | |
var eu2Http; | |
var auHttp; | |
var ruHttp; | |
var brHttp; | |
var pricenodes = new Array(); | |
var pricenodes_conly = new Array(); | |
var originalprices = new Array(); | |
var originalprices_conly = new Array(); | |
var ukscript; | |
var euscript; | |
var auscript; | |
var ruscript; | |
var localeurscript; | |
var localusdscript; | |
var localgbpscript; | |
var localrubscript; | |
var someNode; | |
var tier1text = "Albania, Andorra, Austria, Belgium, Denmark, Finland, " + | |
"France, Germany, Ireland, Liechtenstein, Luxembourg, Macedonia, " + | |
"Netherlands, Sweden, Switzerland"; | |
var tier2text = "Bosnia and Herzegovina, Bulgaria, Croatia, Cyprus, " + | |
"Czech Republic, Estonia, Greece, Hungary, Italy, Latvia, Lithuania, " + | |
"Malta, Monaco, Montenegro, Norway, Poland, Portugal, Romania, San Marino, " + | |
"Serbia, Slovakia, Slovenia, Spain, Vatican City"; | |
function getCountryPageUrl(country) | |
{ | |
var pos=document.documentURI.indexOf('?'); | |
if (pos < 0) | |
return document.documentURI+"?cc="+country; | |
else | |
return document.documentURI+"&cc="+country; | |
} | |
//Test the URL to see if we're on a game page | |
if (urlGamePattern.test(document.documentURI) || urlSalePattern.test(document.documentURI)) { | |
someNode = document.getElementById("global_header"); | |
console.log("fdsfasFD"); | |
//For security reasons, JavaScript code isn't allowed to fetch data from | |
//external websites. Instead, we insert a HTML <script> tag that fetches | |
//external javascript files. These will help with currency conversion. | |
if (showUKPrice) { | |
ukscript = document.createElement("script"); | |
ukscript.setAttribute("type", "text/javascript"); | |
ukscript.setAttribute("src", | |
"http://javascriptexchangerate.appspot.com/?from=USD&to=GBP"); | |
document.body.insertBefore(ukscript, someNode); | |
} | |
if (showYourLocalCurrency) { | |
localeurscript = document.createElement("script"); | |
localeurscript.setAttribute("type", "text/javascript"); | |
//localscript.setAttribute("src", | |
//"http://javascriptexchangerate.appspot.com/?from=" + yourDLCBaseCurrency + "&to=" + yourLocalCurrency); | |
localeurscript.setAttribute("src", | |
"http://javascriptexchangerate.appspot.com/?from=EUR&to="+yourLocalCurrency); | |
document.body.insertBefore(localeurscript, someNode); | |
localusdscript = document.createElement("script"); | |
localusdscript.setAttribute("type", "text/javascript"); | |
localusdscript.setAttribute("src", | |
"http://javascriptexchangerate.appspot.com/?from=USD&to="+yourLocalCurrency); | |
document.body.insertBefore(localusdscript, someNode); | |
localgbpscript = document.createElement("script"); | |
localgbpscript.setAttribute("type", "text/javascript"); | |
localgbpscript.setAttribute("src", | |
"http://javascriptexchangerate.appspot.com/?from=GBP&to="+yourLocalCurrency); | |
document.body.insertBefore(localgbpscript, someNode); | |
localrubscript = document.createElement("script"); | |
localrubscript.setAttribute("type", "text/javascript"); | |
localrubscript.setAttribute("src", | |
"http://javascriptexchangerate.appspot.com/?from=RUB&to="+yourLocalCurrency); | |
document.body.insertBefore(localrubscript, someNode); | |
localbrlscript = document.createElement("script"); | |
localbrlscript.setAttribute("type", "text/javascript"); | |
localbrlscript.setAttribute("src", | |
"http://javascriptexchangerate.appspot.com/?from=BRL&to="+yourLocalCurrency); | |
document.body.insertBefore(localbrlscript, someNode); | |
} | |
euscript = document.createElement("script"); | |
euscript.setAttribute("type", "text/javascript"); | |
euscript.setAttribute("src", | |
"http://javascriptexchangerate.appspot.com/?from=USD&to=EUR"); | |
document.body.insertBefore(euscript, someNode); | |
/* not needed, since price is in USD for the Australian site | |
but converting to USD to USD will let us change the script easily | |
in case the Australian steam site moves to AUD */ | |
/* | |
if (showAUPrice) { | |
auscript = document.createElement("script"); | |
auscript.setAttribute("type", "text/javascript"); | |
auscript.setAttribute("src", | |
"http://javascriptexchangerate.appspot.com/?from=USD&to=USD"); | |
document.body.insertBefore(auscript, someNode); | |
} | |
*/ | |
if (showRUPrice) { | |
ruscript = document.createElement("script"); | |
ruscript.setAttribute("type", "text/javascript"); | |
ruscript.setAttribute("src", | |
"http://javascriptexchangerate.appspot.com/?from=USD&to=RUB"); | |
document.body.insertBefore(ruscript, someNode); | |
} | |
if (showBRPrice) { | |
ruscript = document.createElement("script"); | |
ruscript.setAttribute("type", "text/javascript"); | |
ruscript.setAttribute("src", | |
"http://javascriptexchangerate.appspot.com/?from=USD&to=BRL"); | |
document.body.insertBefore(ruscript, someNode); | |
} | |
var game_purchase_price = false; | |
var discount_final_price = false; | |
//Test to see if the game has a price | |
divnodes = document.getElementsByTagName("div"); | |
for (i=0; i<divnodes.length; i++) { | |
if (divnodes[i].getAttribute("class") == "game_purchase_price price") { | |
game_purchase_price = true; | |
pricenodes.push(divnodes[i]); | |
if (!showTieredEuPrices) | |
originalprices.push(divnodes[i].innerHTML); | |
divnodes[i].innerHTML += | |
"<br/><span style='color: rgb(136, 136, 136);'>Collecting data...</span>" | |
divnodes[i].style.textAlign = "left"; | |
} | |
if ((divnodes[i].getAttribute("class") == "game_area_dlc_price") && (divnodes[i].innerHTML.indexOf("discount_final_price") == -1)) { | |
if (showYourLocalCurrency) { | |
pricenodes_conly.push(divnodes[i]); | |
originalprices_conly.push(divnodes[i].innerHTML); | |
divnodes[i].innerHTML += | |
"<span style='color: rgb(136, 136, 136);'>Collecting data...</span>" | |
divnodes[i].style.textAlign = "left"; | |
} | |
} else if ((divnodes[i].getAttribute("class") == "discount_final_price") && (divnodes[i].innerHTML.indexOf("<") == -1)) { | |
if (divnodes[i-4].parentNode.className != 'game_area_dlc_price') { | |
discount_final_price = true; | |
pricenodes.push(divnodes[i]); | |
if (!showTieredEuPrices) | |
originalprices.push(divnodes[i].innerHTML); | |
divnodes[i].innerHTML += | |
"<br/><span style='color: rgb(136, 136, 136);'>Collecting data...</span>" | |
divnodes[i].style.textAlign = "left"; | |
} else if (showYourLocalCurrency) { | |
pricenodes_conly.push(divnodes[i]); | |
originalprices_conly.push(divnodes[i].innerHTML); | |
divnodes[i].innerHTML += | |
"<span style='color: rgb(136, 136, 136);'> Collecting data...</span>" | |
divnodes[i].style.textAlign = "right"; | |
} | |
} | |
} | |
//If the current page contains a price, | |
//start downloading regional versions of this page | |
if ((pricenodes.length > 0) || (pricenodesdlc.length > 0)) { | |
//Create cookie that prevents the age verification | |
//dialog from breaking the script | |
if (document.cookie.indexOf("birthtime") < 0) { //Check if cookie exists | |
var date = new Date(); | |
date.setTime(date.getTime()+(365*24*60*60*1000));//Expires in 365 days | |
document.cookie = "birthtime=1; expires=" //birthtime is set to 1 Jan 1900 | |
+ date.toGMTString() + "; path=/" | |
} | |
//Set up HTTP requests | |
usHttp = new XMLHttpRequest(); | |
usHttp.onreadystatechange=stateChanged; | |
usHttp.open("GET",getCountryPageUrl("us"),true); | |
usHttp.send(null); | |
if (showUKPrice) { | |
ukHttp = new XMLHttpRequest(); | |
ukHttp.onreadystatechange=stateChanged; | |
ukHttp.open("GET",getCountryPageUrl("uk"),true); | |
ukHttp.send(null); | |
} | |
if (showTieredEuPrices) { | |
eu1Http = new XMLHttpRequest(); | |
eu1Http.onreadystatechange=stateChanged; | |
eu1Http.open("GET",getCountryPageUrl(tier1cc),true); | |
eu1Http.send(null); | |
eu2Http = new XMLHttpRequest(); | |
eu2Http.onreadystatechange=stateChanged; | |
eu2Http.open("GET",getCountryPageUrl(tier2cc),true); | |
eu2Http.send(null); | |
} | |
if (showAUPrice) { | |
auHttp = new XMLHttpRequest(); | |
auHttp.onreadystatechange=stateChanged; | |
auHttp.open("GET",getCountryPageUrl("au"),true); | |
auHttp.send(null); | |
} | |
if (showRUPrice) { | |
ruHttp = new XMLHttpRequest(); | |
ruHttp.onreadystatechange=stateChanged; | |
ruHttp.open("GET",getCountryPageUrl("ru"),true); | |
ruHttp.send(null); | |
} | |
if (showBRPrice) { | |
brHttp = new XMLHttpRequest(); | |
brHttp.onreadystatechange=stateChanged; | |
brHttp.open("GET",getCountryPageUrl("br"),true); | |
brHttp.send(null); | |
} | |
var style = document.createElement("style"); | |
style.type = "text/css"; | |
style.title = 'compareSteamPrices'; | |
document.getElementsByTagName('head')[0].appendChild(style); | |
// Get stylesheet object | |
var s; | |
for(i in document.styleSheets ) | |
if( document.styleSheets[i].title == 'compareSteamPrices' ) | |
s = document.styleSheets[i]; | |
if (game_purchase_price) | |
s.insertRule(".game_area_purchase_game .game_purchase_action{height:auto;bottom:auto}", s.cssRules.length); | |
if (discount_final_price) | |
s.insertRule(".game_purchase_action .game_purchase_price, .game_purchase_discount{height:auto;padding-bottom:8px}", s.cssRules.length); | |
s.insertRule(".game_purchase_action_bg{height:auto;bottom:auto!important}", s.cssRules.length); | |
s.insertRule(".game_purchase_action .game_purchase_price{height:auto;padding-bottom:8px}", s.cssRules.length); | |
var margin = 30; | |
if (showUKPrice) margin += 16; | |
if (showTieredEuPrices) margin += 16; | |
if (showAUPrice) margin += 16; | |
if (showRUPrice) margin += 16; | |
if (showBRPrice) margin += 16; | |
s.insertRule(".game_area_purchase_game,.sale_page_purchase_package{margin-bottom:"+margin+"px!important}", s.cssRules.length); | |
s.insertRule(".block.block_content{margin-bottom:"+margin+"px!important}", s.cssRules.length); | |
} | |
} | |
function getConvFunction(currency, id) | |
{ | |
if (currency != yourLocalCurrency) | |
return "Math.round(" + currency + "to" + yourLocalCurrency + "(" + id + ".innerHTML * 100))/100"; | |
else | |
return id + ".innerHTML"; | |
} | |
//Extracts prices from the downloaded HTML and displays them | |
function stateChanged() { | |
//Check to see of all scripts have completed | |
if (usHttp.readyState != 4) return; | |
if (showUKPrice && ukHttp.readyState != 4) return; | |
if (showTieredEuPrices && (eu1Http.readyState != 4 || eu2Http.readyState != 4)) return; | |
if (showAUPrice && auHttp.readyState != 4) return; | |
if (showRUPrice && ruHttp.readyState != 4) return; | |
if (showBRPrice && brHttp.readyState != 4) return; | |
//All requests completed, good to go | |
//The pattern variables can't be reused because it's global, so just duplicate | |
var uspricepattern = | |
new RegExp(/<div class="(?:game_purchase_price price|discount_final_price)"[^>]*>([^<]+?)<\/div>/gi); | |
var ukpricepattern = | |
new RegExp(/<div class="(?:game_purchase_price price|discount_final_price)"[^>]*>([^<]+?)<\/div>/gi); | |
var eu1pricepattern = | |
new RegExp(/<div class="(?:game_purchase_price price|discount_final_price)"[^>]*>([^<]+?)<\/div>/gi); | |
var eu2pricepattern = | |
new RegExp(/<div class="(?:game_purchase_price price|discount_final_price)"[^>]*>([^<]+?)<\/div>/gi); | |
var aupricepattern = | |
new RegExp(/<div class="(?:game_purchase_price price|discount_final_price)"[^>]*>([^<]+?)<\/div>/gi); | |
var rupricepattern = | |
new RegExp(/<div class="(?:game_purchase_price price|discount_final_price)"[^>]*>([^<]+?)<\/div>/gi); | |
var brpricepattern = | |
new RegExp(/<div class="(?:game_purchase_price price|discount_final_price)"[^>]*>([^<]+?)<\/div>/gi); | |
var priceHtml = new Array(7); | |
var mypriceHtml; | |
var usvaluepattern = new RegExp(/$([\d\.]+)/i); | |
var ukvaluepattern = new RegExp(/£([\d\.]+)/i); | |
var euvaluepattern = new RegExp(/([\d,-]+)€/i); | |
var auvaluepattern = new RegExp(/$([\d\.]+)[\s]USD/i); | |
var ruvaluepattern = new RegExp(/([\d\.]+) pуб./i); | |
var brvaluepattern = new RegExp(/R$ ([\d,]+)/i); | |
var localvaluepattern = new RegExp(/([\d,-]+)/i); | |
var price = new Array(7); | |
var myprice; | |
var calcscript = "function getDifference(currency, usdPrice, localPrice) " + | |
"{\n" + | |
" var usdConverted; var lessmore; var diff;\n" + | |
" if (currency == 'GBP') {usdConverted = USDtoGBP(usdPrice);}\n" + | |
" else if (currency == 'EUR') {usdConverted = USDtoEUR(usdPrice);}\n" + | |
" else if (currency == 'RUB') {usdConverted = USDtoRUB(usdPrice);}\n" + | |
" else if (currency == 'BRL') {usdConverted = USDtoBRL(usdPrice);}\n" + | |
//" else if (currency == 'USD') {usdConverted = USDtoUSD(usdPrice);}\n" + | |
" else if (currency == 'USD') {usdConverted = usdPrice;}\n" + | |
" diff = Math.abs((localPrice/usdConverted)*100-100);\n" + | |
" if (localPrice == usdConverted) {lessmore = '<img src=\"http://www.steamunpowered.eu/orangebar.png\" width=\"9\" height=\"5\" border=\"0\">';}\n" + | |
" else if (localPrice > usdConverted) {lessmore = '<img src=\"http://www.steamunpowered.eu/uparrow.png\" width=\"7\" height=\"9\" border=\"0\">';}\n" + | |
" else {lessmore = '<img src=\"http://www.steamunpowered.eu/downarrow.png\" width=\"7\" height=\"9\" border=\"0\">';}\n" + | |
" if (localPrice == usdConverted) {return ' <span style=\"color: #ac9b09; font-weight: normal\">(' + lessmore + ')</span>';}\n" + | |
" else if (localPrice > usdConverted) {return ' <span style=\"color: #f00; font-weight: normal\">(' + Math.round(diff) + '% ' + lessmore + ')</span>'}\n" + | |
" else return ' <span style=\"color: #4fc20f; font-weight: normal\">(' + Math.round(diff) + '% ' + lessmore + ')</span>';}\n"; | |
var calcscript_opera = "function getDifference(currency, usdPrice, localPrice) " + | |
"{\n" + | |
" var usdConverted; var lessmore; var diff;\n" + | |
" if (currency == 'GBP') {usdConverted = USDtoGBP(usdPrice);}\n" + | |
" else if (currency == 'EUR') {usdConverted = USDtoEUR(usdPrice);}\n" + | |
" else if (currency == 'RUB') {usdConverted = USDtoRUB(usdPrice);}\n" + | |
" else if (currency == 'BRL') {usdConverted = USDtoBRL(usdPrice);}\n" + | |
//" else if (currency == 'USD') {usdConverted = USDtoUSD(usdPrice);}\n" + | |
" else if (currency == 'USD') {usdConverted = usdPrice;}\n" + | |
" diff = Math.abs((localPrice/usdConverted)*100-100);\n" + | |
" if (localPrice == usdConverted) {lessmore = 'prices are equal'; return ' (' + lessmore + ')';} \n" + | |
" else if (localPrice > usdConverted) {lessmore = 'higher';}\n" + | |
" else {lessmore = 'lower';}\n" + | |
" return ' (' + Math.round(diff) + '% ' + lessmore + ')';}\n"; | |
var calculatescript = document.createElement("script"); | |
calculatescript.setAttribute("type", "text/javascript"); | |
//Shitty Opera browser detection | |
if (navigator.appName == "Opera") { | |
calculatescript.innerHTML = calcscript_opera; | |
} else { | |
calculatescript.innerHTML = calcscript; | |
} | |
document.body.insertBefore(calculatescript, someNode); | |
//For DLC on game page | |
var mypriceHtml_conly; | |
var myprice_conly; | |
for (i = 0; i < pricenodes_conly.length; i++) { | |
try { | |
var myvaluepattern_conly = new RegExp(/([\d,-]+)/i); | |
mypriceHtml_conly = originalprices_conly[i]; | |
myprice_conly = parseFloat(myvaluepattern_conly.exec(originalprices_conly[i])[1].replace(",", ".").replace("--", "00")); | |
} | |
catch(err) { | |
if (!mypriceHtml_conly || mypriceHtml_conly.length == 0) | |
mypriceHtml_conly = "N/A"; | |
myprice_conly = null; | |
} | |
if (showYourLocalCurrency) { | |
pricenodes_conly[i].innerHTML = mypriceHtml_conly + " <span id='dlc" + i + "' style='font-weight: bold; color: rgb(136, 136, 136);'>" + myprice_conly + "</span>"; | |
var dlc00 = document.createElement("script"); | |
dlc00.setAttribute("type", "text/javascript"); | |
dlc00.innerHTML = "var dlc = document.getElementById('dlc" + i + "');" + | |
"dlc.innerHTML = \"(\" + " + getConvFunction(yourDLCBaseCurrency, "dlc") + " + \" " + yourLocalCurrency + ")\";"; | |
document.body.insertBefore(dlc00, someNode); | |
} | |
} | |
for (i=0; i<pricenodes.length; i++) { | |
if (!showTieredEuPrices) { | |
try { | |
var myvaluepattern = new RegExp(/([\d,-]+)/i); | |
mypriceHtml = originalprices[i]; | |
myprice = parseFloat(myvaluepattern.exec(originalprices[i])[1].replace(",", ".").replace("--", "00")); | |
} | |
catch(err) { | |
if (!mypriceHtml || mypriceHtml.length == 0) | |
mypriceHtml = "N/A"; | |
myprice = null; | |
} | |
} | |
//Search for the price information in the downloaded HTML documents | |
try { | |
priceHtml[0] = uspricepattern.exec(usHttp.responseText)[1]; | |
price[0] = parseFloat(usvaluepattern.exec(priceHtml[0])[1]); | |
if (usVat > 0) { | |
price[0] = price[0] * (1 + (usVat / 100)); | |
priceHtml[0] = "$" + price[0].toFixed(2); | |
} | |
} | |
catch(err) { | |
//Prevent search from looping around and starting at the beginning | |
if (err.message.search("responseText\\) is null") != -1) { | |
usHttp = null; priceHtml[0] = "N/A"; | |
} | |
if (!priceHtml[0] || priceHtml[0].length == 0) | |
priceHtml[0] = "N/A"; | |
price[0] = null; | |
} | |
var country = null | |
if (typeof g_oSuggestParams != 'undefined') | |
country = g_oSuggestParams.cc; | |
if (showYourLocalCurrency && (price[0] != null) && (country != "US")) { | |
if (usVat > 0) { | |
pricenodes[i].innerHTML = "US: " + priceHtml[0] + " (inc. " + usVat + "% VAT)" + " <span id='us" + i + "' style='font-weight: bold;'>" + price[0] + "</span>"; | |
} else { | |
pricenodes[i].innerHTML = "US: " + priceHtml[0] + " <span id='us" + i + "' style='font-weight: bold;'>" + price[0] + "</span>"; | |
} | |
var tmp00 = document.createElement("script"); | |
tmp00.setAttribute("type", "text/javascript"); | |
if (usVat > 0) { | |
tmp00.innerHTML = "var us = document.getElementById('us" + i + "');" + | |
"us.innerHTML = \"(\" + " + getConvFunction("USD", "us") + " + \" " + yourLocalCurrency + " inc. " + usVat + "% VAT)\";"; | |
} else { | |
tmp00.innerHTML = "var us = document.getElementById('us" + i + "');" + | |
"us.innerHTML = \"(\" + " + getConvFunction("USD", "us") + " + \" " + yourLocalCurrency + ")\";"; | |
} | |
document.body.insertBefore(tmp00, someNode); | |
} else { | |
pricenodes[i].innerHTML = "US: " + priceHtml[0]; | |
if (usVat > 0) | |
pricenodes[i].innerHTML += " (inc. " + usVat + "% VAT)"; | |
} | |
if (showRUPrice) { | |
try { | |
priceHtml[5] = rupricepattern.exec(ruHttp.responseText)[1]; | |
price[5] = parseFloat(ruvaluepattern.exec(priceHtml[5])[1]); | |
} | |
catch(err) { | |
//Prevent search from looping around and starting at the beginning | |
if (err.message.search("responseText\\) is null") != -1) { | |
ruHttp = null; priceHtml[5] = "N/A"; | |
} | |
if (!priceHtml[5] || priceHtml[5].length == 0) | |
priceHtml[5] = "N/A"; | |
price[5] = null; | |
} | |
if (showYourLocalCurrency && (price[5] != null) && (country != "RU")) { | |
pricenodes[i].innerHTML += "<br>RU: " + priceHtml[5] + " <span id='rub" + i + "' style='font-weight: bold;'>" + price[5] + "</span>"; | |
var tmp06 = document.createElement("script"); | |
tmp06.setAttribute("type", "text/javascript"); | |
tmp06.innerHTML = "var rub = document.getElementById('rub" + i + "');" + | |
"rub.innerHTML = \"(\" + " + getConvFunction("RUB", "rub") + " + \" " + yourLocalCurrency + ")\";"; | |
document.body.insertBefore(tmp06, someNode); | |
createGetDifferenceScript("rub" + i, "RUB", price[0], price[5]); | |
} else { | |
pricenodes[i].innerHTML += "<br>RU: " + priceHtml[5] | |
+ " <span id='rub" + i + "'></span>" | |
createGetDifferenceScript("rub" + i, "RUB", price[0], price[5]); | |
} | |
} | |
if (showBRPrice) { | |
try { | |
priceHtml[6] = brpricepattern.exec(brHttp.responseText)[1]; | |
price[6] = parseFloat(brvaluepattern.exec(priceHtml[6])[1].replace(",", ".")); | |
} | |
catch(err) { | |
//Prevent search from looping around and starting at the beginning | |
if (err.message.search("responseText\\) is null") != -1) { | |
ruHttp = null; priceHtml[6] = "N/A"; | |
} | |
if (!priceHtml[6] || priceHtml[6].length == 0) | |
priceHtml[6] = "N/A"; | |
price[6] = null; | |
} | |
if (showYourLocalCurrency && (price[6] != null) && (country != "BR")) { | |
pricenodes[i].innerHTML += "<br>BR: " + priceHtml[6] + " <span id='brl" + i + "' style='font-weight: bold;'>" + price[6] + "</span>"; | |
var tmp07 = document.createElement("script"); | |
tmp07.setAttribute("type", "text/javascript"); | |
tmp07.innerHTML = "var brl = document.getElementById('brl" + i + "');" + | |
"brl.innerHTML = \"(\" + " + getConvFunction("BRL", "brl") + " + \" " + yourLocalCurrency + ")\";"; | |
document.body.insertBefore(tmp07, someNode); | |
createGetDifferenceScript("brl" + i, "BRL", price[0], price[6]); | |
} else { | |
pricenodes[i].innerHTML += "<br>BR: " + priceHtml[6] | |
+ " <span id='brl" + i + "'></span>" | |
createGetDifferenceScript("brl" + i, "BRL", price[0], price[6]); | |
} | |
} | |
if (showUKPrice) { | |
try { | |
priceHtml[1] = ukpricepattern.exec(ukHttp.responseText)[1]; | |
price[1] = parseFloat(ukvaluepattern.exec(priceHtml[1])[1]); | |
} | |
catch(err) { | |
//Prevent search from looping around and starting at the beginning | |
if (err.message.search("responseText\\) is null") != -1) { | |
ukHttp = null; priceHtml[1] = "N/A"; | |
} | |
if (!priceHtml[1] || priceHtml[1].length == 0) | |
priceHtml[1] = "N/A"; | |
price[1] = null; | |
} | |
if (showYourLocalCurrency && (price[1] != null) && (country != "UK")) { | |
pricenodes[i].innerHTML += "<br>UK: " + priceHtml[1] + " <span id='gbp" + i + "' style='font-weight: bold;'>" + price[1] + "</span>"; | |
var tmp01 = document.createElement("script"); | |
tmp01.setAttribute("type", "text/javascript"); | |
tmp01.innerHTML = "var gbp = document.getElementById('gbp" + i + "');" + | |
"gbp.innerHTML = \"(\" + " + getConvFunction("GBP", "gbp") + " + \" " + yourLocalCurrency + ")\";"; | |
document.body.insertBefore(tmp01, someNode); | |
createGetDifferenceScript("gbp" + i, "GBP", price[0], price[1]); | |
} else { | |
pricenodes[i].innerHTML += "<br>UK: " + priceHtml[1] | |
+ " <span id='gbp" + i + "'></span>" | |
createGetDifferenceScript("gbp" + i, "GBP", price[0], price[1]); | |
} | |
} | |
if (showTieredEuPrices) { | |
try { | |
priceHtml[2] = eu1pricepattern.exec(eu1Http.responseText)[1]; | |
} | |
catch(err) { | |
//Prevent search from looping around and starting at the beginning | |
if (err.message.search("responseText\\) is null") != -1) { | |
eu1Http = null; priceHtml[2] = "N/A"; | |
} | |
if (!priceHtml[2] || priceHtml[2].length == 0) | |
priceHtml[2] = "N/A"; | |
} | |
try { | |
priceHtml[3] = eu2pricepattern.exec(eu2Http.responseText)[1]; | |
} | |
catch(err) { | |
//Prevent search from looping around and starting at the beginning | |
if (err.message.search("responseText\\) is null") != -1) { | |
eu2Http = null; priceHtml[3] = "N/A"; | |
} | |
if (!priceHtml[3] || priceHtml[3].length == 0) | |
priceHtml[3] = "N/A"; | |
} | |
var t; | |
for (t = 2; t < 4; t++) { | |
try { | |
price[t] = parseFloat(euvaluepattern.exec(priceHtml[t])[1].replace(",", ".").replace("--", "00")); | |
} catch(err) { | |
price[t] = null; | |
} | |
} | |
//If tier 1 and 2 prices are equal, display only one EU price | |
if (price[2] == price[3]) { | |
if (showYourLocalCurrency && (price[2] != null) && (price[3] != null)) { | |
pricenodes[i].innerHTML += "<br>EU: " + priceHtml[2] + " <span id='eur1_" + i + "' style='font-weight: bold;'>" + price[2] + "</span>"; | |
var tmp01 = document.createElement("script"); | |
tmp01.setAttribute("type", "text/javascript"); | |
tmp01.innerHTML = "var eur1_ = document.getElementById('eur1_" + i + "');" + | |
"eur1_.innerHTML = \"(\" + " + getConvFunction("EUR", "eur1_") + " + \" " + yourLocalCurrency + ")\";"; | |
document.body.insertBefore(tmp01, someNode); | |
createGetDifferenceScript("eur1_" + i, "EUR", price[0], price[2]); | |
} else { | |
pricenodes[i].innerHTML += "<br>EU: " + priceHtml[2] | |
+ " <span id='eur1_" + i + "'></span>"; | |
createGetDifferenceScript("eur1_" + i, "EUR", price[0], price[2]); | |
} | |
} else { //...but if they differ, display both | |
if (showYourLocalCurrency && (price[2] != null)) { | |
pricenodes[i].innerHTML += "<br>EU Tier 1: " + priceHtml[2] + " <span id='eur1_" + i + "' style='font-weight: bold;'>" + price[2] + "</span>"; | |
var tmp02 = document.createElement("script"); | |
tmp02.setAttribute("type", "text/javascript"); | |
tmp02.innerHTML = "var eur1_ = document.getElementById('eur1_" + i + "');" + | |
"eur1_.innerHTML = \"(\" + " + getConvFunction("EUR", "eur1_") + " + \" " + yourLocalCurrency + ")\";"; | |
document.body.insertBefore(tmp02, someNode); | |
createGetDifferenceScript("eur1_" + i, "EUR", price[0], price[2]); | |
} else { | |
pricenodes[i].innerHTML += "<br><span title='" + tier1text | |
+ "'>EU Tier 1: " + priceHtml[2] | |
+ " <span id='eur1_" + i + "'></span></span>"; | |
createGetDifferenceScript("eur1_" + i, "EUR", price[0], price[2]); | |
} | |
if (showYourLocalCurrency && (price[3] != null)) { | |
pricenodes[i].innerHTML += "<br>EU Tier 2: " + priceHtml[3] + " <span id='eur2_" + i + "' style='font-weight: bold;'>" + price[3] + "</span>"; | |
var tmp03 = document.createElement("script"); | |
tmp03.setAttribute("type", "text/javascript"); | |
tmp03.innerHTML = "var eur2_ = document.getElementById('eur2_" + i + "');" + | |
"eur2_.innerHTML = \"(\" + " + getConvFunction("EUR", "eur2_") + " + \" " + yourLocalCurrency + ")\";"; | |
document.body.insertBefore(tmp03, someNode); | |
createGetDifferenceScript("eur2_" + i, "EUR", price[0], price[3]); | |
} else { | |
pricenodes[i].innerHTML += "<br><span title='" + tier2text | |
+ "'>EU Tier 2: " + priceHtml[3] | |
+ " <span id='eur2_" + i + "'></span></span>"; | |
createGetDifferenceScript("eur2_" + i, "EUR", price[0], price[3]); | |
} | |
} | |
} else { //Ignore country codes, only display price for YOUR region | |
if (showYourLocalCurrency && (myprice != null)) { | |
pricenodes[i].innerHTML += "<br>You: " + mypriceHtml + " <span id='myprice" + i + "' style='font-weight: bold;'>" + myprice + "</span>"; | |
var tmp04 = document.createElement("script"); | |
tmp04.setAttribute("type", "text/javascript"); | |
tmp04.innerHTML = "var myprice = document.getElementById('myprice" + i + "');" + | |
"myprice.innerHTML = \"(\" + " + getConvFunction("EUR", "myprice") + " + \" " + yourLocalCurrency + ")\";"; | |
document.body.insertBefore(tmp04, someNode); | |
createGetDifferenceScript("myprice" + i, "EUR", price[0], myprice); | |
} else { | |
pricenodes[i].innerHTML += "<br>You: " + mypriceHtml | |
+ " <span id='myprice" + i + "'></span>"; | |
createGetDifferenceScript("myprice" + i, "EUR", price[0], myprice); | |
} | |
} | |
if (showAUPrice) { | |
try { | |
priceHtml[4] = aupricepattern.exec(auHttp.responseText)[1]; | |
price[4] = parseFloat(auvaluepattern.exec(priceHtml[4])[1]); | |
} | |
catch(err) { | |
//Prevent search from looping around and starting at the beginning | |
if (err.message.search("responseText\\) is null") != -1) { | |
auHttp = null; priceHtml[4] = "N/A"; | |
} | |
if (!priceHtml[4] || priceHtml[4].length == 0) | |
priceHtml[4] = "N/A"; | |
price[4] = null; | |
} | |
if (showYourLocalCurrency && (price[4] != null)) { | |
pricenodes[i].innerHTML += "<br>AU: " + priceHtml[4] + " <span id='aud" + i + "' style='font-weight: bold;'>" + price[4] + "</span>"; | |
var tmp05 = document.createElement("script"); | |
tmp05.setAttribute("type", "text/javascript"); | |
tmp05.innerHTML = "var aud = document.getElementById('aud" + i + "');" + | |
"aud.innerHTML = \"(\" + " + getConvFunction("USD", "aud") + " + \" " + yourLocalCurrency + ")\";"; | |
document.body.insertBefore(tmp05, someNode); | |
createGetDifferenceScript("aud" + i, "USD", price[0], price[4]); | |
} else { | |
pricenodes[i].innerHTML += "<br>AU: " + priceHtml[4] | |
+ " <span id='aud" + i + "'></span>" | |
createGetDifferenceScript("aud" + i, "USD", price[0], price[4]); | |
} | |
} | |
} | |
//Remove cookie that may store the wrong currency for this region | |
document.cookie = "fakeCC=; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/"; | |
} | |
function createGetDifferenceScript(elementid, currencystring, usdPrice, localPrice) { | |
if (usdPrice && localPrice) { | |
var getdiff = document.createElement("script"); | |
getdiff.setAttribute("type", "text/javascript"); | |
getdiff.innerHTML += "var node = document.getElementById('" + elementid | |
+ "');" + "if (node)" | |
+ "node.innerHTML += getDifference('" + currencystring + "', " + usdPrice + | |
", " + localPrice + ");"; | |
document.body.insertBefore(getdiff, someNode); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New version available here http://bit.ly/WP4nAG