写了个油猴脚本

由于baidu.com的url经常变化,baidu.com前面经常会添加一些奇怪的前缀:如vww,web。。。因而每次都需要我输入账号密码重新登录 或者 把baidu.com及其后面的网址复制并重新打开一个网址,十分麻烦。(baidu.com为任意假想网址,请勿对号入座。。。)

因而一个重来没学过javascript的人--我写了一个油猴脚本。

实现很简单,代码中那个7的意思是“http://”的长度(分割字符串需要,其实也没人关心吧)。

// ==UserScript== 
// @name           baidu.com 
// @description    Change URL to real baidu.com 
// @version        1.0 
// @include        http://*.baidu.com/* 
// @include        http://*.*.baidu.com/* 
// @include        http://*.*.*.baidu.com/* 
// @run-at         document-start 
// ==/UserScript==            
 (function(){   
     host_length = location.host.length;   
     href_length = location.href.length;  
     var old_url = location.href;   
     var left_url = old_url.substring(host_length + 7, href_length);   
     location.href = "http://baidu.com" + left_url; 
})(); 

 

 

posted on 2013-05-11 22:28  大宴天下  阅读(369)  评论(0编辑  收藏  举报