Straight Techgig

Remove URL redirection from TechGig

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name Straight Techgig
// @id	straight_techgig_xifos
// @namespace	  in.co.tossing.toolkit.techgig
// @description	Remove URL redirection from TechGig
// @license	GPL v3 or later version
// @include		*://www.techgig.com/*
// @version	0.1
// @author	XiFoS
// ==/UserScript==

(function (d) {
	var all_a = d.getElementsByTagName('a');
	var a = null;
	var match;
	for(i = 0; i < all_a.length; i++) {
		a = all_a.item(i);
		if(a.href) {
			match = a.href.match(/readnews\.php/);
			if(match) {
				a.href = getQueryVariable(a.href, 'tgnews_link');
			}
		}
	}

	function urldecode(url) {
		return decodeURIComponent(url.replace(/\+/g, ' '));
	}

	function getQueryVariable(url, variable) {
		// remove all until the first `?`
		var query = url.split('?');
		query.shift(1);
		var vars = query.join('?').split('&');
		for (var i = 0; i < vars.length; i++) {
			var pair = vars[i].split('=');
			if (urldecode(pair[0]) == variable) {
				return urldecode(pair[1]);
			}
		}
		return null;
	}
})(document);