Anonymous edits have been disabled on the wiki. If you want to contribute please login or create an account.


Warning for game developers: PCGamingWiki staff members will only ever reach out to you using the official press@pcgamingwiki.com mail address.
Be aware of scammers claiming to be representatives or affiliates of PCGamingWiki who promise a PCGW page for a game key.

Difference between revisions of "MediaWiki:Common.js"

From PCGamingWiki, the wiki about fixing PC games
(Undo revision 25463 by Andytizer (talk))
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*='" + storeDomain + "']").bind('click keypress', function(event) {
+
$("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;
if(before) {
 
newLink = affTag + link
 
} else {
 
var queryParam = link.indexOf("?") !== -1 ? '&' : '?';
 
newLink = link + queryParam + 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 === 1) {
+
} 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);
});