
不废话,上代码。依赖Jquery
$('#content a[href]').each(function () { $this = $(this); var href = this.href; $this.attr('href', 'http://webcache.googleusercontent.com/search?q=cache:' + href); }); 1 pengfei 2015-07-27 12:41:05 +08:00 不懂,怎么用 |
2 xiandao7997 2015-07-27 12:46:56 +08:00 @pengfei 火狐搜 GreaseMonkey, Chrome 搜 TamperMonkey |
3 KCheshireCat 2015-07-27 12:50:57 +08:00 Array.prototype.slice.call(document.querySelectorAll("a[href]")).forEach(function(element, index, array) {element.href = 'http://webcache.googleusercontent.com/search?q=cache:' + element.href;}); 改版为无依赖 |
4 oott123 2015-07-27 13:04:19 +08:00 via Android @KCheshireCat 为啥不 Array.prototype.forEach.call 呢( |
5 KCheshireCat 2015-07-27 13:09:28 +08:00 @oott123 因为我没系统了解过这些东西,都是遇到问题,寻找解决方案这样的。。。。 Array.prototype.forEach.call(document.querySelectorAll("a[href]"), function(element, index, array) {element.href = 'http://webcache.googleusercontent.com/search?q=cache:' + element.href;}); |
6 bramblex OP |
7 yanwen 2015-07-28 17:45:03 +08:00 求个完整版的 user.js 脚本。谢谢。。 |
8 bramblex OP |
9 bramblex OP @KCheshireCat 还是有依赖,不过这次用的方式更聪明了……不直接改链接了,而是劫持链接。虽然这样做有个问题,就是如果右键打开的话就会出问题了…… https://greasyfork.org/zh-CN/scripts/11281-%E5%BF%AB%E7%85%A7%E9%93%BE%E6%8E%A5 // ==UserScript== // @name 快照链接 // @namespace lovearia.me // @description 把谷歌快照的链接全部转换成谷歌快照 // @include http://webcache.googleusercontent.com/search?*q=cache:* // @version 2 // @grant none // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js // ==/UserScript== $('body').on('click', 'a[href]', function (e) { if (!$(this).closest('#google-cache-hdr').length) { var href = 'http://webcache.googleusercontent.com/search?q=cache:' + escape(this.href); location.href = href; e.preventDefault(); } }); |