// ==UserScript== // @name AC-baidu: 优化百度、搜狗、谷歌搜索结果之重定向 lite // @icon https://coding.net/u/zb227/p/zbImg/git/raw/master/img0/icon.jpg // @grant GM_xmlhttpRequest // @author AC // @create 2015-11-25 // @run-at document-start // @version 9.5 // @connect * // @include http://www.baidu.com/* // @include https://www.baidu.com/* // @include http://www.sogou.com/* // @include https://www.sogou.com/* // @include /^https?\:\/\/encrypted.google.[^\/]+/ // @include /^https?\:\/\/www.google.[^\/]+/ // @include https://*.zhidao.baidu.com/* // @include https://zhidao.baidu.com/* // @home-url https://greasyfork.org/zh-TW/scripts/14178 // @namespace 1353464539@qq.com // @copyright 2017, AC // @description 繞過百度、搜狗搜索結果中的自己的跳轉鏈接,直接訪問原始網頁-反正都能看懂 // @lastmodified 2017-06-11 // @feedback-url https://greasyfork.org/zh-TW/scripts/14178 // @note 2017.06.11-V9.5 不再使用DOM方式来监听页面了,使用timer+MO来处理,极大减少了cpu占用时间和瞬时网速占用 // @downloadURL none // ==/UserScript== // 初次:还是采用了setInterval来处理,感觉这样的话速度应该比Dom快,也比MO适用,因为MO需要在最后才能调用,实用性还不如timer // 之后:还是采用MO的方式来处理 (function(){ var fatherName = new Array( "c-container", //baidu1 "rc", //google "b_algo", //bing1 "b_ans", //bing2 "vrwrap", //sogou1 "rb"//sogou2 ); var Stype; // 去重定向的选择 var Ftype; // favicon的选择 if (location.host == "www.baidu.com") { Stype = "h3.t>a"; Ftype = ".f13 .c-showurl[href],.c-container>div[class^='c-'] .c-showurl[href],.c-container>div[class^='c-'] .texttolink[href]"; } else if (location.host == "sogou.com") { Stype = "h3.pt>a, h3.vrTitle>a"; Ftype = "cite[id*='cacheresult_info_']"; } else if (location.host.indexOf("google") > -1){ Stype = "h3>a"; Ftype = "._Rm"; } else { addStyle(".word-replace{display: none !important;}"); return; } var ACMO = window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver; var option = {'childList':true,'subtree':true}; var observer = new ACMO(function(records){ ACHandle(); //console.log(records); }); var tt = setInterval(function(){ if(document.querySelector("#content_left")){ clearInterval(tt); /***最后必须要设置好MO继续监听页面数据--自动加载下一页的问题***/ observer.observe(document.querySelector("#wrapper_wrapper"), option); // 处理当前-可以开始设置那个xxx了 ACHandle(); } }, 200); function ACHandle(){ resetURL(document.querySelectorAll(Stype)); // 百度去重定向 removeOnMouseDownFunc(); // 移除onMouseDown事件,谷歌去重定向 }; function removeOnMouseDownFunc(){ try{ document.querySelectorAll(".g .rc .r a").forEach(function(one){ one.setAttribute("onmousedown", ""); }); }catch(e){} } function addStyle(css) { //添加CSS的代码--copy的 var pi = document.createProcessingInstruction( 'xml-stylesheet', 'type="text/css" href="data:text/css;utf-8,' + encodeURIComponent(css) + '"' ); return document.insertBefore(pi, document.documentElement); } function resetURL(list){ for(var i = 0; i < list.length; i++){ // 此方法是异步,故在结束的时候使用i会出问题-严重! // 采用闭包的方法来进行数据的传递 var curhref = list[i].href; if(list[i].getAttribute("ac_redirectStatus") == null){ list[i].setAttribute("ac_redirectStatus", "0"); if(curhref.indexOf("baidu.com") > -1 || curhref.indexOf("sogou.com") > -1){ (function(c_curhref){ setTimeout(function(){ GM_xmlhttpRequest({ url: c_curhref, headers: { "Accept": "text/html" }, method: "GET", onreadystatechange:function(response) { if(response.status==200){ DealResult(response, c_curhref); } } }); },100); })(curhref); //传递旧的网址过去,读作c_curhref }else if(curhref.indexOf("/interstitial") > -1){ }else{ } } } } function DealResult(response, c_curhref){ // 数据获取成功,替换页面地址为真实地址 var resultURL = response.finalUrl; if(Stype.length > 10){ //如果是搜狗的结果 var resultResponseUrl = Reg_Get(response.responseText, "URL='([^']+)'"); if(resultResponseUrl != null) resultURL = resultResponseUrl; } var indexhref = Reg_Get(c_curhref, "((?:http)[^&]+)");// 必须要提取部分数据,因为之后的莫名加了其他参数ck=0.0.0.0..... var ccnode = document.querySelectorAll("h3>[href*='"+indexhref+"']")[0]; if(ccnode != null){ ccnode.href = resultURL; }else{ console.log("该链接已经被其他脚本干掉了哦"+resultURL); } } function Reg_Get(HTML, reg){ var RegE = new RegExp(reg); return RegE.exec(HTML)[1]; } })();