Difference between revisions of "MediaWiki:Common.js"
From PCGamingWiki, the wiki about fixing PC games
Line 16: | Line 16: | ||
var LinkShare = ''; | var LinkShare = ''; | ||
var LinkShare_Domains = new Array('origin.com'); | var LinkShare_Domains = new Array('origin.com'); | ||
− | var Amazon = 'tag=pcgamingwiki-20'; | + | var Amazon = '?tag=pcgamingwiki-20'; |
− | var AmazonUK = 'tag=pcgamingwiki-21'; | + | var AmazonUK = '?tag=pcgamingwiki-21'; |
− | var GoG = 'pp=708a77db476d737e54b8bf4663fc79b346d696d2'; | + | var GoG = '?pp=708a77db476d737e54b8bf4663fc79b346d696d2'; |
function UpdateLinkRedirection(storeDomain, affTag, before) | function UpdateLinkRedirection(storeDomain, affTag, before) | ||
{ | { | ||
− | $("a[href | + | $("a[href^='http://www." + storeDomain + "']").bind('click keypress', function(event) { |
event.preventDefault(); | event.preventDefault(); | ||
var link = this.href; | var link = this.href; | ||
− | var newLink | + | var newLink = before ? affTag + link : link + affTag; |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
var code = event.charCode || event.keyCode; | var code = event.charCode || event.keyCode; | ||
var button = event.button; | var button = event.button; | ||
if((!code || (code && code == 13)) && (!button || (button && button == 0))) { | if((!code || (code && code == 13)) && (!button || (button && button == 0))) { | ||
window.location = newLink; | window.location = newLink; | ||
− | } else if(button && button | + | } else if(button && button == 1) { |
window.open(newLink); | window.open(newLink); | ||
} | } |
Revision as of 16:00, 6 January 2013
function addAnchorInHeaders() { $('span.mw-headline', '#mw-content-text').each(function() { var $this = $(this); if ($this.attr('id') !== undefined) { $('<span class="mw-linkhere"></span>').text(' • ').append( $('<a></a>').text('Link').attr({title: 'Link', href: '#'+$this.attr('id')}) ).appendTo(this); } }); } $(addAnchorInHeaders); var CJ = 'http://www.dpbolvw.net/click-6723194-10912384?url='; var CJ_Domains = new Array('greenmangaming.com', 'gamersgate.co.uk', 'gamefly.co.uk'); var LinkShare = ''; var LinkShare_Domains = new Array('origin.com'); var Amazon = '?tag=pcgamingwiki-20'; var AmazonUK = '?tag=pcgamingwiki-21'; var GoG = '?pp=708a77db476d737e54b8bf4663fc79b346d696d2'; function UpdateLinkRedirection(storeDomain, affTag, before) { $("a[href^='http://www." + storeDomain + "']").bind('click keypress', function(event) { event.preventDefault(); var link = this.href; var newLink = before ? affTag + link : link + affTag; var code = event.charCode || event.keyCode; var button = event.button; if((!code || (code && code == 13)) && (!button || (button && button == 0))) { window.location = newLink; } else if(button && button == 1) { window.open(newLink); } }); } $(document).ready(function() { //--CJ $.each(CJ_Domains, function(index, domain) { UpdateLinkRedirection(domain, CJ, true); }); //--Linkshare $.each(LinkShare_Domains, function(index, domain) { UpdateLinkRedirection(domain, LinkShare, true); }); //--Amazon UpdateLinkRedirection('amazon.com', Amazon, false); UpdateLinkRedirection('amazon.co.uk', AmazonUK, false); //--GoG UpdateLinkRedirection('gog.com', GoG, false); });