借用了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)); });