Note that in order to reduce spam, I have disabled account creation. If you are willing to help me keep this wiki up to date, please send Angel a private message on Wattpad or on Patreon with the username and password you would like to use. Thank you!
MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
| Line 16: | Line 16: | ||
function updateAmazonLinks() { | function updateAmazonLinks() { | ||
var amazonLinks = document.querySelectorAll('a[data-amazon-asin]'); | var amazonLinks = document.querySelectorAll('a[data-amazon-asin]'); | ||
if (amazonLinks.length | if (amazonLinks.length > 0) { | ||
fetch('https://ip-api.com/json/') | |||
.then(response => response.json()) | |||
.then(data => { | |||
var region = getAmazonRegion(data.countryCode); | |||
amazonLinks.forEach(function(link) { | |||
var finalUrl = getAmazonLink(region, link.getAttribute('data-amazon-asin')); | |||
link.setAttribute('href', finalUrl); | |||
}); | |||
}) | |||
.catch(console.error); | |||
} | |||
} | } | ||
document.addEventListener('DOMContentLoaded', updateAmazonLinks); | document.addEventListener('DOMContentLoaded', updateAmazonLinks); | ||
})(); | })(); | ||
Revision as of 21:39, 22 December 2024
/* Any JavaScript here will be loaded for all users on every page load. */
console.log("testing!");
(function() {
function getAmazonLink(countryCode, asin) {
switch (countryCode) {
case 'GB': return 'https://www.amazon.co.uk/dp/'+asin;
case 'DE': return 'https://www.amazon.de/dp/'+asin;
case 'JP': return 'https://www.amazon.co.jp/dp/'+asin;
case 'CA': return 'https://www.amazon.ca/dp/'+asin;
case 'AU': return 'https://www.amazon.com.au/dp/'+asin;
case 'FR': return 'https://www.amazon.fr/dp/'+asin;
default: return 'https://www.amazon.com/dp/'+asin;
}
}
function updateAmazonLinks() {
var amazonLinks = document.querySelectorAll('a[data-amazon-asin]');
if (amazonLinks.length > 0) {
fetch('https://ip-api.com/json/')
.then(response => response.json())
.then(data => {
var region = getAmazonRegion(data.countryCode);
amazonLinks.forEach(function(link) {
var finalUrl = getAmazonLink(region, link.getAttribute('data-amazon-asin'));
link.setAttribute('href', finalUrl);
});
})
.catch(console.error);
}
}
document.addEventListener('DOMContentLoaded', updateAmazonLinks);
})();