// ==UserScript== // @name BingSearchHelper // @namespace leawind // @version 1.8 // @description Automatically add options when searching by bing // @author leawind // @license MIT // @include *://* // @grant unsafeWindow // @run-at document-start // @downloadURL https://update.greasyfork.icu/scripts/448803/BingSearchHelper.user.js // @updateURL https://update.greasyfork.icu/scripts/448803/BingSearchHelper.meta.js // ==/UserScript== (function () { "use strict"; if (!/^cn.bing.com$/.exec(location.host)) return; // Only work in cn.bing.com console.log("BingSearchHelper loaded successfully"); // CONSTANTS const ID = "kBk78DkeNReVLVXs"; // for identification purposes const ID_URL = `${ID}-url`; // const ID_Q_SPLITER = ` -${ID}`; // To separate keywords and advanced search suffixes. const RGX = { bing_search: /^https?:\/\/((www)|(cn))\.bing\.com\/search\?.*/, // Determine if this is a search page question_suffix: new RegExp(`\\s*${ID_Q_SPLITER}.*$`), // find all advanced searching suffixes that added by me }; let options; let locator = new URL(location.href), params = locator.searchParams; let intervalFuncId = NaN; // 从 LocalStorage 中读取配置信息 try { options = JSON.parse(localStorage[ID]); } catch (err) { options = { sites_exclude: [], advs_params: [], consts: { // The following domains are only for testing purposes, absolutely nothing else. sites: { unexpected: [ "zhidao.baidu.com", "jingyan.baidu.com", "baijiahao.baidu.com", "pconline.com.cn", ".120ask.com", ".suning.com", ".toutiao.com", "163.com", "game.163.com", "play.163.com", "mc.163.com", ".dadagame.net", "99box.com", "mn.qq.com", "new.qq.com", ], EBP: [ ".jd.com", ".1688.com", "tb.alicdn.com", ".taobao.com", "kaola.com", ], softDownload: [ "downxia.com", "onlinedown.net", "xitongzhijia.net", "downza.cn", ".zol.com.cn", "pcsoft.com.cn", ".crsky.com", ".yehes.com", ".pw88.com", ".pc6.com", "soft.so.com", "121xia.com", "pc.qq.com", ".pcsoft.com.cn", "winwin7.com", "mydown.yesky.com", ".ddooo.com", "duote.com", ".pcsoft.com.cn", ".eyunsou.com", "baoku.360.cn", "soft.360.cn", ".xiaozhuzy.top", ], gameDownload: [ "down.gamersky.com", "down.ali213.net", "mydown.yesky.com", ".3dmgame.com", ".yxdown.com", "pc.52pk.com", ".wegame.com.cn", "www.gmz88.com", ".962.net", "www.mydown.com", ], }, }, }; { // Please forgive me if I forget to delete this block when publish this script. for (let i of options.consts.sites.unexpected) options.sites_exclude.push(i); for (let i of options.consts.sites.EBP) options.sites_exclude.push(i); for (let i of options.consts.sites.softDownload) options.sites_exclude.push(i); } } // 搜索页面 if (RGX.bing_search.exec(location.href)) { if (isUrlGoodSearch(location.href)) { intervalFuncId = window.setInterval(checkInputValue, 10); } else { params.set(ID_URL, ""); let q = params.get("q"); q += generateAdvancedSearchSuffix(options); params.set("q", q); console.log(locator); console.error("Relocating..."); location.href = locator.href; } } // 设置页面 // https://cn.bing.com/account/ if (/^https?:\/\/cn.bing.com\/account.*/.exec(location.href)) { window.addEventListener("load", () => { // Inject HTML let me_sidenav = document.getElementById("me_sidenav"); let profileSet = document.getElementById("profileSet"); let ele_ta_se; let ele_ta_ap; const saveOptions = () => { options.sites_exclude = ele_ta_se.value ? ele_ta_se.value.trim().split("\n") : []; options.advs_params = ele_ta_ap.value ? ele_ta_ap.value.trim().split("\n") : []; localStorage[ID] = JSON.stringify(options); }; { // 左侧目录 let ele_a = document.createElement("a"); ele_a.innerHTML = "LEAWIND's Bing Search Helper"; ele_a.href = "#bing-search-helper-by-leawind"; me_sidenav.appendChild(ele_a); } { // Section let ele_section = document.createElement("div"); let pfsChildren = profileSet.children; profileSet.insertBefore( ele_section, pfsChildren[pfsChildren.length - 2] ); ele_section.id = "bing-search-helper-by-leawind"; ele_section.setAttribute("class", "me_section me_cbst"); ele_section.innerHTML = `