把google搜索结果的缓存链接变成https的gs脚本

Posted on 2010-05-18 15:46  wanderxjtu  阅读(586)  评论(0编辑  收藏  举报
借用了Google click-tracking disabler的代码,对原作者表示感谢。
// ==UserScript==
// @name			ghttpswebcache
// @namespace		wanderxjtu@twitter
// @description		把google搜索结果的缓存链接变成https
// @include		http://www.google.com/search*
// @include		http://www.google.com.hk/search*
// ==/UserScript==
// A test for whether or not an object is a DOM node that can contain other DOM nodes
var domlist = document.body.childNodes.constructor;
function fertile(o) { return (o.childNodes || false) && (o.constructor == domlist); }

// A simple string test we'll be using
if (String.prototype.beginsWith) {
	console.warn('googleclicktrackingdisab.user.js warning: String.prototype.beginsWith() has already been defined');
} else {
	String.prototype.beginsWith = function(s) {return this.slice(0, s.length) == s; }
}

Array.prototype.forEach.call(document.getElementsByTagName('a'), function(el) {
	var s = el.getAttribute('href');
	if (('string' == typeof s) && (s.beginsWith('http://webcache.google')))
		el.setAttribute('href','https:'+s.slice(5,s.length));
});

Copyright © 2024 wanderxjtu
Powered by .NET 8.0 on Kubernetes