google_direct_link

Google direct link for avoiding laggy '/url?' link.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        google_direct_link
// @namespace   http://catherine.v0cyc1pp.com/google_direct_link.user.js
// @match       https://www.google.tld/search*
// @match       https://www.google.com/?*
// @run-at      document-end
// @author      greg10
// @license     GPL 3.0
// @version     2.2
// @grant       none
// @description Google direct link for avoiding laggy '/url?' link.
// @license     MIT
// ==/UserScript==

// [desctiption details]
// This script will replace links on google search results.
// from
// https://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwjzmeD83cnQAhVBPpQKHQtkC6wQFggbMAA&url=http%3A%2F%2Fwww.nyc.gov%2F&usg=AFQjCNGtbMsqtosAyddPnaeiyyG142mO3A&bvm=bv.139782543,d.dGo
// to
//http://www.nyc.gov/
//
// for avoiding laggy '/url?' link.


function replacelink(elem) {
	var str = elem.getAttribute("href");
	//console.log("str="+str);
	if ( str == null || str == undefined ) {
		return;
	}
	var result = str.match( /&url=([^&]+)&/ );
	if ( result == null || result == undefined ) {
		return;
	}
	var direct = result[1];
	if ( direct == null || direct == undefined ) {
		return;
	}

	var decoded = decodeURIComponent( direct );
	elem.setAttribute("href", decoded);
	elem.setAttribute("ping", str);

}

function main() {
	document.querySelectorAll('a').forEach( function(elem) {
		replacelink(elem);
	});
}


var observer = new MutationObserver(function(mutations) {
    observer.disconnect();
    main();
    observer.observe( document, config);
});

var config = { attributes: true, childList: true, characterData: true, subtree:true };

observer.observe( document, config);