刚刚随手写了一个猴子脚本,把 google 网页快照里面的所有链接全部转换成网页快照的链接

2015-07-27 12:37:12 +08:00
 bramblex

不废话,上代码。依赖Jquery

$('#content a[href]').each(function () {
  $this = $(this);
  var href = this.href;
  $this.attr('href', 'http://webcache.googleusercontent.com/search?q=cache:' + href);
});
3070 次点击
所在节点    JavaScript
9 条回复
pengfei
2015-07-27 12:41:05 +08:00
不懂,怎么用
xiandao7997
2015-07-27 12:46:56 +08:00
@pengfei 火狐搜 GreaseMonkey, Chrome 搜 TamperMonkey
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;});

改版为无依赖
oott123
2015-07-27 13:04:19 +08:00
@KCheshireCat 为啥不 Array.prototype.forEach.call 呢(
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;});
bramblex
2015-07-27 13:33:33 +08:00
@KCheshireCat

不错。/w\
yanwen
2015-07-28 17:45:03 +08:00
求个完整版的 user.js 脚本。谢谢。。
bramblex
2015-07-28 19:18:35 +08:00
bramblex
2015-07-28 19:23:37 +08:00
@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();
}
});

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/208616

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX