Skip to content

Instantly share code, notes, and snippets.

@JinnLynn
Last active December 10, 2015 23:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JinnLynn/4507194 to your computer and use it in GitHub Desktop.
Save JinnLynn/4507194 to your computer and use it in GitHub Desktop.
在Google搜索结果中避免使用跳转,直接访问目标网址 http://jeeker.net/article/google-search-url-uncover/
javascript:(function(){function getRealUrl(l){if(l.indexOf('/url?')<0)return null;var a=document.createElement('a');a.href=l;seg=a.search.replace(/^\?/,'').split('&');for(i=0;i<seg.length;i++){if(!seg[i])continue;s=seg[i].split('=');if(s[0]=='url')return decodeURIComponent(s[1]);}return null;}var real=getRealUrl(location.href);if(real){window.location.href=real;return;};document.addEventListener('click',function(e){for(a=e.target;a;a=a.parentNode){if(a.localName!='a')continue;real=getRealUrl(a.getAttribute('href'));if(real){alert('d');a.setAttribute('href',real);a.removeAttribute('onmousedown');}break;}},false);})();
{
"name": "Google Search URL Uncover",
"description": "Google 搜索结果链接去除google跳转,直接访问目标网址。",
"manifest_version": 2,
"permissions": [ "tabs" ],
//"update_url": "http://clients2.google.com/service/update2/crx",
"version": "0.1",
"content_scripts": [ {
"all_frames": true,
"js": ["url.js" ],
"matches": [ "*://www.google.com/*",
"*://www.google.com.hk/*",
"*://www.google.com/url*",
"*://www.google.com.hk/url*"
],
//"permissions": [ "tabs" ],
"run_at": "document_start"
} ]
}
(function(){
function getRealUrl(l) {
if (l.indexOf('/url?') < 0)
return null;
var a = document.createElement('a');
a.href = l;
seg = a.search.replace(/^\?/,'').split('&');
for (i = 0; i < seg.length; i++) {
if (!seg[i])
continue;
s = seg[i].split('=');
if (s[0] == 'url')
return decodeURIComponent( s[1] );
}
return null;
}
/**
* 直接在载入http:://www.google.com/url?.... 中重定向到真实的目标网址
* 问题:当目标网址无法访问时,地址栏中的地址信息并未改变到目标网址,可能产生误解
*/
var real = getRealUrl(location.href);
if (real) {
window.location.href = real;
return;
};
document.addEventListener('click', function(e){
for(a = e.target; a; a = a.parentNode) {
if(a.localName != 'a')
continue;
real = getRealUrl( a.getAttribute('href') );
if (real) {
a.setAttribute( 'href', real );
a.removeAttribute('onmousedown');
}
break;
}
}, false);
})();
// ==UserScript==
// @name Google URL Uncover
// @namespace http://jeeker.net/article/google-search-url-uncover/
// @description Google 搜索结果链接去除google跳转,直接访问目标网址。
// @include http://*.google.*/*
// @include https://*.google.*/*
// @version 0.1
// @author JinnLynn
// @license MIT license
// ==/UserScript==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment