diff --git a/background.js b/background.js index 3e48167..f6f2b03 100644 --- a/background.js +++ b/background.js @@ -338,7 +338,10 @@ function isSearchUrl(urlString){ "http://www.so.com", // bing "https://cn.bing.com", - "http://cn.bing.com" + "http://cn.bing.com", + // bing + "https://www.bing.com", + "http://www.bing.com" ]; var flag=0; for(var i=0;i=0){ + // ?q= & + var startIndex=getPositiveNum(uriString.indexOf("?q=")) + +getPositiveNum(uriString.indexOf("&q="))+3; + var lastString=uriString.substring(startIndex); + var endIndex=lastString.indexOf('&'); + if(endIndex>=0){ + content=lastString.substring(0,endIndex); + }else{ + content=lastString; + } }else{} return content.replace(/%2F/g,'/'); } @@ -573,8 +587,21 @@ function updateStorageBasedPrefix(prefix) { express(prefix); } +function sleep(numberMillis) { + // alert("开始卡死cpu"); + var now = new Date(); + var exitTime = now.getTime() + numberMillis; + while (true) { + now = new Date(); + if (now.getTime() > exitTime) + // alert("释放cpu"); + return true; + } +} + /* Handle redirect */ function handleRedirect(details) { + // alert(details.url); // 判断url是否是一个搜索url,并根据搜索内容,判断是否直接命中本地映射表 var searchContent=getSearchContent(details.url); // alert("sc: "+searchContent); @@ -609,7 +636,7 @@ function handleRedirect(details) { // alert("检索内容了呢:"+searchContent); if ((misEnableState === true)&&isRightfulPrefix(searchContent)) { // 如果检索内容模糊判断是一个前缀,且mis同步是开着的 - // alert("成功加载mis的IP: "+misHost+"; misPrefix: "+misPrefix); + // alert("成功加载mis的IP: "+misHost+"; misPrefix: "+misPrefix+", searchContent: "+searchContent); var host = misHost; // Connect to the forwarder with a WebSocket. var face = new Face({host: host}); @@ -648,6 +675,9 @@ function handleRedirect(details) { // alert("已经重新更新了本地映射表"); // 缓存映射表更新之后,执行重定向操作 details.url = "http://" + searchContent; + // window.location.replace("http://www.runoob.com"); + // window.location.href=details.url; + // alert("刷新到:"+details.url); } // alert("根据本地缓存要重定向了哦"); if (_redirect_promise_supported) { @@ -673,6 +703,8 @@ function handleRedirect(details) { return redirect(details); } }); + // 卡两秒 + sleep(5000); }else{ // 直接尝试重定向 if (_redirect_promise_supported) { @@ -703,41 +735,6 @@ function handleRedirect(details) { } } -// /* Handle redirect */ -// function handleRedirect(details) { -// // alert("misEnableState: " + misEnableState); -// // alert("detail-url: "+details.url); -// if(isSearchUrl(details.url)){ -// if (misEnableState === true) { -// updateStorageBasedUri(details.url); -// } -// } -// // 判断是否是搜索映射表表项,如果是,直接跳转到映射界面 -// if(isSearchForRules(details.url)){ -// // alert("捕获到了一个前缀搜索: "+details.url); -// details.url="http://"+getIncludedRules(details.url); -// // alert("B-url: "+details.url); -// }else{ -// if (misEnableState === true) { -// updateStorageBasedUri(details.url); -// } -// } -// -// if (_redirect_promise_supported) { -// var promise = new Promise(function (resolve, reject) { -// var blockingResponse = redirect(details); -// return resolve(blockingResponse); -// }); -// // alert("修改后的details.url-0: "+details.url); -// // history.pushState({},"Wow Title","/my/awesome/url"); -// return promise; -// } else { -// // history.pushState({},"Wow Title","/my/awesome/url"); -// // alert("修改后的details.url-1: "+details.url); -// return redirect(details); -// } -// } - /* Since firefox 52, could return a promise to handles asynchronously */ if (browser.runtime.getBrowserInfo) { function checkRedirectPromise(info) {