Google Hit Hider by Domain 汉化版

从Google、DuckDuckGo、Startpage.com、Bing和Yahoo搜索结果中屏蔽不需要的站点。 v2.3.1 2024-05-11

  1. // ==UserScript==
  2. // @name Google Hit Hider by Domain 汉化版
  3. // @author Jefferson "jscher2000" Scher ,7980963
  4. // @namespace JeffersonScher
  5. // @version 2.3.1.3
  6. // @copyright Copyright 2023 Jefferson Scher
  7. // @license BSD-3-Clause
  8. // @description 从Google、DuckDuckGo、Startpage.com、Bing和Yahoo搜索结果中屏蔽不需要的站点。 v2.3.1 2024-05-11
  9. // @include http*://www.google.*/*
  10. // @exclude http*://www.google.com/recaptcha/*
  11. // @include http*://www.google.co*.*/*
  12. // @include http*://news.google.*/*
  13. // @include http*://encrypted.google.*/*
  14. // @include http*://startpage.com/*
  15. // @include http*://*.startpage.com/*
  16. // @exclude https://www.startpage.com/*/ads?*
  17. // @exclude https://www.startpage.com/*/*/ads*
  18. // @exclude https://us-browse.startpage.com/av/proxy?*
  19. // @include http*://duckduckgo.com/*
  20. // @include http*://start.duckduckgo.com/*
  21. // @include http*://safe.duckduckgo.com/*
  22. // @include http*://3g2upl4pq6kufc4m.onion/*
  23. // @include http*://www.bing.com/*
  24. // @include http*://*search.yahoo.com/*
  25. // @include http*://search.yahoo.co.jp/*
  26. // @include http*://www.yandex.com/*
  27. // @include http*://yandex.com/*
  28. // @include http*://searx.*/*
  29. // @include http*://www.qwant.com/*
  30. // @include http*://www.qwantjunior.com/*
  31. // @include http*://www.baidu.com/*
  32. // @include https://www.ecosia.org/search*
  33. // @grant GM_getValue
  34. // @grant GM.getValue
  35. // @grant GM_setValue
  36. // @grant GM.setValue
  37. // @grant GM_registerMenuCommand
  38. // @grant GM_deleteValue
  39. // @grant GM.deleteValue
  40. // @grant GM_getResourceURL
  41. // @grant GM.getResourceUrl
  42. // @resource mycon https://www.jeffersonscher.com/gm/src/gfrk-GHHbD-ver231.png
  43. // ==/UserScript==
  44. var script_about = "https://gf.qytechs.cn/zh-CN/scripts/457749-google-hit-hider-by-domain-%E6%B1%89%E5%8C%96%E7%89%88";
  45. /*
  46. Copyright (c) 2024 Jefferson Scher.
  47. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met and subject to the following restriction:
  48. 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  49. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  50. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  51. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. */
  53. var GM4 = (typeof GM.getValue === "undefined") ? false : true;
  54. function GHHbD_addStyle(txt){
  55. var s=document.createElement('style');
  56. s.className = 'GHHbDcss';
  57. s.appendChild(document.createTextNode(txt));
  58. document.body.appendChild(s);
  59. }
  60. var isch = false, nws = false;
  61. function injectBaseCSS(){
  62. // == == == To override the style of the script's buttons and panes, use the custom style feature == == ==
  63. GHHbD_addStyle("div.ghhider{color:#888;} div.ghhider:hover{background-color:#eee;} " +
  64. "button.ghhider{color:#555;background-color:#fcfcfc;font-family:sans-serif;font-size:0.85em;line-height:1.2em;margin:auto 2px;border:1px solid #ccc;border-radius:4px;padding:2px 3px;} h3>button.ghhider{font-size:0.75em;} " +
  65. "button.ghhider:hover{color:#000;background:#ff8;} .ghh1time{background:#eee !important;} .ghhdnone{display:none !important;} " +
  66. ".ghhpane{position:absolute;color:#333;background-color:#fcfcfc;border:1px solid #ccc;border-radius:4px;padding:0.25em 1.5em;font-size:13px;display:none} " +
  67. "#ghhsitelist, #ghhpbanlist{background:#fff;list-style-type:none;padding:0;margin:0;} " +
  68. "#ghhsitelist li,#ghhpbanlist li{width:100%;line-height:1.5em;padding:0;position:relative} " +
  69. "#ghhsitelist li:nth-of-type(odd),#ghhpbanlist li:nth-of-type(odd){background-color:#fcfcaa} " +
  70. ".ghhhost{display:block;padding:0 0.25em;cursor:pointer;} #ghhutil{text-align:center;margin:0.5em 0 1em 0;border:1px solid #ccc;border-radius:4px;padding:3px 0;} " +
  71. ".ghhinfo{font-size:12px;line-height:9px;position:absolute;top:0;right:0;z-index:1001;border:4px solid transparent;border-radius:4px;border-bottom-left-radius:8px;border-top-left-radius:8px;margin-top:1px;padding-left:1px} " +
  72. ".ghhdel{text-decoration:line-through;color:#333;} .ghhpb{text-decoration:none;color:#f00;} " +
  73. ".ghhblk{text-decoration:none;color:#333;} .ghhd{position:relative;line-height:1.2em;cursor:pointer;} " +
  74. ".ghhindent{position:absolute;left:350px;top:-3px;} #btnedit p{margin:2px 4px 4px 4px;} #ghhblockform input[type='radio'], #ghhmngform input[type='radio']{vertical-align:baseline !important;margin-top:5px;margin-bottom:1px} " +
  75. "#ghhblockform label, #ghhmngform label{display:inline;font-weight:normal;font-size:unset;} .ghhtbl{border:1px solid black;border-collapse:collapse} .ghhtbl td, .ghhtbl th{border:1px solid black;padding:2px 4px;} " +
  76. "#ghhtsdiv{margin:0 -1.5em;padding:0 3px 0 8px;border-bottom:1px solid #ccc;} #ghhtstrip{padding-bottom:0;} " +
  77. "#ghhtstrip button{color:#555;background-color:#f5f5f5;margin:0 2px 0 0;border:1px solid #ccc;padding:1px 2px;height:22px;border-radius:2px;} " +
  78. "#ghhtstrip .ghhCurTab{background-color:#fcfcfc;border-bottom-color:#fcfcfc;} .ghhtab {margin-top:1em;height:17em;overflow-y:scroll;border:1px solid #333;} " +
  79. "#mflists>div>p{margin:1em 0;} #ghhmngform{position:fixed;top:65px;right:0;z-index:9001;text-align:left;line-height:1.2em} #ghhblockform{text-align:left;z-index:3005} " +
  80. 'h3[wotdonut="true"]{overflow:visible!important} div.divGHHbD{text-align:right;align-self:flex-end;padding:4px;} ' +
  81. 'button.imgGHHbD{position:relative;z-index:1000;color:#609beb;background-color:#333;border:1px solid #609beb;} button.imgGHHbD:hover{background-color:#000;color:#0ee;}');
  82. GHHbD_addStyle("@media print {button.ghhider,button.imgGHHbD{display:none;}}");
  83. // Standard image results style block
  84. if (location.search.indexOf("tbm=isch") > -1){
  85. var ghhbd_imgsty = document.createElement("style");
  86. ghhbd_imgsty.id = "ghhStyleImgResults";
  87. ghhbd_imgsty.setAttribute("type", "text/css");
  88. ghhbd_imgsty.appendChild(document.createTextNode('div[imgblock="regular"] img{opacity:0.1 !important} div.isv-r[imgblock="regular"] a div:first-of-type{opacity:0.6 !important} div[imgblock="regular"]:not(.isv-r) a div{display:block !important;opacity:0.6 !important}div[imgblock="regular"] img:hover{opacity:0.5 !important} div[imgblock="pban"]{background-color:#aaa !important;border-radius:6px !important} div[imgblock="pban"] a{display:none !important}'));
  89. document.body.appendChild(ghhbd_imgsty);
  90. isch=true;
  91. }
  92. if (location.search.indexOf("tbm=nws") > -1){ //v2.2.6 for News results under www
  93. var ghhbd_nwssty = document.createElement("style");
  94. ghhbd_nwssty.id = "ghhStyleNwsResults";
  95. ghhbd_nwssty.setAttribute("type", "text/css");
  96. ghhbd_nwssty.appendChild(document.createTextNode('.ghhb{position:relative; top: -22px; float:right;} g-scrolling-carousel .ghhb{position:static !important; float:none;}'));
  97. document.body.appendChild(ghhbd_nwssty);
  98. nws=true;
  99. }
  100. }
  101. injectBaseCSS();
  102. var currentG = location.hostname; var engine = 'misc';
  103. function doSiteSpecific(){
  104. if (currentG.indexOf("google") > -1){
  105. engine = 'Google';
  106. // Google: div#res > div#search > div > div#ires > div.srg | ol#rso | div._NId | div.bkWMgd > div.g > div.rc > h3.r > a
  107. // Google in-depth articles: div#res > div#search > div#ires > ol#rso > div > li.g.card-section or li.g.ct-cs > div.rc > div > h3.r > a
  108. // Google Images (default): div#res > div#search > div > div#ires > div#rso > div#isr_mc > div > div#rg > div#rg_s > div.rg_di.rg_el.ivg-ig > a > img
  109. }
  110. if (currentG.indexOf("bing.com") > -1){
  111. engine = 'Bing';
  112. // Bing: div#b_content > main > ol#b-results > li.b_algo > h2 > a
  113. // [as of v2.2.7 5/28/2023] true URL found in li.b_algo > div:not(.b_algo_group) cite
  114. GHHbD_addStyle("li[ghhresult] h2 button.ghhider{font-size:0.7em !important;} li > h2 {white-space:nowrap !important;}");
  115. }
  116. if (currentG.indexOf("duckduckgo") > -1 || currentG.indexOf("3g2upl4pq6kufc4m") > -1){
  117. engine = 'DDG';
  118. // DuckDuckGo: div#links > div.results_links_deep > div.links_main > h2 > a
  119. GHHbD_addStyle(".links_main, .result__title{overflow:visible !important;} .result__title{white-space:nowrap !important;} " +
  120. ".ghhb{font-size:12px!important;margin-left:4px!important;position:absolute;margin-top:4px!important} " +
  121. ".results_links_deep[blocknotice] + .results__sitelink--organics, .ghhdnone + .results__sitelink--organics, .results_links_deep[blocknotice] + .result__sitelinks--organics, .ghhdnone + .result__sitelinks--organics {display:none;}");
  122. // v2.2.3 2022-05-02: div#links > div.nrn-react-div > article > div > h2 > a
  123. // not sure what CSS changes might be needed yet
  124. // v2.2.5 2023-05-13: ol.react-results--main > li[data-layout="organic"] > article[data-testid="result"][data-nrn="result"] > div > h2 > a
  125. GHHbD_addStyle('li[blocknotice] .ghhider.ghhd{padding-left:10px !important;} li[ghhresult="unset"] h2 > a{display:inline-block !important;}');
  126. }
  127. if (currentG.indexOf("startpage") > -1){
  128. engine = 'Startpage';
  129. // Startpage: div#results > ol > li > div.result > h3 > a
  130. // 11/21/2018: [data-view="results"] div.columns article.column.column--main > div.column.column--main__content > ol.list-flat > li.search-result.search-item > h3.search-item__title > a
  131. // 7/03/2019: div.mainline-results__web section.w-gl > div.w-gl__result > a.w-gl__result-title
  132. // 5/08/2024: div#main > div.w-gl > div.result > a.result-title.result-link, div#main > div.w-bg > div.result > div.result__main > a.result-title.result-link
  133. GHHbD_addStyle('.w-gl__result{overflow:visible !important;} @media(min-width: 651px){div.w-gl .result, div.w-bg .result{position:relative!important;}' +
  134. '.result button.ghhb{position:absolute;right:-30px;margin-top:-28px;} .result .result__main button.ghhb{margin-top:26px;}}' +
  135. 'div.w-gl__result .ghhd{padding:0 10px 8px 12px}button.ghhider{font-weight:normal;}' +
  136. '#ghhblockform input[type="checkbox"], #ghhmngform input[type="checkbox"]{width:unset;height:unset;position:static;margin:unset;border:unset;padding:unset;clip:unset;}' +
  137. '#ghhblockform button, #ghhmngform button{font-size:1em;font-weight:normal;border:1px solid #e3e3e3;border-radius:3px;padding:2px 8px;box-shadow:none} #ghhmngform{top:105px !important;}');
  138. }
  139. if (currentG.indexOf("yahoo.com") > -1){
  140. engine = 'Yahoo';
  141. // Yahoo (Firefox): div#results > div#cols > div#left > div > div#main > div > div#web > ol > li > div > div > h3 > a
  142. // GHHbD_addStyle("div#web > ol.reg, li div.compTitle {overflow:visible !important;} .ghhd{margin: 1em 0px -1em 10px} #ghhmngform{top:80px} li div div h3{white-space:nowrap !important;}");
  143. GHHbD_addStyle("div#web > ol.reg, li div.compTitle {overflow:visible !important; border-top:0.1px solid transparent;} .ghhd{margin: 1em 0px 0px 0px} #ghhmngform{top:80px} li div div h3{white-space:normal !important;}"); // v2.2.1
  144. }
  145. if (currentG.indexOf("yahoo.co.jp") > -1){
  146. // Yahoo Japan (OLD): div#contents > div > div > div > div#WS2m > div.w > div.hd > h3 > a
  147. // Yahoo Japan: div#contents > div#contents__wrap > div.Contents__inner Contents__inner--main > div.Contents__innerGroupBody > div.sw-CardBase div.sw-Card__title > a > h3 //v2.2.1
  148. GHHbD_addStyle("#WS2m .w{overflow:visible !important;} #ghhmngform{z-index:3001}");
  149. }
  150. if (currentG.indexOf("baidu") > -1){
  151. engine = 'Baidu';
  152. // Baidu: (title) #content_left > div.result.c-container > h3 > a; (domain) #content_left > div.result.c-container > div > a.c-showurl
  153. // Baidu rich result: (title) #content_left > div.result-op.c-container > h3 > a (or p.op_site_domain_title, div.op_generalqa_main.c-row); (domain) #content_left > div.result-op.c-container[mu]
  154. }
  155. if (currentG.indexOf("yandex.com") > -1){
  156. // Yandex: div.serp-list | ul.serp-list > div.serp-item | li.serp-item > h2 > a
  157. GHHbD_addStyle("h2.serp-item__title{white-space:nowrap;}.ghhb{font-size:0.75em!important;margin-left:4px!important;}");
  158. }
  159. if (currentG.indexOf("qwant") > -1){
  160. // Qwant: div.results-column > div.result_fragment > div.result--web | div.result--news > h3 > a
  161. GHHbD_addStyle("div[blocknotice]:not(.ghh1time){min-height:1em;padding-left:0;}");
  162. }
  163. if (currentG.indexOf("searx") > -1){
  164. // Searx.me: div#main_results > div.result > h4.result_header > a
  165. GHHbD_addStyle("h2.serp-item__title{white-space:nowrap;}.ghhb{font-size:0.75em!important;margin-left:4px!important;}");
  166. }
  167. if (currentG.indexOf("ecosia") > -1){
  168. engine = 'Ecosia';
  169. // Ecosia: div.results-wrapper > div.container.results ... div.card-web ... div.result-firstline-title > a.result-title
  170. GHHbD_addStyle("[ghhresult] h2.result-firstline-title>a.result-title{display:inline;}.ghhider{font-size:0.6em!important;}");
  171. }
  172. }
  173. doSiteSpecific();
  174. function injectCustom(){
  175. if (document.getElementById("ghhbdcuststy")) return;
  176. var ghhbd_custsty = document.createElement("style");
  177. ghhbd_custsty.setAttribute("type", "text/css");
  178. ghhbd_custsty.id = "ghhbdcuststy";
  179. ghhbd_custsty.appendChild(document.createTextNode(custSty));
  180. document.body.appendChild(ghhbd_custsty);
  181. }
  182. var custSty;
  183. if (!GM4){
  184. custSty = GM_getValue("hiderStyles", "");
  185. if (custSty.length > 0) injectCustom();
  186. } else {
  187. GM.getValue("hiderStyles", "").then(function(value){custSty = value; if (custSty.length > 0) injectCustom();});
  188. }
  189. // == == == Globals for preferences == == ==
  190. var blist, defaultTxts, txtsPref, txts, defaultPrefs, ghhPrefs, ghhPrefO, showYN, mpopen, mbstyle, bbstyle, bbpos, addAt, listchgs, bLUopen, bAggress, bAJAX, bMutOb, pref1click, betatest, MutOb, chgMon, opts, kids, needupdate = true, doms = [], t_pb;
  191. var patIPv4 = /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/;
  192. function checkblist(){
  193. if (blist.length === 0) blist = "|example.com:t|";
  194. if (blist.substr(0,1) != "|") blist = "|" + blist;
  195. if (blist.indexOf(":") < 0) convertFormat();
  196. }
  197. if (!GM4){
  198. blist = GM_getValue("hideyhosts", "");
  199. checkblist();
  200. } else {
  201. GM.getValue("hideyhosts", "").then(function(value){blist = value; checkblist();});
  202. }
  203. defaultTxts = {
  204. "block": ["屏蔽", "在结果标题旁边的按钮,可呼出屏蔽对话框"],
  205. "unblock": ["解除屏蔽", "在结果中的绿色按钮,可将网站从屏蔽列表中移除"],
  206. "onetime": ["临时显示", "在结果中的黄色按钮,可暂时显示一个结果"],
  207. "pban": ["永久屏蔽", "将网站移到永久屏蔽列表中的红色按钮"],
  208. "shownotc": ["显示通知", "设置是否显示通知的按钮"],
  209. "hidenotc": ["隐藏通知", "设置是否隐藏通知的按钮"],
  210. "okbtn": ["常规屏蔽", "在屏蔽对话框中屏蔽所选域名的按钮"],
  211. "cancelbtn": ["取消", "在屏蔽对话框中取消更改的按钮"],
  212. "savebtn": ["保存列表", "在管理面板中更新屏蔽和永久屏蔽列表的按钮"],
  213. "closebtn": ["关闭", "在管理面板中关闭面板的按钮"],
  214. "okPbtn": ["永久屏蔽", "在屏蔽对话框中永久屏蔽所选域名的按钮"],
  215. "cancelMbtn": ["管理隐藏", "在屏蔽对话框中打开管理面板的按钮"],
  216. "mngbtn": ["Manage Hiding", "Button on the right side to open the management pane"],
  217. "eximbtn": ["导出", "在管理面板中导出屏蔽列表的按钮"],
  218. "utilbtn": ["列表工具", "在管理面板中打开实用程序面板的按钮"],
  219. "sortbtn": ["排序", "在管理面板中对屏蔽列表进行排序的按钮"],
  220. "unwwwbtn": ["去除www", "在管理面板中从被屏蔽的域名中去除www的按钮"],
  221. "dedupbtn": ["去重", "在管理面板中对屏蔽列表进行去重的按钮"],
  222. "impobtn": ["导入", "在管理面板中将域名导入屏蔽列表的按钮"],
  223. "sharebtn": ["分享", "在管理面板中将屏蔽列表发布到网络的按钮"],
  224. "addallbtn": ["全部添加", "在管理面板中批量添加所有未屏蔽的域名到当前列表的按钮"]
  225. };
  226. function checktxts(){
  227. if (txtsPref.indexOf(":[") == -1 || txtsPref.indexOf("mngbtn") == -1 ||
  228. txtsPref.indexOf("eximbtn") == -1 || txtsPref.indexOf("utilbtn") == -1 ||
  229. txtsPref.indexOf("impobtn") == -1 || txtsPref.indexOf("addallbtn") == -1) {
  230. convertTxts(txtsPref);
  231. } else {
  232. txts = JSON.parse(txtsPref);
  233. }
  234. }
  235. if (!GM4){
  236. txtsPref = GM_getValue("textstrings", JSON.stringify(defaultTxts));
  237. checktxts();
  238. } else {
  239. GM.getValue("textstrings", JSON.stringify(defaultTxts)).then(function(value){txtsPref = value; checktxts();});
  240. }
  241. defaultPrefs = {
  242. "shownotc":["Y","Show hit notices(Y|N)"],
  243. "mngpaneopen":["Y-N","Persistence enabled(Y|N),Pane was open(Y|N),Last tab number(1-4)"],
  244. "mngbtnstyle":["both-ifrN-R-P-Y-H","Display Manage Hiding button and Block buttons(mng|blk|both),In iframes(ifrN|ifrY),Position(R,T,B),Block button display(P,M),Block button tooltips(Y|N), Block button position(H|C)"],
  245. "addtolistpos":["end","Where to add new hits to block lists(end|top|sort)"],
  246. "aggressiveblock":["none","Which domains to default to shorter form(none|all|www)"],
  247. "usemutation":["on-Y","Listen for mutation events(on|off),Use DOM4 Mutation Observer(Y|N)"],
  248. "oneclick":["N-N","One-click blocking(Y|N),Goes to Perma-ban(Y|N)"],
  249. "runbeta":["N","Enable incompletely tested features (Y|N)"],
  250. "reserved2":["X","Y"]
  251. };
  252. function checkprefs(){
  253. if (ghhPrefs.length == 0){
  254. convertPrefs(defaultPrefs, "true");
  255. } else {
  256. if (ghhPrefs.indexOf("reserved1")>-1){
  257. convertPrefs(defaultPrefs, "false");
  258. } else {
  259. ghhPrefO = JSON.parse(ghhPrefs);
  260. }
  261. }
  262. }
  263. if (!GM4){
  264. ghhPrefs = GM_getValue("ghhprefs", "");
  265. checkprefs();
  266. if (engine == 'Startpage') window.setTimeout(GHHbDinit, 300);
  267. else GHHbDinit();
  268. } else {
  269. GM.getValue("ghhprefs", "").then(function(value){
  270. ghhPrefs = value;
  271. checkprefs();
  272. if (engine == 'Startpage') window.setTimeout(GHHbDinit, 300);
  273. else GHHbDinit();
  274. });
  275. }
  276. function GHHbDinit(){
  277. showYN = ghhPrefO.shownotc[0];
  278. mpopen = ghhPrefO.mngpaneopen[0];
  279. mbstyle = ghhPrefO.mngbtnstyle[0];
  280. if (mbstyle.split("-")[0] == "mng") toggleBlockHiders("H");
  281. if (mbstyle.split("-").length < 3){
  282. GHHbD_addStyle("#ghhMngBtn {position:fixed;top:150px;right:-2.8em;-moz-transform:rotate(-90deg);-webkit-transform:rotate(-90deg);"+
  283. "border-bottom:0;border-bottom-left-radius:0;border-bottom-right-radius:0;padding:6px 1px;z-index:1000;}");
  284. } else {
  285. switch (mbstyle.split("-")[2]){
  286. case "B":
  287. GHHbD_addStyle("#ghhMngBtn {position:fixed;bottom:0;right:2px;"+
  288. "border-bottom:0;border-bottom-left-radius:0;border-bottom-right-radius:0;padding:6px 1px;z-index:1000;}");
  289. break;
  290. case "T":
  291. GHHbD_addStyle("#ghhMngBtn {margin:0;padding:4px 6px;z-index:3000;}");
  292. if (document.querySelector("#appbar ol")){
  293. window.setTimeout(function(){document.querySelector("#appbar ol#ab_ctls").appendChild(document.getElementById("ghhMngBtn"))}, 1000);
  294. window.setTimeout(function(){var liNew = document.createElement("li");liNew.className="ab_ctl";liNew.appendChild(document.getElementById("ghhMngBtn"));document.querySelector("ol#ab_ctls").appendChild(liNew);}, 1500);
  295. } else {
  296. window.setTimeout(function(){if (document.querySelector("#appbar ol")){var liNew = document.createElement("li");liNew.className="ab_ctl";liNew.appendChild(document.getElementById("ghhMngBtn"));document.querySelector("ol#ab_ctls").appendChild(liNew);}else{document.getElementById("ghhMngBtn").setAttribute("style","position:absolute;top:8em;right:0")}}, 1500);
  297. }
  298. break;
  299. default:
  300. GHHbD_addStyle("#ghhMngBtn {position:fixed;top:150px;right:-2.8em;-moz-transform:rotate(-90deg);-webkit-transform:rotate(-90deg);"+
  301. "border-bottom:0;border-bottom-left-radius:0;border-bottom-right-radius:0;padding:6px 1px;z-index:1000;}");
  302. }
  303. }
  304. if (mbstyle.split("-").length > 3) bbstyle = mbstyle.split("-")[3];
  305. else bbstyle = "P";
  306. if (mbstyle.split("-").length > 5) bbpos = mbstyle.split("-")[5];
  307. else bbpos = "H";
  308. // toggleciteline(bbpos); called by fixuistyle()
  309. addAt = ghhPrefO.addtolistpos[0];
  310. listchgs = 0;
  311. bLUopen = "N";
  312. bAggress = ghhPrefO.aggressiveblock[0];
  313. bAJAX = ghhPrefO.usemutation[0].split("-")[0];
  314. if (ghhPrefO.usemutation[0].split("-").length > 1) bMutOb = ghhPrefO.usemutation[0].split("-")[1];
  315. else bMutOb = "Y";
  316. pref1click = ghhPrefO.oneclick[0];
  317. betatest = ghhPrefO.runbeta[0];
  318. if (document.body){
  319. // Add buttons, hide unwanted domains
  320. hidehits(null,false);
  321. if (document.getElementById("GTR")) removePBs();
  322. // Special results layout
  323. if (betatest == "Y"){
  324. var itbl = document.querySelector("#res .images_table");
  325. if (itbl) hidebasic(itbl);
  326. }
  327. // Create skeleton of manage form
  328. if (!document.getElementById("ghhmngform")) addManageForm();
  329. // Add manage button
  330. if (!document.getElementById("ghhMngBtn") && mbstyle.split("-")[0] != "blk"){
  331. if (engine == 'Google'){if(document.getElementById("res") || isch) addMngBtn();}
  332. else addMngBtn();
  333. }
  334. // Show pane if last open
  335. if (mpopen.substr(0,3) == "Y-Y") showManageForm("mngform");
  336. // Add menu item - Legacy Only
  337. if (typeof GM_registerMenuCommand != "undefined") GM_registerMenuCommand("Manage Hiding", showManageForm);
  338. // Create block form
  339. if (!document.getElementById("ghhblockform")) addBlockForm();
  340. // Watch for changes that could be new instant or AJAX search results
  341. if (bAJAX == "on") setMutationWatch();
  342. }
  343. }
  344. function setMutationWatch(){
  345. // Prefer MutationObserver (Firefox 14+) over Mutation Events
  346. MutOb = (window.MutationObserver) ? window.MutationObserver : window.WebKitMutationObserver;
  347. if (MutOb && bMutOb == "Y"){
  348. chgMon = new MutOb(function(mutationSet){
  349. mutationSet.forEach(function(mutation){
  350. if (mutation.type == "childList"){
  351. for (var i=0; i<mutation.addedNodes.length; i++){
  352. if (mutation.addedNodes[i].nodeType == 1){
  353. checkNode(mutation.addedNodes[i]);
  354. }
  355. }
  356. } else if (engine == 'DDG' && mutation.target.className == 'results js-results') { // v2.2.3
  357. for (i=0; i<mutation.target.childNodes.length; i++){
  358. if (mutation.target.childNodes[i].className == 'nrn-react-div'){
  359. checkNode(mutation.target.childNodes[i]);
  360. }
  361. }
  362. } else { // attribute mutation on Google Images
  363. if(mutation.target.className == "rg_l") checkNode(mutation.target.parentNode);
  364. }
  365. });
  366. });
  367. // attach chgMon to document.body
  368. if (isch == true) opts = {childList: true, subtree: true, attributes: true, attributeFilter: ["href"], characterData: false};
  369. else if (engine == 'DDG') opts = {childList: true, subtree: true, attributes: true, characterData: false}; // v2.2.3
  370. else opts = {childList: true, subtree: true, attributes: false, characterData: false};
  371. chgMon.observe(document.body, opts);
  372. } else if (bMutOb == "Y") { // Legacy browser support and Baidu
  373. document.body.addEventListener("DOMSubtreeModified", checkOlist, false);
  374. }
  375. }
  376. // == == == Main Event Loops == == ==
  377. var ignoreNodeNames = "|BODY|#text|#comment|INPUT|BUTTON|SCRIPT|LI|A|FORM|";
  378. var ignoreIds = "|leftnav|leftnavc|foot|ghhtemp|ghhblockform|ghhmanageform|ghhsitelist|ghhpbanlist|rhs|rhscol|";
  379. var ignoreClass = "|ghhider|ghhdbuttons|ghh1time|";
  380. var t_ap, t_gimg;
  381. function checkOlist(e){ // Check for new results // Needed for Baidu
  382. var el = e.target;
  383. // Ignore events on some elements
  384. if (ignoreNodeNames.indexOf("|"+el.nodeName+"|") > -1) return;
  385. if (el.hasAttribute("id")){if (ignoreIds.indexOf("|"+el.id+"|") > -1) return;}
  386. if (el.hasAttribute("class")){
  387. if (ignoreClass.indexOf("|"+el.className+"|") > -1) return;
  388. if (el.classList.contains("goog-date")) return;
  389. }
  390. if (!document.getElementById("ghhmngform")){
  391. addManageForm();
  392. injectBaseCSS();
  393. injectCustom();
  394. if (!document.getElementById("ghhMngBtn") && mbstyle.split("-")[0] != "blk"){
  395. if (engine == 'Google'){if(document.getElementById("res")) addMngBtn();}
  396. else addMngBtn();
  397. }
  398. // Use default button style for now (1.9.3)
  399. GHHbD_addStyle("#ghhMngBtn {position:fixed;top:150px;right:-2.8em;-moz-transform:rotate(-90deg);-webkit-transform:rotate(-90deg);"+
  400. "border-bottom:0;border-bottom-left-radius:0;border-bottom-right-radius:0;padding:6px 1px;z-index:1000;}");
  401. }
  402. checkNode(el);
  403. }
  404. function checkNode(el){
  405. if (el.parentNode && (el.parentNode.id == 'ghhsitelist' || el.parentNode.id == 'ghhpbanlist')) return; // 2.0.6 duh!
  406. // AutoPager extension
  407. if (document.querySelector("#navcnt")){
  408. if (t_ap) window.clearTimeout(t_ap);
  409. t_ap = window.setTimeout(refreshListeners, 500);
  410. }
  411. if (el.nodeName == "LI" || (el.nodeName == "DIV" && (el.className == "g" || el.classList.contains("rg_di") || el.className == "rgsh")) ||
  412. el.nodeName == 'G-INNER-CARD' || el.nodeName == 'G-CARD' || el.classList.contains("isv-r")) var nlist = [el];
  413. else nlist = el.querySelectorAll('li.g, div.g, div.rg_di, div.isv-r');
  414. if (engine != 'Google' && el.nodeName != "LI"){
  415. if (el.nodeName == "DIV" && (el.classList.contains("result--web") || el.classList.contains("result--news") ||
  416. el.className == "card-mobile" || el.classList.contains('nrn-react-div'))) nlist = [el]; // Qwant, Ecosia, DDG-react
  417. else if (el.nodeName == "OL" && el.classList.contains('react-results--main')) nlist = el.querySelectorAll('li');
  418. else nlist = el.querySelectorAll('div.result, div.result-op, div.links_main, div.serp-item, div.hd, li.b_algo, ol.list-flat > li, div.card-web div.card-mobile');
  419. }
  420. if (nlist.length > 0){
  421. if (isch) hidehits(nlist,true);
  422. else hidehits(nlist,false);
  423. if (document.getElementById("GTR")) removePBs();
  424. } else if (el.nodeName == "DIV" && ( (el.classList.contains("irc_c") || el.classList.contains("irc_bg")) || el.id == 'irc_bg') ) {
  425. var buttondivs = el.querySelectorAll('.irc_butc:not([ghhresult]), .irc_but_r:not([ghhresult]), .irc_ab:not([ghhresult]), .irc_but_pdfr:not([ghhresult])');
  426. for (var k=0; k<buttondivs.length; k++){
  427. buttondivs[k].setAttribute("ghhresult", "image-unset");
  428. buttondivs[k].style.position = "relative";
  429. if (buttondivs[k].nodeName == 'TABLE'){
  430. var tdnew = document.createElement("td");
  431. tdnew.innerHTML = '<button type="button" title="Block/Unblock" class="irc_but"><span class="irc_but_t">GHHbD</span></button>';
  432. buttondivs[k].querySelector('tr').appendChild(tdnew);
  433. tdnew.firstChild.addEventListener("click", imgblockdialog, false);
  434. } else {
  435. var spannew = document.createElement("span");
  436. spannew.style.marginLeft = '10px';
  437. spannew.innerHTML = '<button type="button" title="Block/Unblock" class="irc_but"><span class="irc_but_t">GHHbD</span></button>';
  438. buttondivs[k].appendChild(spannew);
  439. spannew.firstChild.addEventListener("click", imgblockdialog, false);
  440. }
  441. }
  442. } else {
  443. var abtn = el.querySelectorAll('a[role="button"][href]'); // Google images sidebar 2020-06-20
  444. if (abtn.length > 0 && abtn[0].closest('c-wiz') != null) var alnk = abtn[0].closest('c-wiz').querySelector('a[role="link"][href]');
  445. if (alnk && !alnk.parentNode.hasAttribute('ghhresult')) {
  446. alnk.parentNode.setAttribute('ghhresult', 'image-unset');
  447. var dnew = document.createElement("div");
  448. dnew.classList.add('divGHHbD'); // v2.2.8 update horizontal position for flex layout, move styling to classes
  449. dnew.innerHTML = '<button type="button" title="Block/Unblock" url="' + alnk.href + '" class="imgGHHbD">GHHbD</button>';
  450. alnk.parentNode.insertBefore(dnew, alnk);
  451. dnew.firstChild.addEventListener("click", imgblockdialog, false);
  452. }
  453. }
  454. if (document.querySelectorAll('style.GHHbDcss').length === 0){ // Bing losing styles... 2018-10-01
  455. injectBaseCSS();
  456. doSiteSpecific();
  457. GHHbD_addStyle("#ghhMngBtn {position:fixed;top:150px;right:-2.8em;-moz-transform:rotate(-90deg);-webkit-transform:rotate(-90deg);"+
  458. "border-bottom:0;border-bottom-left-radius:0;border-bottom-right-radius:0;padding:6px 1px;z-index:1000;}");
  459. }
  460. }
  461. var parentcard;
  462. function hidehits(liels,ovrd){
  463. if (!liels){
  464. if (engine == 'Google'){
  465. liels = document.querySelectorAll("#res li.g, #res div.srg div.g, #res div._NId div.g, #res div._bkWMgd div.g, #res #rso div.g, #res #GTR div.g, #res #isr_mc, g-section-with-header g-scrolling-carousel g-inner-card, g-card div.dbsr, g-card, [data-async-context^=\"query:\"] div.g");
  466. } else {
  467. liels = document.querySelectorAll('div#results li, div#results > div.result, div#links > div.results_links_deep > div.links_main, div#links > div.nrn-react-div, div#b_content ol > li.b_algo, div#results div#web > ol > li, div#WS2m > div.w, div.sw-CardBase, div.serp-list > div.serp-item, ul.serp-list > li.serp-item, div#main_results > div.result, div.results-column div.result--web, div.results-column div.result--news, #content_left > div.result.c-container, #content_left > div.result-op.c-container, ol.list-flat > li, div.w-gl__result, div.w-gl > div.result, div.w-bg > div.result, div.card-web div.card-mobile, ol.react-results--main > li');
  468. }
  469. if (nws == true) liels = document.querySelectorAll('#res #rso div[class][data-hveid]'); //v2.2.6 for News results under www
  470. if (!liels) return;
  471. }
  472. if (isch && liels.length==0){
  473. liels = document.querySelectorAll('div.rg_di, div.isv-r');
  474. } else if (liels.length==0){
  475. if (engine == 'Google'){
  476. liels = document.querySelectorAll("#res li.g, #res div.srg div.g, #res div._NId div.g, #res div._bkWMgd div.g, #res #rso div.g, #res #GTR div.g, #res #isr_mc, g-section-with-header g-scrolling-carousel g-inner-card, g-card div.dbsr, g-card, [data-async-context^=\"query:\"] div.g");
  477. } else {
  478. liels = document.querySelectorAll('div#results li, div#results > div.result, div#links > div.results_links_deep > div.links_main, div#links > div.nrn-react-div, div#b_content ol > li.b_algo, div#results div#web > ol > li, div#WS2m > div.w, div.sw-CardBase, div.serp-list > div.serp-item, ul.serp-list > li.serp-item, div#main_results > div.result, div.results-column div.result--web, div.results-column div.result--news, #content_left > div.result.c-container, #content_left > div.result-op.c-container, ol.list-flat > li, div.w-gl__result, div.w-gl > div.result, div.w-bg > div.result, div.card-web div.card-mobile, ol.react-results--main > li');
  479. }
  480. }
  481. if (liels.length == 0) return;
  482. if (liels.length == 1){ // Google Standard Image Results
  483. if(liels[0].id == "isr_mc") liels = liels[0].querySelectorAll(".rg_di");
  484. }
  485. var hosts, hiders, nhider, i, j, k, hid, ael, ahref, dom, dompart, btn, apar, dgone, pban, linkwidth;
  486. hosts = blist;
  487. for (i=0; i<liels.length; i++){
  488. if ((liels[i].parentNode.nodeName == "OL" || liels[i].parentNode.nodeName == "TD" ||
  489. liels[i].classList.contains("card-section") || liels[i].classList.contains("ct-cs") || liels[i].classList.contains("w-gl__result") ||
  490. (liels[i].parentNode.nodeName == "DIV" && (liels[i].parentNode.classList.contains("srg") ||
  491. liels[i].parentNode.classList.contains("_NId") || liels[i].parentNode.parentNode.classList.contains("_NId") ||
  492. liels[i].parentNode.classList.contains("bkWMgd") || liels[i].parentNode.parentNode.classList.contains("bkWMgd") ||
  493. liels[i].nodeName === 'G-INNER-CARD' || liels[i].nodeName === 'G-CARD')) ||
  494. (liels[i].parentNode.nodeName == "DIV" && liels[i].closest('#rso, [data-async-context^="query:"]') !== null) ||
  495. (engine != 'Google' && liels[i].parentNode.nodeName == "DIV") ||
  496. (engine == 'Startpage' && liels[i].classList.contains("result")) ||
  497. liels[i].classList.contains('serp-item')) &&
  498. liels[i].className.indexOf("gbt")!=0 &&
  499. liels[i].classList.contains("gplusgrid") === false &&
  500. liels[i].classList.contains("mitem") === false &&
  501. liels[i].classList.contains("kno-kp") === false) {
  502. liels[i].setAttribute("ghhresult","unset");
  503. hiders = liels[i].getElementsByClassName("ghhider");
  504. nhider = hiders.length;
  505. if (nhider == 0 || ovrd == true){ // skip if a button is there
  506. hid = false;
  507. ael = liels[i].querySelector("div.r > a, h3 a, div.rc a"); // first link (not useful for video or book blocks), <h3> preferred
  508. if (!ael || ael.parentNode.className=='deeplink_title') ael = liels[i].querySelector("h2 a, h4 a");
  509. if (!ael) ael = liels[i].querySelector("a");
  510. if (liels[i].classList.contains("videobox")) ael = liels[i].querySelectorAll("td")[1].querySelector("a"); //video page
  511. if (engine == 'Google' && location.search.indexOf('adtest=on') > -1){
  512. ael = liels[i].querySelector('cite');
  513. if(ael){if(!ael.hasAttribute('href')){
  514. if (ael.textContent.indexOf('http://')===-1 && ael.textContent.indexOf('https://')===-1) ael.setAttribute('href', 'http://'+ael.textContent);
  515. else ael.setAttribute('href', ael.textContent);
  516. }}
  517. }
  518. if (engine == 'Baidu'){
  519. if(liels[i].hasAttribute('mu')){
  520. liels[i].insertAdjacentHTML('beforeend', '<span style="display:none"><a class="c-showurl" href="' + liels[i].getAttribute('mu') +'">' + liels[i].getAttribute('mu') + '</a></span>');
  521. }
  522. ael = liels[i].querySelector("a.c-showurl");
  523. if(ael){if(!ael.hasAttribute('href')){
  524. if (ael.textContent.indexOf('http://')===-1 && ael.textContent.indexOf('https://')===-1) ael.setAttribute('href', 'http://'+ael.textContent);
  525. else ael.setAttribute('href', ael.textContent);
  526. }}
  527. }
  528. if (engine == 'Startpage'){
  529. ael = liels[i].querySelector('a.result-link');
  530. }
  531. if (ael){ahref=ael.getAttribute("href"); if(ahref){if (ahref.search(/http|ftp/i)==0 || ahref.indexOf("/interstitial")==0 ||
  532. ahref.indexOf("/url?q=")==0 || ahref.indexOf(currentG+"/url?q=")>-1 || ahref.indexOf("/url?sa=")==0 ||
  533. (ahref.indexOf("/aclk?")==0 && liels[i].classList.contains("psli")) ||
  534. ahref.indexOf("//r.search.yahoo")==0 || ahref.indexOf(currentG+"/link?url=")>-1 ||
  535. ahref.indexOf('/rebates/welcome') === 0){
  536. if (engine == 'Bing'){ // v2.2.7
  537. if (ahref.indexOf('https://www.bing.com/') === 0 || ahref.indexOf('/rebates/welcome') === 0){
  538. var citeEl = liels[i].querySelector('div:not(.b_algo_group) cite');
  539. if (citeEl) ahref = citeEl.textContent.trim();
  540. }
  541. }
  542. dom = ahref.substr(ahref.search(/http|ftp/i));
  543. if (ael.hasAttribute("data-href")) dom = ael.getAttribute("data-href").substr(ael.getAttribute("data-href").indexOf("http"));
  544. if (dom.indexOf(currentG+"/aclk?")>-1) dom = ahref.substr(ahref.indexOf("http", 10));
  545. if (ahref.indexOf("/url?sa=")>-1) dom = decodeURIComponent(ahref.substr(ahref.indexOf("&url=")+5));
  546. if (ahref.indexOf("r.search.yahoo.com/_ylt=")>-1) dom = decodeURIComponent(ahref.substr(ahref.indexOf("RU=http")+3));
  547. if (dom.indexOf("search.yahoo.co.jp/r/FOR=")>-1) dom = decodeURIComponent(ahref.substr(ahref.indexOf("/**http")+3));
  548. if (dom.indexOf("https://ixquick-proxy.com/do/spg/highlight.pl")>-1) dom = decodeURIComponent(ahref.substr(ahref.indexOf("&u=http")+3));
  549. if (currentG.indexOf("baidu") > -1) dom = '//' + ael.textContent.replace('https://', '').replace('http://', '').replace('....', '');
  550. // if (dom.indexOf("imgrefurl")>-1) dom = dom.match(/imgrefurl=([^&]+)/)[1];
  551. dom = dom.split("/")[2];
  552. if (dom.indexOf(":")> -1) dom = dom.substr(0,dom.indexOf(":")); // Strip port number
  553. dompart = dom;
  554. liels[i].setAttribute("ghhhost",dompart);
  555. while (dompart.indexOf(".")> -1) {
  556. if (hosts.indexOf("|"+dompart+":")>-1) { // These domains suck
  557. if (nhider > 0){ // Remove old buttons, notices, etc.
  558. for (k=hiders.length-1; k>=0; k--){
  559. hiders[k].remove();
  560. nhider = liels[i].getElementsByClassName("ghhider").length;
  561. }
  562. }
  563. if (liels[i].classList.contains("ghh1time") === false){
  564. if (hosts.indexOf("|"+dompart+":p")<0) { // Regular block
  565. if (showYN=="Y"){
  566. if (liels[i].classList.contains("results_links_deep")){ // DDG
  567. replaceHit(dompart,ael,liels[i].querySelector(".links_main"),"");
  568. }
  569. else replaceHit(dompart,ael,liels[i],"");
  570. }
  571. else replaceHit(dompart,ael,liels[i],"none");
  572. } else { // Perma-ban
  573. liels[i].setAttribute("blockhidden",dompart);
  574. if (engine != 'Google' && liels[i].classList.contains("ghhdnone") === false){
  575. liels[i].classList.add('ghhdnone');
  576. if (liels[i].classList.contains("links_main")) liels[i].parentNode.classList.add('ghhdnone');
  577. }
  578. }
  579. if (engine == 'DDG' && liels[i].classList.contains("results_links_deep")) kids = liels[i].lastElementChild.children; //DDG
  580. else kids = liels[i].children;
  581. for (j=0; j<kids.length; j++){ // Hide Google result
  582. if (kids[j].classList.contains("ghhider") === false && kids[j].classList.contains("ghhdnone") === false){
  583. kids[j].classList.add('ghhdnone');
  584. }
  585. }
  586. }
  587. if (liels[i].classList.contains("psli")) liels[i].style.padding = "0"; // Shopping results
  588. hid = true;
  589. break;
  590. }
  591. else {
  592. dompart = dompart.slice(dompart.indexOf(".")+1);
  593. if (dompart.indexOf(".") === -1 && dompart != "tld") dompart += '.tld';
  594. }
  595. }
  596. if (hid == false && nhider > 1) { // Remove previous block & reset nhider
  597. if (liels[i].children[0].classList.contains("ghhd")) liels[i].children[0].remove();
  598. // Clean up unblocked one-times
  599. if (liels[i].classList.contains("ghh1time")){
  600. liels[i].classList.remove('ghh1time');
  601. dgone = liels[i].getElementsByClassName("ghhd");
  602. if (dgone.length > 0) dgone[0].remove();
  603. dgone = liels[i].getElementsByClassName("ghhdbuttons");
  604. if (dgone.length > 0) dgone[0].remove();
  605. }
  606. nhider = liels[i].getElementsByClassName("ghhider").length;
  607. }
  608. if (hid == false && (nhider == 0 || liels[i].children[0].nodeName.toLowerCase() == 'g-section-with-header')) { // Not blocked, insert block button
  609. // First, remove hiding for unblocked domains
  610. if (engine == 'DDG' && liels[i].classList.contains("results_links_deep")) kids = liels[i].lastElementChild.children; //DDG
  611. else kids = liels[i].children;
  612. for (j=0; j<kids.length; j++){
  613. if (kids[j].classList.contains("ghhdnone")){
  614. kids[j].classList.remove('ghhdnone');
  615. }
  616. }
  617. if (liels[i].hasAttribute("blockhidden")){
  618. liels[i].removeAttribute("blockhidden");
  619. liels[i].classList.remove('ghhdnone');
  620. if (engine == 'DDG' && liels[i].classList.contains("links_main")) liels[i].parentNode.classList.remove('ghhdnone');
  621. }
  622. if (liels[i].hasAttribute("blocknotice")) liels[i].removeAttribute("blocknotice");
  623. if (liels[i].parentNode.hasAttribute("blocknotice")) liels[i].parentNode.removeAttribute("blocknotice"); //DDG
  624. // Insert block button
  625. apar = ael;
  626. if (engine == 'Google'){
  627. if (location.search.indexOf('adtest=on') > -1){
  628. apar = liels[i].querySelector("h3 a, a");
  629. if (!apar.hasAttribute('hreforiginal')) apar.setAttribute('hreforiginal', ael.getAttribute('href'));
  630. } else {
  631. if (!apar.hasAttribute('hreforiginal')) apar.setAttribute('hreforiginal', apar.href);
  632. }
  633. }
  634. if (engine == 'Baidu'){
  635. apar = liels[i].querySelector("h3 a, .c-result-content a");
  636. if (!apar && liels[i].querySelector("p.op_site_domain_title, div.op_generalqa_main.c-row") != null) apar = liels[i].querySelector("p.op_site_domain_title, div.op_generalqa_main.c-row").firstChild;
  637. }
  638. if (apar != null && !apar.nextElementSibling){
  639. if (apar.parentNode.nodeName != "LI" &&
  640. apar.parentNode.nodeName != "TD" &&
  641. apar.parentNode.nodeName != "H2") apar = apar.parentNode;
  642. }
  643. if (apar != null && apar != undefined) { if (dom.indexOf(currentG)<0 &&
  644. (liels[i].parentNode != document.querySelector("#tads ol")) &&
  645. (liels[i].parentNode != document.querySelector("#bottomads ol")) &&
  646. (liels[i].parentNode != document.querySelector("#ads div")) &&
  647. (liels[i].parentNode != document.querySelector("#rhs ol"))){
  648. btn = document.createElement("button");
  649. btn.appendChild(document.createTextNode(txts.block[0]));
  650. btn.className="ghhider ghhb";
  651. btn.setAttribute("meta",dom);
  652. if (pref1click.substr(0,1) == "Y" && mbstyle.split("-")[4] == "Y"){ //BUG: for 1-click with aggressive (subdomain) settings, dom will be incorrect
  653. if (engine == 'Google') btn.setAttribute("title","Block "+dom+" / SHIFT+click to display block form / ALT+click to omit");
  654. else btn.setAttribute("title","Block "+dom+" / SHIFT+click to display block form");
  655. } else if (mbstyle.split("-")[4] == "Y"){
  656. if (engine == 'Google') btn.setAttribute("title","Block "+dom+" / Show block form / ALT+click to omit");
  657. else btn.setAttribute("title","Block "+dom+" / Show block form");
  658. }
  659. btn.addEventListener("click",showbfd,true);
  660. // Position button inside the H2 or H3 or H4
  661. if (apar.nodeName == "H3" || apar.nodeName == "H2" || apar.nodeName == "H4" || engine == 'Startpage'){
  662. apar.style.overflow = "visible";
  663. apar.appendChild(btn);
  664. // full link text tooltip
  665. if (engine == 'Yahoo' && apar.querySelector('a').childNodes[0].nodeName == 'SPAN') apar.querySelector('a').setAttribute("title",apar.querySelector('a').childNodes[1].textContent);
  666. else if (engine == 'Startpage' && apar.nodeName == 'A') {
  667. apar.parentNode.insertBefore(btn, apar.nextSibling);
  668. apar.setAttribute("title",apar.firstElementChild.textContent);
  669. }
  670. else apar.querySelector('a').setAttribute("title",apar.querySelector('a').textContent);
  671. } else if (apar.parentNode.parentNode.nodeName == 'G-CARD'){
  672. apar.parentNode.appendChild(btn);
  673. apar.parentNode.parentNode.style.overflowY = 'visible';
  674. apar.parentNode.parentNode.style.height = 'unset';
  675. apar.parentNode.parentNode.style.position = 'relative';
  676. } else if (apar.parentNode.className == 'dbsr') {
  677. apar.parentNode.appendChild(btn);
  678. parentcard = apar.closest('g-card');
  679. if (parentcard){
  680. parentcard.style.overflowY = 'visible';
  681. parentcard.style.position = 'relative';
  682. }
  683. } else {
  684. if (apar.nextSibling) apar.parentNode.insertBefore(btn,apar.nextSibling);
  685. else apar.parentNode.appendChild(btn);
  686. }
  687. // Move button to citeline 6/10/2013; updated 8/16/2020 to look for action-menu first
  688. if (bbpos == "C") {
  689. var axnmenu = liels[i].querySelector(".action-menu");
  690. var citelines = liels[i].querySelectorAll("cite");
  691. if (axnmenu){ // parentNode is a span
  692. axnmenu.parentNode.insertBefore(btn, axnmenu);
  693. if (citelines.length > 0) axnmenu.parentNode.className = citelines[0].className;
  694. } else {
  695. for (var citenum=0; citenum<citelines.length; citenum++){
  696. if (window.getComputedStyle(citelines[citenum]).visibility != "hidden"){
  697. citelines[citenum].parentNode.appendChild(btn);
  698. btn.removeAttribute("style");
  699. if (engine == 'Google') btn.style.visibility = 'visible';
  700. } else { // add to visibility:hidden element for spacing
  701. citelines[citenum].parentNode.appendChild(btn.cloneNode(true));
  702. if (engine == 'Google') btn.style.visibility = 'hidden';
  703. }
  704. }
  705. // Startpage.com
  706. citelines = liels[i].querySelectorAll('.w-gl__result-url-container');
  707. if (citelines.length > 0){
  708. citelines[0].appendChild(btn);
  709. btn.removeAttribute("style");
  710. }
  711. }
  712. }
  713. // Implement Mouseover Option 6/22/2012
  714. if (bbstyle == "M") {
  715. btn.style.visibility = "hidden";
  716. liels[i].addEventListener("mouseover",togglebbtn,false);
  717. liels[i].addEventListener("mouseout",togglebbtn,false);
  718. }
  719. // Avoid unhiding garbage span 5/25/2012
  720. for (j=0; j<liels[i].children.length; j++){
  721. if (liels[i].children[j].classList.contains("ghhider") === false){
  722. if (liels[i].children[j].style.display=="none") liels[i].children[j].setAttribute("wasdisplaynone","wasdisplaynone");
  723. }
  724. }
  725. }}
  726. }
  727. }}}
  728. }
  729. } else { // Check for and handle Google standard image results - doesn't yet support BASIC image results
  730. if (liels[i].classList.contains("rg_di") || liels[i].classList.contains("isv-r")){
  731. if (!liels[i].hasAttribute("imgblock") || ovrd == true){ // skip if previously processed
  732. liels[i].setAttribute("imgblock", "normal");
  733. ael = liels[i].querySelector('a[href*="."]');
  734. if (ael && ael.href.indexOf('/search?') == -1){
  735. if (ael.getAttribute("href").indexOf("imgrefurl")>-1){ // Site showing the image ("visit page")
  736. dom = decodeURIComponent(ael.href).match(/imgrefurl=([^&]+)/)[1].split("/")[2];
  737. } else if (ael.getAttribute("href").indexOf("imgurl")>-1){ // Site hosting the image ("view image")
  738. dom = decodeURIComponent(ael.href).match(/imgurl=([^&]+)/)[1].split("/")[2];
  739. } else { //sometimes you get a clean URL
  740. dom = ael.getAttribute("href").split("/")[2];
  741. }
  742. if (dom.length > 0){
  743. if (dom.indexOf(":")> -1) dom = dom.substr(0,dom.indexOf(":")); // Strip port number
  744. dompart = dom;
  745. while (dompart.indexOf(".")> -1) {
  746. if (hosts.indexOf("|"+dompart+":")>-1) { // These domains suck
  747. if (hosts.indexOf("|"+dompart+":p")<0) { // Regular block
  748. liels[i].setAttribute("imgblock", "regular");
  749. } else { // Perma-ban
  750. liels[i].setAttribute("imgblock", "pban");
  751. }
  752. break;
  753. } else {
  754. dompart = dompart.slice(dompart.indexOf(".")+1);
  755. if (dompart.indexOf(".") === -1 && dompart != "tld") dompart += '.tld';
  756. }
  757. }
  758. }
  759. }
  760. }
  761. var imgshuffle = false; // CHANGE TO TRUE TO TURN ON SHUFFLING (CURRENTLY BROKEN)
  762. if (imgshuffle){
  763. // Standard image results: move p-banned nodes to the end to maintain overall page length (otherwise, autoloading stops)
  764. if (t_gimg) window.clearTimeout(t_gimg);
  765. t_gimg = window.setTimeout(fixImagesLayout, 500);
  766. }
  767. }
  768. }
  769. }
  770. if (!document.getElementById("ghhMngBtn") && mbstyle.split("-")[0] != "blk" && document.getElementById("res")) addMngBtn();
  771. if (document.getElementsByClassName("unbtn").length > 1) undupMngBtn();
  772. if (betatest == "Y" && engine == 'Google'){ // BETA - NEW - v1.5.2
  773. // If there are more than two completely invisible results, modify the query to exclude the first hidden site
  774. var invis = document.querySelectorAll("li[blockhidden]");
  775. if (invis.length >= 3) reQry("+-site:"+invis[0].getAttribute("blockhidden"));
  776. }
  777. }
  778. function fixImagesLayout(){
  779. // BUGGY: REPLACEMENT IMAGES DO NOT LOAD UNTIL YOU TRIGGER A REPAINT (e.g., open/close Find bar, resize window, zoom in then zoom out)
  780. var madeamove = false;
  781. var rgshes = document.querySelectorAll(".rgsh");
  782. var lastdatapg = rgshes[rgshes.length-1].getAttribute("data-pg");
  783. var badimg = document.querySelectorAll('div[imgblock="pban"]');
  784. // TODO: Create setting to let user choose to remove regular blocks, too; temporary workaround: uncomment the following line:
  785. // var badimg = document.querySelectorAll('div[imgblock="pban"],div[imgblock="regular"]');
  786. if (badimg.length > 0){
  787. for (var bi=0; bi<badimg.length; bi++){
  788. if (badimg[bi].hasAttribute("newdatapg")){ // already moved
  789. if (badimg[bi].getAttribute("newdatapg") != lastdatapg){
  790. document.getElementById("rg_s").appendChild(badimg[bi]);
  791. badimg[bi].setAttribute("newdatapg", lastdatapg);
  792. madeamove = true;
  793. }
  794. } else { // first move
  795. document.getElementById("rg_s").appendChild(badimg[bi]);
  796. badimg[bi].setAttribute("newdatapg", lastdatapg);
  797. madeamove = true;
  798. }
  799. }
  800. // Trigger Google's function to re-layout the results neatly
  801. if (madeamove){
  802. var sctag = document.createElement("script");
  803. sctag.setAttribute("type", "text/javascript");
  804. sctag.appendChild(document.createTextNode("google.isr.layoutInit();"));
  805. document.body.appendChild(sctag);
  806. }
  807. }
  808. }
  809. function replaceHit(sdomain,oa,oli,ddis){
  810. var fc, dnew, dset, btn;
  811. fc = oli.querySelector('h3, h2');
  812. if (!fc) fc = oli.firstChild;
  813. if (fc.nodeName=="DIV" && fc.classList.contains("ghhider")) return;
  814. dnew = document.createElement("div");
  815. if (oa.querySelector('h3')){
  816. dnew.appendChild(document.createTextNode(oa.querySelector('h3').textContent+" on "+sdomain));
  817. } else if (nws == true && oa.querySelector('div[role="heading"]')) { //v2.2.6 for News results under www
  818. dnew.appendChild(document.createTextNode(oa.querySelector('div[role="heading"]').textContent+" on "+sdomain));
  819. } else if (oli.nodeName === 'G-INNER-CARD' || oli.nodeName === 'G-CARD' || oli.className === 'dbsr'){
  820. if (oa.children[1]) dnew.appendChild(document.createTextNode(oa.children[1].textContent+" on "+sdomain));
  821. else if (oa.children[0] && oa.children[0].children[1] && oa.children[0].children[1].children[1]) dnew.appendChild(document.createTextNode(oa.children[0].children[1].children[1].textContent+" on "+sdomain));
  822. dnew.style.whiteSpace = 'normal';
  823. } else {
  824. if (engine == 'Yahoo' && oa.childNodes[0].nodeName == 'SPAN') dnew.appendChild(document.createTextNode(oa.childNodes[1].textContent+" on "+sdomain)); //v2.2.1
  825. else dnew.appendChild(document.createTextNode(oa.textContent+" on "+sdomain));
  826. }
  827. dnew.className="ghhider ghhd";
  828. dnew.setAttribute("title","Click to view, unblock or Perma-ban");
  829. dnew.style.display = ddis;
  830. if (ddis == "none"){
  831. oli.setAttribute("blockhidden",sdomain);
  832. if (oli.hasAttribute("blocknotice")) oli.removeAttribute("blocknotice");
  833. } else {
  834. oli.setAttribute("blocknotice",sdomain);
  835. if (oli.hasAttribute("blockhidden")) oli.removeAttribute("blockhidden");
  836. oli.classList.remove('ghhdnone');
  837. if (oli.parentNode.classList.contains("results_links_deep")){
  838. oli.parentNode.setAttribute("blocknotice",sdomain);
  839. if (oli.parentNode.hasAttribute("blockhidden")) oli.parentNode.removeAttribute("blockhidden");
  840. oli.parentNode.classList.remove('ghhdnone');
  841. }
  842. }
  843. dnew.addEventListener("click",reshow,false);
  844. // dnew is disappearing on Bing in Chrome TODO: FIXIT
  845. if (oli.className === 'dbsr'){
  846. parentcard = oa.closest('g-card');
  847. if (parentcard){
  848. parentcard.insertBefore(dnew, parentcard.firstChild);
  849. }
  850. } else {
  851. oli.insertBefore(dnew,oli.firstChild);
  852. }
  853. dset = document.createElement("div");
  854. dset.className = "ghhider ghhindent";
  855. dset.setAttribute("dom",sdomain);
  856. dset.style.display = "none";
  857. btn = document.createElement("button");
  858. btn.appendChild(document.createTextNode(txts.unblock[0]));
  859. btn.className="ghhider";
  860. btn.setAttribute("title","Unblock this site");
  861. btn.style.backgroundColor="#9f6";
  862. btn.addEventListener("click",unblock,false);
  863. dset.appendChild(btn);
  864. btn = document.createElement("button");
  865. btn.appendChild(document.createTextNode(txts.pban[0]));
  866. btn.className="ghhider";
  867. btn.setAttribute("title","Permanently hide this site");
  868. btn.style.backgroundColor="#f66";
  869. btn.addEventListener("click",permban,false);
  870. dset.appendChild(btn);
  871. btn = document.createElement("button");
  872. btn.appendChild(document.createTextNode("close"));
  873. btn.className="ghhider";
  874. btn.setAttribute("title","Re-hide this hit");
  875. btn.style.backgroundColor="#eee";
  876. btn.addEventListener("click",rehide,false);
  877. dset.appendChild(btn);
  878. dnew.appendChild(dset);
  879. if (dnew.parentNode.style.overflow == "hidden" || dnew.parentNode.style.overflowX == "hidden"){
  880. dnew.insertBefore(document.createElement("br"), dnew.firstChild);
  881. }
  882. dset.addEventListener("click",ghhkillevent,false);
  883. if (oli.classList.contains("psli")) dnew.style.margin = "1em 0"; // Shopping results
  884. }
  885. function hidebasic(tbl){ // BASIC IMAGE RESULTS, BETA ONLY, NON-AJAX
  886. var hosts, tds, i, j, k, hid, ael, dom, dompart, btn, apar, dgone;
  887. hosts = blist;
  888. tds = tbl.querySelectorAll("td");
  889. for (i=0; i<tds.length; i++){
  890. ael = tds[i].querySelector("a");
  891. if (ael){if(ael.hasAttribute("href")){if (ael.getAttribute("href").indexOf("imgrefurl=")>-1){
  892. dom = ael.getAttribute("href").substr(ael.getAttribute("href").indexOf("imgrefurl=")+7).split("/")[2];
  893. if (dom.indexOf(":")> -1) dom = dom.substr(0,dom.indexOf(":")); // Strip port number
  894. dompart = dom;
  895. while (dompart.indexOf(".")> -1) {
  896. if (hosts.indexOf("|"+dompart+":")>-1) { // These domains suck; mark the cell for now
  897. if (hosts.indexOf("|"+dompart+":p")>-1 || showYN=="N") tds[i].setAttribute("ghhaction","delete");
  898. else tds[i].setAttribute("ghhaction","notice");
  899. break;
  900. } else {
  901. dompart = dompart.slice(dompart.indexOf(".")+1);
  902. if (dompart.indexOf(".") === -1 && dompart != "tld") dompart += '.tld';
  903. }
  904. }
  905. }}}
  906. }
  907. for (i=0; i<tds.length; i++){
  908. switch (tds[i].getAttribute("ghhaction")){
  909. case "delete":
  910. // TODO implement deletion
  911. tds[i].innerHTML = "delete cell";
  912. break;
  913. case "notice":
  914. // TODO implement clickable notices
  915. tds[i].style.textDecoration = "line-through";
  916. tds[i].style.opacity = "0.3";
  917. break;
  918. default:
  919. // TODO add block button
  920. }
  921. }
  922. }
  923. // == == == Other Functions == == ==
  924. function reshow(e){ // Show hit without unblocking
  925. var liel, ael, dabs, k;
  926. liel = e.target.closest('[ghhresult]');
  927. if (!liel) return;
  928. liel.classList.add('ghh1time');
  929. // Hide notice, move action buttons, then show hit
  930. e.target.style.display="none";
  931. ael = liel.querySelector("div.r > a, h3 a, .c-result-content a");
  932. if (!ael && engine == 'DDG') ael = liel.querySelector('article h2 > a');
  933. if (!ael && engine == 'Baidu' && liel.hasAttribute('mu')) ael = liel.querySelector("p.op_site_domain_title, div.op_generalqa_main.c-row").firstChild;
  934. if (!ael) ael = liel.querySelector("span.tl a"); // summarized news result
  935. if (!ael) ael = liel.querySelector("a"); // other
  936. if (liel.classList.contains("videobox")) ael = liel.querySelectorAll("td")[1].querySelector("a"); //video page
  937. dabs = e.target.firstElementChild;
  938. if (engine != 'Bing'){
  939. if (ael.parentNode.classList.contains('ghh1time')){
  940. ael.parentNode.insertBefore(dabs,ael.nextSibling);
  941. } else {
  942. if (ael.parentNode.parentNode.nodeName === 'G-INNER-CARD' || ael.parentNode.parentNode.nodeName === 'G-CARD') ael.parentNode.parentNode.insertBefore(dabs,ael.parentNode);
  943. else {
  944. if (ael.parentNode.nextSibling) ael.parentNode.parentNode.insertBefore(dabs,ael.parentNode.nextSibling);
  945. else ael.parentNode.parentNode.appendChild(dabs);
  946. }
  947. }
  948. dabs.className = "ghhdbuttons";
  949. dabs.removeAttribute("style");
  950. if (dabs.nextElementSibling) if (dabs.nextElementSibling.className.indexOf("ghhider") == 0 || dabs.nextElementSibling.innerHTML == "block") dabs.parentNode.removeChild(dabs.nextElementSibling);
  951. } else {
  952. // TODO dabs is disappearing on Bing when moved -- temporarily, don't move it
  953. e.target.style.display='';
  954. dabs.className = "ghhdbuttons";
  955. dabs.removeAttribute("style");
  956. }
  957. for (k=1; k<liel.children.length; k++){
  958. liel.children[k].classList.remove('ghhdnone');
  959. }
  960. e.stopPropagation();
  961. }
  962. // Hide or Show hit notices
  963. async function updtpref(e){
  964. var btns, j, hds, s;
  965. if (showYN == "Y"){
  966. if (confirm("No longer show titles or buttons for suppressed results?")){
  967. ghhPrefO.shownotc[0] = "N";
  968. if (!GM4){
  969. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  970. } else {
  971. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  972. }
  973. showYN = ghhPrefO.shownotc[0];
  974. togHiderDivs("no");
  975. }
  976. } else {
  977. hds = document.getElementsByClassName("ghhd");
  978. if (hds.length > 0) s = (hds.length == 1) ? "is 1 blocked hit" : "are "+hds.length+" blocked hits";
  979. else s = "are no blocked hits";
  980. if (confirm("Show titles and buttons for suppressed results? (There "+s+" on this page.)")){
  981. ghhPrefO.shownotc[0] = "Y";
  982. if (!GM4){
  983. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  984. } else {
  985. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  986. }
  987. showYN = ghhPrefO.shownotc[0];
  988. togHiderDivs("yes");
  989. }
  990. }
  991. fixShowHideBtn();
  992. e.target.blur();
  993. }
  994. function fixShowHideBtn(){
  995. var chkMP = document.getElementById("chkshownotc");
  996. var chkBF = document.getElementById("chkshownotcbf");
  997. if (showYN == "Y"){
  998. chkMP.setAttribute("checked","checked");
  999. chkMP.checked = true;
  1000. if (chkBF){
  1001. chkBF.setAttribute("checked","checked");
  1002. chkBF.checked = true;
  1003. }
  1004. } else {
  1005. chkMP.removeAttribute("checked");
  1006. chkMP.checked = false;
  1007. if (chkBF){
  1008. chkBF.removeAttribute("checked");
  1009. chkBF.checked = false;
  1010. }
  1011. }
  1012. }
  1013. function togHiderDivs(sShow){
  1014. var dh, i;
  1015. dh = document.getElementsByClassName("ghhider");
  1016. for(i=0;i<dh.length;i++) {
  1017. if (dh[i].nodeName == "DIV" && dh[i].classList.contains("ghhindent") === false) {
  1018. if (sShow == "yes") dh[i].style.display = "";
  1019. else dh[i].style.display = "none";
  1020. }
  1021. }
  1022. }
  1023. // Remove domain from the block list
  1024. async function unblock(e){
  1025. var elPar, sdom, slist, liel, tgt;
  1026. elPar = e.target.parentNode;
  1027. sdom = elPar.getAttribute("dom");
  1028. if (!sdom || sdom.length<4){
  1029. alert("Problem with domain to unblock");
  1030. return;
  1031. }
  1032. if (!GM4){
  1033. slist = GM_getValue("hideyhosts");
  1034. } else {
  1035. slist = await GM.getValue("hideyhosts");
  1036. }
  1037. if (slist.substr(0,1) != "|") slist = "|" + slist;
  1038. slist = slist.replace("|"+sdom+":t","");
  1039. if (!GM4){
  1040. GM_setValue("hideyhosts", slist);
  1041. } else {
  1042. await GM.setValue("hideyhosts", slist);
  1043. }
  1044. blist = slist;
  1045. needupdate = true;
  1046. liel = elPar.closest('[ghhresult]');
  1047. if ((liel.nodeName =="LI" || liel.nodeName == "DIV") && liel.classList.contains("ghh1time")){
  1048. liel.classList.remove('ghh1time');
  1049. var ghhds = liel.getElementsByClassName("ghhd");
  1050. if (ghhds.length > 0) ghhds[0].remove();
  1051. elPar.remove();
  1052. }
  1053. hidehits(null,true);
  1054. if (document.getElementById("ghhmngform")){
  1055. if(document.getElementById("ghhmngform").style.display=="block") refreshSiteList();
  1056. }
  1057. }
  1058. // Add domain to the Perma-ban list
  1059. async function permban(e){
  1060. if (!confirm("Never see hits for this domain again?")) return;
  1061. var dpar, sdom, slist, liel;
  1062. dpar = e.target.parentNode;
  1063. sdom = dpar.getAttribute("dom");
  1064. if (!GM4){
  1065. slist = GM_getValue("hideyhosts");
  1066. } else {
  1067. slist = await GM.getValue("hideyhosts");
  1068. }
  1069. if (slist.substr(0,1) != "|") slist = "|" + slist;
  1070. slist = slist.replace("|"+sdom+":t","|"+sdom+":p");
  1071. if (!GM4){
  1072. GM_setValue("hideyhosts", slist);
  1073. } else {
  1074. await GM.setValue("hideyhosts", slist);
  1075. }
  1076. blist = slist;
  1077. needupdate = true;
  1078. liel = dpar.closest('[ghhresult]');
  1079. if (!liel) alert('Developer error in permban (no liel)');
  1080. if ((liel.nodeName =="LI" || liel.nodeName == "DIV" || liel.nodeName == 'G-INNER-CARD' || liel.nodeName == 'G-CARD') && liel.classList.contains("ghh1time")){
  1081. liel.classList.remove('ghh1time');
  1082. }
  1083. if(dpar.classList.contains("ghhindent")) dpar = dpar.parentNode;
  1084. dpar.remove();
  1085. hidehits(null,true);
  1086. if (document.getElementById("GTR")) removePBs();
  1087. if (document.getElementById("ghhmngform")){
  1088. if(document.getElementById("ghhmngform").style.display=="block") refreshSiteList();
  1089. }
  1090. }
  1091. // Close this bad result and rehide (to allow indendent open/close, do not run through hidehits)
  1092. function rehide(e){
  1093. var dpar, liel, dompart, ael, j;
  1094. dpar = e.target.parentNode;
  1095. liel = dpar.closest('[ghhresult]');
  1096. if (!liel) alert('Developer error in rehide (no liel)');
  1097. dompart = dpar.getAttribute("dom");
  1098. if (engine != 'Bing'){
  1099. dpar.remove();
  1100. liel.removeChild(liel.querySelector("div.ghhd"));
  1101. } else {
  1102. // TODO notice is disappearing on Bing -- temporarily, do not move/remove the buttons div
  1103. liel.querySelector('div.ghhd > div.ghhdbuttons').style.display = 'none';
  1104. }
  1105. ael = liel.querySelector("h3 a, h2 a, a h2, a h3");
  1106. if (!ael) ael = liel.querySelector("a");
  1107. liel.classList.remove('ghh1time');
  1108. replaceHit(dompart,ael,liel,"");
  1109. for (j=0; j<liel.children.length; j++){ // Hide Google result
  1110. if (liel.children[j].classList.contains("ghhider") === false && liel.children[j].classList.contains("ghhdnone") === false){
  1111. liel.children[j].classList.add('ghhdnone');
  1112. }
  1113. }
  1114. }
  1115. // Functions relating to the Block form
  1116. function addBlockForm(){
  1117. var bfd = document.createElement("div");
  1118. bfd.id = "ghhblockform";
  1119. bfd.className = "ghhpane";
  1120. var bfdcode = '<form onsubmit="return false;"><p style="margin:0.75em 0;"><strong>添加至屏蔽列表:</strong></p><p><label ' +
  1121. 'style="white-space:pre"><input type="radio" name="ghhdom" value="f"> <span id="ghhfulldom"></span></label><br>' +
  1122. '<label><input type="radio" name="ghhdom" value="p"> <span id="ghhpartdom"></span> <button type="button" id="ghhdomadj" ' +
  1123. 'title="调整部分域名" style="position: absolute; right: 1em; padding: 0 1px;">~</button></label></p>' +
  1124. '<p style="text-align:center;white-space:pre;line-height:2em;margin:0.75em 0"><button type="button" id="ghhbf1" bt="t"> ' +
  1125. txts.okbtn[0] + ' </button> <button type="button" id="ghhbf3" bt="p"> ' + txts.okPbtn[0] + ' </button><br>' +
  1126. '<button type="button" id="ghhbf2" mng="N"> ' + txts.cancelbtn[0] + ' </button> ' +
  1127. '<button type="button" id="ghhbf4" mng="Y">' + txts.cancelMbtn[0] + '</button></p>';
  1128. if (engine == 'Google'){
  1129. bfdcode += "<p style=\"border-top:1px solid #aaa;text-align:center;white-space:pre;line-height:2em;margin:0.75em 0;padding-top:0.5em;\">编辑查询: <button type=\"button\" id=\"ghhbf5\" title=\"仅限此网站\"> +site: </button> " +
  1130. "<button type=\"button\" id=\"ghhbf6\" title=\"排除此网站\"> -site: </button></p>";
  1131. }
  1132. bfdcode += "<p style=\"margin:0.75em 0;\"><label title=\"切换显示或隐藏常规屏蔽结果标题\"><input " +
  1133. "type=\"checkbox\" name=\"chkshownotcbf\" id=\"chkshownotcbf\"> 显示隐藏提示</label><br>" +
  1134. "<label title=\"切换屏蔽对话框和一键屏蔽\"><input type=\"checkbox\" name=\"chk1clickbf\" " +
  1135. "id=\"chk1clickbf\"> 启用一键屏蔽</label></p></form>";
  1136. bfd.innerHTML = bfdcode;
  1137. document.body.appendChild(bfd);
  1138. document.getElementById("ghhbf1").addEventListener("click",addblock,false);
  1139. document.getElementById("ghhbf2").addEventListener("click",ghhcloseform,false);
  1140. document.getElementById("ghhbf3").addEventListener("click",addblock,false);
  1141. document.getElementById("ghhbf4").addEventListener("click",ghhcloseform,false);
  1142. if (engine == 'Google'){
  1143. document.getElementById("ghhbf5").addEventListener("click",reQuery,false);
  1144. document.getElementById("ghhbf6").addEventListener("click",reQuery,false);
  1145. }
  1146. document.getElementById("ghhblockform").addEventListener("click",ghhkillevent,false);
  1147. document.getElementById("chkshownotcbf").addEventListener("change",updtpref,false);
  1148. document.getElementById("chk1clickbf").addEventListener("change",updt1click,false);
  1149. document.getElementById("ghhdomadj").addEventListener("click",adjpartdom,false);
  1150. }
  1151. function showbfd(e) {
  1152. var bbtn, bfdiv, fdom, pdom, fspan, pspan, tdiv, lt;
  1153. bbtn = e.target;
  1154. fdom = bbtn.getAttribute("meta");
  1155. if (!document.getElementById("ghhblockform")) addBlockForm();
  1156. fspan = document.getElementById("ghhfulldom");
  1157. fspan.textContent = fdom;
  1158. fspan.previousElementSibling.checked = true;
  1159. pdom = fdom.substr(fdom.indexOf(".")+1);
  1160. pspan = document.getElementById("ghhpartdom");
  1161. if (pdom.indexOf(".") > -1 && patIPv4.test(fdom) != true) {
  1162. pspan.textContent = pdom;
  1163. pspan.parentNode.style.display = "";
  1164. switch (bAggress){
  1165. case 'all':
  1166. pspan.previousElementSibling.checked = true; break;
  1167. case 'www':
  1168. if (fdom.substr(0,3) == 'www') pspan.previousElementSibling.checked = true; break;
  1169. default:
  1170. // default to full domain
  1171. }
  1172. document.getElementById("ghhdomadj").style.display = '';
  1173. } else {
  1174. pspan.parentNode.style.display = "none";
  1175. document.getElementById("ghhdomadj").style.display = 'none';
  1176. }
  1177. if (e.altKey == true && engine == 'Google'){
  1178. reQuery(); return;
  1179. }
  1180. bfdiv = document.getElementById("ghhblockform");
  1181. tdiv = document.getElementById("ghhtemp");
  1182. if (!tdiv){
  1183. tdiv = document.createElement("div");
  1184. tdiv.id = "ghhtemp";
  1185. }
  1186. if (isch == true){
  1187. tdiv.setAttribute("style", "position:absolute;right:0;top:4em;z-index:3000;width:250px;");
  1188. bbtn.parentNode.appendChild(tdiv);
  1189. } else if (e.target.parentNode.parentNode.nodeName == 'G-INNER-CARD' || e.target.parentNode.parentNode.nodeName == 'G-CARD') {
  1190. tdiv.setAttribute("style", "position:absolute;left:8px;top:8px;z-index:9999;width:100%;");
  1191. e.target.parentNode.parentNode.insertBefore(tdiv, e.target.parentNode.parentNode.children[0]);
  1192. } else if (e.target.parentNode.nodeName == 'G-INNER-CARD' || e.target.parentNode.nodeName == 'G-CARD') {
  1193. tdiv.setAttribute("style", "position:absolute;left:8px;top:8px;z-index:9999;width:100%;");
  1194. e.target.parentNode.insertBefore(tdiv, e.target.parentNode.children[0]);
  1195. } else if (e.target.parentNode.className == 'dbsr') {
  1196. tdiv.setAttribute("style", "position:absolute;left:8px;top:8px;z-index:9999;width:100%;");
  1197. e.target.parentNode.insertBefore(tdiv, e.target.parentNode.children[0]);
  1198. } else if(engine == 'Google' && bbpos == 'C') {
  1199. tdiv.setAttribute("style", "position:absolute;left:8px;top:16px;z-index:9999;width:100%;");
  1200. e.target.parentNode.style.position = 'relative';
  1201. e.target.parentNode.insertBefore(tdiv, e.target.parentNode.children[0]);
  1202. } else {
  1203. lt = bbtn.offsetLeft + bbtn.offsetWidth + 12;
  1204. if (bbtn.parentNode.previousElementSibling){
  1205. if (window.getComputedStyle(bbtn.parentNode.previousElementSibling,null).getPropertyValue("float") != "none" ||
  1206. (bbtn.style.position == "absolute" && bbtn.parentNode.nodeName == "TD")) lt=lt-bbtn.parentNode.offsetLeft;
  1207. }
  1208. if (document.querySelector('table#GTR')){
  1209. lt-=230;
  1210. }
  1211. if (engine != 'Google') lt=lt-bbtn.parentNode.offsetLeft;
  1212. if (engine == 'Startpage') lt = 16;
  1213. if (engine == 'Google' && bbtn.closest('div.g') != null){
  1214. tdiv.setAttribute("style", "position:relative;left:" + lt + "px;top:-18px;z-index:500;width:250px;");
  1215. bbtn.closest('div.g').insertBefore(tdiv, bbtn.closest('div.g').children[0]);
  1216. } else {
  1217. tdiv.setAttribute("style", "position:relative;left:" + lt + "px;top:-65px;z-index:500;width:250px;");
  1218. if (bbtn.nextElementSibling){
  1219. if (bbtn.nextElementSibling.nodeName == "DIV" || bbtn.nextElementSibling.nodeName == "BR") bbtn.parentNode.insertBefore(tdiv,bbtn.nextElementSibling);
  1220. else bbtn.parentNode.appendChild(tdiv);
  1221. }
  1222. else bbtn.parentNode.appendChild(tdiv);
  1223. }
  1224. }
  1225. tdiv.appendChild(bfdiv);
  1226. if (window.getComputedStyle(tdiv.parentNode).overflowX == "hidden" || window.getComputedStyle(tdiv.parentNode).overflowY == "hidden"){
  1227. tdiv.parentNode.style.overflowX = "visible";
  1228. tdiv.parentNode.style.overflowY = "visible";
  1229. }
  1230. if (pref1click.substr(0,1) == "Y" && e.shiftKey != true && isch != true){ // 1-click; hold Shift to override
  1231. if (pref1click.substr(2,1) == "N"){
  1232. document.getElementById("ghhbf1").click();
  1233. } else {
  1234. document.getElementById("ghhbf3").click();
  1235. }
  1236. } else { // regular + populating 1-click checkbox
  1237. var chkBF = document.getElementById("chk1clickbf");
  1238. if (pref1click.substr(0,1) == "Y"){
  1239. chkBF.setAttribute("checked","checked");
  1240. chkBF.checked = true;
  1241. } else {
  1242. chkBF.removeAttribute("checked");
  1243. chkBF.checked = false;
  1244. }
  1245. chkBF = document.getElementById("chkshownotcbf");
  1246. if (showYN == "Y"){
  1247. chkBF.setAttribute("checked","checked");
  1248. chkBF.checked = true;
  1249. } else {
  1250. chkBF.removeAttribute("checked");
  1251. chkBF.checked = false;
  1252. }
  1253. bfdiv.style.display = "block";
  1254. document.getElementById("ghhbf1").focus();
  1255. }
  1256. e.stopPropagation();
  1257. }
  1258. function adjpartdom(e){ // v1.8.1
  1259. var pspan = document.getElementById("ghhpartdom");
  1260. var parts = pspan.textContent.replace('...', '').split(".");
  1261. if (parts.length <= 2){
  1262. if (parts.length == 2 && parts[1].indexOf('tld [all') !== 0){
  1263. // offer the entire TLD option v1.9.9
  1264. parts.push('tld [all dot-' + parts[1] + '\'s]');
  1265. } else {
  1266. // cycle back to the original partial domain
  1267. parts = document.getElementById("ghhfulldom").textContent.split(".");
  1268. }
  1269. }
  1270. parts.shift(); // discard leftmost subdomain
  1271. pspan.textContent = parts.join(".");
  1272. }
  1273. async function addblock(e){
  1274. var btype, els, i, sdom, tgt;
  1275. tgt = e.target;
  1276. btype = tgt.getAttribute("bt");
  1277. els = tgt.form.querySelectorAll('input[type="radio"]');
  1278. for (i=0; i<els.length; i++){
  1279. if(els[i].checked == true){
  1280. sdom = els[i].nextElementSibling.textContent.split(" ")[0];
  1281. break;
  1282. }
  1283. }
  1284. ghhcloseform(e);
  1285. if (blist.substr(0,1) != "|") blist = "|" + blist;
  1286. if (!btype) btype = "t";
  1287. if (addAt == "end") blist += sdom + ":" + btype + "|";
  1288. else blist = "|" + sdom + ":" + btype + blist;
  1289. needupdate = true;
  1290. if (!GM4){
  1291. GM_setValue("hideyhosts", blist);
  1292. } else {
  1293. await GM.setValue("hideyhosts", blist);
  1294. }
  1295. hidehits(null,true);
  1296. if (document.getElementById("GTR")) removePBs();
  1297. if (addAt == "sort") sortlist(null);
  1298. if (document.getElementById("ghhmngform")){
  1299. if(document.getElementById("ghhmngform").style.display=="block") refreshSiteList();
  1300. }
  1301. }
  1302. async function ghhcloseform(e){
  1303. if (!e) return;
  1304. if (typeof(e) == "object" && e.target){
  1305. if(e.target.id.indexOf("ghhbf") == 0){
  1306. var mng = e.target.getAttribute("mng");
  1307. var bfdiv = document.getElementById("ghhblockform");
  1308. var tdiv = document.getElementById("ghhtemp");
  1309. bfdiv.style.display = "none";
  1310. document.body.appendChild(bfdiv);
  1311. tdiv.remove();
  1312. if (mng == "Y") showManageForm("mngform");
  1313. }
  1314. if(e.target.id.indexOf("ghhmf") == 0){
  1315. if (mbstyle.split("-")[0] == "mng") toggleBlockHiders("H");
  1316. document.getElementById("ghhmngform").style.display = "none";
  1317. if (mpopen.substr(0,3) == "Y-Y"){
  1318. mpopen = "Y-N";
  1319. ghhPrefO.mngpaneopen[0] = mpopen;
  1320. if (!GM4){
  1321. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1322. } else {
  1323. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1324. }
  1325. }
  1326. }
  1327. } else {
  1328. if(e == "mngform"){
  1329. if (mbstyle.split("-")[0] == "mng") toggleBlockHiders("H");
  1330. document.getElementById("ghhmngform").style.display = "none";
  1331. if (mpopen.substr(0,3) == "Y-Y"){
  1332. mpopen = "Y-N";
  1333. ghhPrefO.mngpaneopen[0] = mpopen;
  1334. if (!GM4){
  1335. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1336. } else {
  1337. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1338. }
  1339. }
  1340. }
  1341. }
  1342. e.stopPropagation();
  1343. }
  1344. async function imgblockdialog(e){
  1345. var viewer = e.target.closest('[ghhresult]');
  1346. if (!viewer) return;
  1347. var ael = viewer.parentNode.children[0].querySelector('._r3 a[href], span > a[href]');
  1348. if (!ael) ael = viewer.querySelector('a[href]'); // Aug. 2019 design
  1349. if (!ael){ alert('Cannot find the URL in this design.'); return; }
  1350. var ameta = ael.href.split("/")[2];
  1351. if (ael.href.indexOf("&url=")>-1) ameta = decodeURIComponent(ael.href).match(/&url=([^&]+)/)[1].split("/")[2];
  1352. if (ameta.indexOf(":")> -1) ameta = ameta.substr(0,ameta.indexOf(":")); // Strip port number
  1353. e.target.setAttribute("meta", ameta);
  1354. var dompart = ameta;
  1355. while (dompart.indexOf(".")> -1) {
  1356. if (blist.indexOf("|"+dompart+":") > -1){
  1357. if (confirm("Unblock " + dompart + "?")){
  1358. if (!GM4){
  1359. var slist = GM_getValue("hideyhosts");
  1360. } else {
  1361. slist = await GM.getValue("hideyhosts");
  1362. }
  1363. if (slist.substr(0,1) != "|") slist = "|" + slist;
  1364. slist = slist.replace("|"+dompart+":t","").replace("|"+dompart+":p","");
  1365. if (!GM4){
  1366. GM_setValue("hideyhosts", slist);
  1367. } else {
  1368. await GM.setValue("hideyhosts", slist);
  1369. }
  1370. blist = slist;
  1371. needupdate = true;
  1372. hidehits(null,true);
  1373. if (document.getElementById("ghhmngform")){
  1374. if(document.getElementById("ghhmngform").style.display=="block") refreshSiteList();
  1375. }
  1376. }
  1377. e.stopPropagation();
  1378. return;
  1379. } else {
  1380. dompart = dompart.slice(dompart.indexOf(".")+1);
  1381. }
  1382. }
  1383. showbfd(e);
  1384. }
  1385. // Functions relating to the Manage Hiding button
  1386. function addMngBtn(){
  1387. if (mbstyle.split("-")[0] == "blk") return;
  1388. if (window.self != window.top) if (mbstyle.split("-")[1] == "ifrN") return;
  1389. var mbtn;
  1390. mbtn = document.createElement("button");
  1391. mbtn.appendChild(document.createTextNode(txts.mngbtn[0]));
  1392. mbtn.className="ghhider unbtn";
  1393. mbtn.setAttribute("title","Manage Google Hit Hider Settings / Ctrl+click to re-hide");
  1394. mbtn.id = "ghhMngBtn";
  1395. mbtn.addEventListener("click",handleManageButton,true);
  1396. document.body.appendChild(mbtn);
  1397. }
  1398. function undupMngBtn(){
  1399. var unbtns = document.getElementsByClassName("unbtn");
  1400. while (unbtns.length > 1){
  1401. unbtns[unbtns.length - 1].parentNode.removeChild(unbtns[unbtns.length - 1]);
  1402. }
  1403. }
  1404. function handleManageButton(e){
  1405. if (e.ctrlKey){
  1406. var btnM = e.target;
  1407. btnM.style.backgroundColor = 'aqua';
  1408. hidehits(null, false);
  1409. window.setTimeout(function(){btnM.style.backgroundColor = ''}, 250);
  1410. } else {
  1411. showManageForm(e);
  1412. }
  1413. }
  1414. async function showManageForm(e){
  1415. if (window.self != window.top) return;
  1416. var mfd;
  1417. if (!document.getElementById("ghhmngform")) addManageForm();
  1418. mfd = document.getElementById("ghhmngform");
  1419. if (mfd.style.display != "none" && e != "mngform"){ // Toggle to hidden
  1420. if (mbstyle.split("-")[0] == "mng") toggleBlockHiders("H");
  1421. if (mpopen.substr(0,3) == "Y-Y"){
  1422. mpopen = "Y-N";
  1423. ghhPrefO.mngpaneopen[0] = mpopen;
  1424. if (!GM4){
  1425. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1426. } else {
  1427. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1428. }
  1429. }
  1430. mfd.style.display = "none";
  1431. } else {
  1432. if (needupdate == true) refreshSiteList();
  1433. mfd.style.display = "block";
  1434. if (mpopen.substr(0,3) == "Y-Y" && mpopen.length == 5){ // Restore last displayed tab
  1435. var tabnum = mpopen.substr(4,1);
  1436. if (document.getElementById('ghhmt'+tabnum).style.display == "none"){
  1437. togglelist('ghhts'+tabnum);
  1438. if (mbstyle.split("-")[0] == "mng") toggleBlockHiders("S");
  1439. if (typeof e == "object") e.target.blur();
  1440. return;
  1441. }
  1442. }
  1443. if (document.getElementById("ghhmt1").style.display != "none" || document.getElementById("ghhmt4").style.display != "none"){
  1444. document.getElementById("ghhmf1").setAttribute("disabled","disabled");
  1445. document.getElementById("ghhutil").style.display = "none";
  1446. }
  1447. else {
  1448. if (document.getElementById("ghhmf1").hasAttribute("disabled")) document.getElementById("ghhmf1").removeAttribute("disabled");
  1449. if (bLUopen != "N") document.getElementById("ghhutil").style.display = "block";
  1450. }
  1451. setCurrentTab();
  1452. if (mbstyle.split("-")[0] == "mng") toggleBlockHiders("S");
  1453. }
  1454. if (typeof e == "object") e.target.blur();
  1455. }
  1456. function setCurrentTab(){
  1457. var k, tabnum;
  1458. var tabset = document.querySelectorAll("#mflists>div");
  1459. for (k=0; k<tabset.length; k++){
  1460. tabnum = tabset[k].getAttribute("id");
  1461. tabnum = tabnum.substr(tabnum.length-1);
  1462. if (tabset[k].style.display != "none"){
  1463. document.getElementById("ghhts"+tabnum).className = "ghhCurTab";
  1464. if (mpopen.substr(0,1) == "Y"){
  1465. mpopen = "Y-Y-"+tabnum;
  1466. ghhPrefO.mngpaneopen[0] = mpopen;
  1467. if (!GM4){
  1468. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1469. } else { /* NOT SYNCHRONOUS */
  1470. GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1471. }
  1472. }
  1473. }
  1474. else document.getElementById("ghhts"+tabnum).className = "";
  1475. }
  1476. }
  1477. // Functions relating to the Manage GHH form
  1478. function addManageForm(){
  1479. var mfd = document.createElement("div");
  1480. mfd.id = "ghhmngform";
  1481. mfd.className = "ghhpane";
  1482. mfd.setAttribute("style","display:none;");
  1483. mfd.innerHTML = "<form onsubmit=\"return false;\"><div id=\"ghhtsdiv\">" +
  1484. "<p style=\"margin:6px 0 -1px 0\" id=\"ghhtstrip\">" +
  1485. "<button type=\"button\" id=\"ghhts1\" title=\"常规使用和通知\">首页</button>" +
  1486. "<button type=\"button\" id=\"ghhts2\" title=\"常规屏蔽列表\">常规屏蔽</button>" +
  1487. "<button type=\"button\" id=\"ghhts3\" title=\"永久屏蔽列表\">永久屏蔽</button>" +
  1488. "<button type=\"button\" id=\"ghhts4\" title=\"管理脚本选项\">选项</button></p></div>" +
  1489. "<div id=\"mflists\" style=\"width:230px\">" +
  1490. "<div id=\"ghhmt1\"><p>欢迎使用 Google Hit Hider! <a href=\"https://www.jeffersonscher.com/gm/google-hit-hider/\" " +
  1491. "style=\"float:right;\" target=\"_blank\" title=\"文档\">JS</a></p>" +
  1492. "<div class=\"ghhtab\">" +
  1493. "<p style=\"padding:0.25em;margin:0.25em\">点击这个在标题旁的按钮 ( <button type=\"button\" class=\"ghhider\" onclick=\"return false;\">" + txts.block[0] + "</button> ) " +
  1494. ",来屏蔽该网站的搜索结果。 一个被 <b>常规屏蔽</b> 的网站显示为单行网址, " +
  1495. "而一个被 <b>永久屏蔽</b> 的网站会消失。</p>" +
  1496. "<p style=\"border-top:1px solid #000; padding:0.25em;margin:0.25em\"><label title=\"切换显示或隐藏常规屏蔽结果的标题" +
  1497. "for regular blocked hits\"><input type=\"checkbox\" name=\"chkshownotc\" id=\"chkshownotc\"> 显示屏蔽通知</label><br>" +
  1498. "<label title=\"切换屏蔽对话框和一键屏蔽\"><input type=\"checkbox\" name=\"chk1click\" " +
  1499. "id=\"chk1click\"> 启用一键屏蔽</label></p>" +
  1500. "<p style=\"border-top:1px solid #000; padding:0.25em;margin:0.25em\">v2.3.1 &copy; 2024 Jefferson Scher. 了解更多信息,请访问" +
  1501. "<a href=\"" + script_about + "\">此脚本页面</a>.</p></div></div>" +
  1502. "<div id=\"ghhmt2\" style=\"display:none\"><p>单击以从常规屏蔽列表中删除:</p>" +
  1503. "<div class=\"ghhtab\"><ul id=\"ghhsitelist\"></ul></div></div>\n" +
  1504. "<div id=\"ghhmt3\" style=\"display:none\"><p>单击以从永久屏蔽列表中删除:</p>" +
  1505. "<div class=\"ghhtab\"><ul id=\"ghhpbanlist\"></ul></div></div>" +
  1506. "<div id=\"ghhmt4\" style=\"display:none\"><p>脚本管理选项:</p>" +
  1507. "<div class=\"ghhtab\" id=\"btnedit\">" +
  1508. "<p id=\"addradios\">添加新屏蔽的域名:<br>" +
  1509. "<label><input type=\"radio\" name=\"addpos\" value=\"end\"> 添加到列表末尾</label><br>" +
  1510. "<label><input type=\"radio\" name=\"addpos\" value=\"top\"> 添加到列表顶部</label><br>" +
  1511. "<label><input type=\"radio\" name=\"addpos\" value=\"sort\"> 按字母顺序排序</label></p>" +
  1512. "<p id=\"aggressrads\" style=\"border-top:1px solid #000;padding-top:0.25em;margin-bottom:8px\">默认屏蔽方式:<br>" +
  1513. "<label><input type=\"radio\" name=\"agglevel\" value=\"none\"> 始终完整域名</label><br>" +
  1514. "<label><input type=\"radio\" name=\"agglevel\" value=\"all\"> 始终部分域名</label><br>" +
  1515. "<label><input type=\"radio\" name=\"agglevel\" value=\"www\"> 仅对www使用部分域名</label></p>" +
  1516. "<p id=\"btnradios\" style=\"border-top:1px solid #000;padding-top:0.25em;margin-bottom:8px\">用户界面风格:<br>" +
  1517. "<label><input type=\"radio\" name=\"uistyle\" value=\"both\">显示Manage Hiding" + "和" + txts.block[0] + "按钮" + "</label><br>" +
  1518. "<label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"checkbox\" name=\"mbiframe\" id=\"mbiframe\">在 iframe 中隐藏该按钮</label><br>" +
  1519. "<label title=\"您可以单击" + txts.block[0] + "按钮打开此对话框\"><input type=\"radio\" name=\"uistyle\" value=\"blk\">隐藏Manage Hiding按钮</label><br>" +
  1520. "<label title=\"" + txts.block[0] + "按钮仅在显示此对话框时显示\"><input type=\"radio\" name=\"uistyle\" value=\"mng\">隐藏" + txts.block[0] + "按钮</label><br>" +
  1521. "<span style=\"display:inline-block;margin-top:4px;\">Manage Hiding 按钮位置:</span><br>" +
  1522. "<label><input type=\"radio\" name=\"mngbtnpos\" value=\"R\"> 侧面</label> " +
  1523. "<label><input type=\"radio\" name=\"mngbtnpos\" value=\"T\"> 顶部</label> " +
  1524. "<label><input type=\"radio\" name=\"mngbtnpos\" value=\"B\"> 底部</label><br>" +
  1525. "<span style=\"display:inline-block;margin-top:4px;\">屏蔽按钮位置<i>(重新加载)</i>:</span><br>" +
  1526. "<label><input type=\"radio\" name=\"blockposit\" value=\"H\"> 标题行</label> " +
  1527. "<label><input type=\"radio\" name=\"blockposit\" value=\"C\"> 引用行</label><br>" +
  1528. "<span style=\"display:inline-block;margin-top:4px;\">显示屏蔽按钮:</span><br>" +
  1529. "<label><input type=\"radio\" name=\"blockdisp\" value=\"P\"> 总是</label> " +
  1530. "<label><input type=\"radio\" name=\"blockdisp\" value=\"M\"> 鼠标悬停时</label><br>" +
  1531. "<span style=\"display:inline-block;margin-top:4px;\">屏蔽按钮工具提示:</span><br>" +
  1532. "<label><input type=\"radio\" name=\"blockttip\" value=\"Y\"> 完整详情</label> " +
  1533. "<label><input type=\"radio\" name=\"blockttip\" value=\"N\"> 无</label></p>" +
  1534. "<p id=\"miscpref\" style=\"border-top:1px solid #000;padding-top:0.25em;margin-bottom:8px\">其他设置:<br>" +
  1535. "<label><input type=\"checkbox\" name=\"chkajax\" id=\"chkajax\"> 即时/AJAX/自动分页</label><br>" +
  1536. "<label><input type=\"checkbox\" name=\"chkdom4\" id=\"chkdom4\"> DOM4 变化观察器</label><br>" +
  1537. "<label><input type=\"checkbox\" name=\"chkmpopen\" id=\"chkmpopen\"> 重启管理面板</label><br>" +
  1538. "<label><input type=\"checkbox\" name=\"chk1pban\" id=\"chk1pban\"> 一键永久禁止列表</label><br>" +
  1539. "<label title=\"尝试尚未完全测试的功能\"><input type=\"checkbox\" name=\"chkbeta\" " +
  1540. "id=\"chkbeta\"> 启用测试功能</label></p>" +
  1541. "<p style=\"border-top:1px solid #000;padding-top:0.25em;margin-bottom:8px\">编辑说明文字:</p>" +
  1542. "<p><button type=\"button\" class=\"ghhider\" id=\"ghhedit1\" key=\"block\">" + txts.block[0] + "</button> " +
  1543. "<button type=\"button\" class=\"ghhider\" id=\"ghhedit3\" key=\"unblock\" style=\"background:#9f6\">" + txts.unblock[0] + "</button> " +
  1544. "<button type=\"button\" class=\"ghhider\" id=\"ghhedit2\" key=\"pban\" style=\"background:#f66\">" + txts.pban[0] + "</button></p>" +
  1545. "<p><i>重新加载以完成更改</i></p><p><button type=\"button\" id=\"ghhmfr\">恢复默认说明文字</button></p>" +
  1546. "<p style=\"border-top:1px solid #000;padding-top:0.25em;margin-bottom:8px\">自定义样式规则:<br>" +
  1547. "<button type=\"button\" id=\"ghhecsr\">编辑自定义样式规则</button></p></div></div>" +
  1548. "</div><p style=\"text-align:center;white-space:pre;margin:1em 0\">" +
  1549. "<button type=\"button\" id=\"ghhmf1\">" + txts.savebtn[0] + "<span id=\"numchgs\"></span></button> " +
  1550. "<button type=\"button\" id=\"ghhmf3\" title=\"显示列表管理的其他按钮\">列表工具" +
  1551. "<div style=\"display:inline;font-size:0.9em;color:#888\"><span id=\"ghhdowntriangle\">&#9660;</span>" +
  1552. "<span id=\"ghhuptriangle\" style=\"display:none\">&#9650;</span></div></button> " +
  1553. "<button type=\"button\" id=\"ghhmf2\">" + txts.closebtn[0] + "</button></p><p id=\"ghhutil\" style=\"display:none\">" +
  1554. "<button type=\"button\" id=\"ghhmf4\" title=\"显示可复制备份或共享的阻止列表\">" +
  1555. txts.eximbtn[0] + "</button> <button type=\"button\" id=\"ghhmf7\" title=\"将域名导入阻止列表\">" +
  1556. txts.impobtn[0] + "</button> <button type=\"button\" id=\"ghhmf8\" title=\"将此页面上的所有域名添加到当前列表\">" +
  1557. txts.addallbtn[0] + "</button><br /><button type=\"button\" id=\"ghhmf5\" title=\"按字母顺序排序\">" +
  1558. txts.sortbtn[0] + "</button> <button type=\"button\" id=\"ghhmf6\" title=\"通过删除不必要的域名对阻止列表进行去重\">" +
  1559. txts.dedupbtn[0] + "</button> <button type=\"button\" id=\"ghhmf9\" title=\"从被阻止的域名中移除 www\">" +
  1560. txts.unwwwbtn[0] + "</button></p></form>";
  1561. document.body.appendChild(mfd);
  1562. fixShowHideBtn();
  1563. fixuistyle();
  1564. fixaddpos();
  1565. fixaggblock();
  1566. fixajaxstyle();
  1567. fixpanepersist();
  1568. fix1clickstyle();
  1569. fixBeta();
  1570. document.getElementById("ghhts1").addEventListener("click",togglelist,true); // tabs
  1571. document.getElementById("ghhts2").addEventListener("click",togglelist,true);
  1572. document.getElementById("ghhts3").addEventListener("click",togglelist,true);
  1573. document.getElementById("ghhts4").addEventListener("click",togglelist,true);
  1574. document.getElementById("chkshownotc").addEventListener("change",updtpref,true); // home
  1575. document.getElementById("chk1click").addEventListener("change",updt1click,true);
  1576. document.getElementById("ghhsitelist").addEventListener("click",togglesite,true); // block
  1577. document.getElementById("ghhpbanlist").addEventListener("click",togglesite,true); // pban
  1578. document.getElementById("addradios").addEventListener("change",updtaddpos,true); // options
  1579. document.getElementById("aggressrads").addEventListener("change",updtaggress,true);
  1580. document.getElementById("chkajax").addEventListener("change",updtAJAX,true);
  1581. document.getElementById("chkdom4").addEventListener("change",updtAJAX,true);
  1582. document.getElementById("chkmpopen").addEventListener("change",updtpersist,true);
  1583. document.getElementById("chk1pban").addEventListener("change",updt1click,true);
  1584. document.getElementById("chkbeta").addEventListener("change",updtBeta,true);
  1585. document.getElementById("btnradios").addEventListener("change",updtuistyle,true);
  1586. document.getElementById("ghhedit1").addEventListener("click",chgcaption,true);
  1587. document.getElementById("ghhedit2").addEventListener("click",chgcaption,true);
  1588. document.getElementById("ghhedit3").addEventListener("click",chgcaption,true);
  1589. document.getElementById("ghhmfr").addEventListener("click",resetTextStrings,true);
  1590. document.getElementById("ghhecsr").addEventListener("click",openCustomStyleBar,true);
  1591. document.getElementById("ghhmf1").addEventListener("click",saveedits,true); // buttons
  1592. document.getElementById("ghhmf2").addEventListener("click",ghhcloseform,true);
  1593. document.getElementById("ghhmf3").addEventListener("click",toggleListUtil,true);
  1594. document.getElementById("ghhmf4").addEventListener("click",exportlist,true);
  1595. document.getElementById("ghhmf5").addEventListener("click",sortlist,true);
  1596. document.getElementById("ghhmf6").addEventListener("click",dedup,true);
  1597. document.getElementById("ghhmf7").addEventListener("click",importlist,true);
  1598. document.getElementById("ghhmf8").addEventListener("click",addAllNow,true);
  1599. document.getElementById("ghhmf9").addEventListener("click",unwww,true);
  1600. // Add JS icon link
  1601. addBtnLink();
  1602. }
  1603. async function addBtnLink(){
  1604. var JSBTN = document.createElement("img");
  1605. JSBTN.setAttribute('alt', 'JS');
  1606. if (typeof GM.getResourceUrl === "undefined"){
  1607. JSBTN.src = GM_getResourceURL("mycon");
  1608. } else { /* asynchronous*/
  1609. JSBTN.src = await GM.getResourceUrl("mycon");
  1610. }
  1611. document.querySelector("#ghhmt1 a").textContent = "";
  1612. document.querySelector("#ghhmt1 a").appendChild(JSBTN);
  1613. }
  1614. function togglelist(e){ // Change tabs
  1615. if (typeof e === 'string'){
  1616. var tgtid = e;
  1617. } else {
  1618. e.target.blur();
  1619. if (e.target.className == "ghhCurTab") return;
  1620. tgtid = e.target.id;
  1621. }
  1622. var tabbtns = document.querySelectorAll("#ghhtstrip>button");
  1623. var k, tabnum;
  1624. for (k=0; k<tabbtns.length; k++){
  1625. tabnum = tabbtns[k].id;
  1626. tabnum = tabnum.substr(tabnum.length-1);
  1627. if (tgtid == tabbtns[k].id){
  1628. document.getElementById("ghhmt"+tabnum).style.display = "";
  1629. } else {
  1630. document.getElementById("ghhmt"+tabnum).style.display = "none";
  1631. }
  1632. }
  1633. if (document.getElementById("ghhmt1").style.display != "none" || document.getElementById("ghhmt4").style.display != "none"){
  1634. document.getElementById("ghhmf1").setAttribute("disabled","disabled");
  1635. document.getElementById("ghhutil").style.display = "none";
  1636. } else {
  1637. if (document.getElementById("ghhmf1").hasAttribute("disabled")) document.getElementById("ghhmf1").removeAttribute("disabled");
  1638. if (bLUopen != "N") document.getElementById("ghhutil").style.display = "block";
  1639. }
  1640. setCurrentTab();
  1641. }
  1642. function toggleListUtil(e){ // Display/close extra set of buttons
  1643. e.target.blur();
  1644. var p = document.getElementById("ghhutil");
  1645. if (!p) return;
  1646. // If not displaying a list now, move to a list
  1647. if (document.getElementById("ghhmt1").style.display != "none" || document.getElementById("ghhmt4").style.display != "none"){
  1648. togglelist('ghhts2');
  1649. p.style.display = "block"; // Always open button pane
  1650. bLUopen = "Y";
  1651. document.getElementById('ghhdowntriangle').style.display = 'none';
  1652. document.getElementById('ghhuptriangle').style.display = '';
  1653. } else {
  1654. if (p.style.display != "block"){ // Toggle when list already was displayed
  1655. p.style.display = "block";
  1656. bLUopen = "Y";
  1657. document.getElementById('ghhdowntriangle').style.display = 'none';
  1658. document.getElementById('ghhuptriangle').style.display = '';
  1659. } else {
  1660. p.style.display = "none";
  1661. bLUopen = "N";
  1662. document.getElementById('ghhdowntriangle').style.display = '';
  1663. document.getElementById('ghhuptriangle').style.display = 'none';
  1664. }
  1665. }
  1666. }
  1667. function togglesite(e){ // Designate list items for unblock, pban or block
  1668. var t, l, s, pid;
  1669. t = e.target;
  1670. if (t.className == "ghhinfo") t = t.nextElementSibling;
  1671. l = t.parentNode;
  1672. pid = l.parentNode.id;
  1673. switch (t.className){
  1674. case "ghhhost ghhpb":
  1675. t.className = "ghhhost ghhblk"; // toggle to block
  1676. if (l.nodeName == "LI"){
  1677. if (pid == "ghhsitelist"){
  1678. l.children[0].style.display = "none";
  1679. listchgs = listchgs - 1;
  1680. } else {
  1681. l.children[0].style.display = "inline";
  1682. l.children[0].textContent = "to " + txts.block[0];
  1683. l.children[0].style.backgroundColor = "#ccc";
  1684. listchgs = listchgs + 1;
  1685. }
  1686. }
  1687. break;
  1688. case "ghhhost ghhdel":
  1689. t.className = "ghhhost ghhpb"; // toggle to perma-ban
  1690. if (l.nodeName == "LI"){
  1691. if (pid == "ghhpbanlist"){
  1692. l.children[0].style.display = "none";
  1693. listchgs = listchgs - 1;
  1694. } else {
  1695. l.children[0].style.display = "inline";
  1696. l.children[0].textContent = "to " + txts.pban[0];
  1697. l.children[0].style.backgroundColor = "#f66";
  1698. }
  1699. }
  1700. break;
  1701. default:
  1702. t.className = "ghhhost ghhdel"; // toggle to unblock
  1703. if (l.nodeName == "LI"){
  1704. l.children[0].style.display = "inline";
  1705. l.children[0].textContent = "to " + txts.unblock[0];
  1706. l.children[0].style.backgroundColor = "#9f6";
  1707. if (pid == "ghhsitelist"){
  1708. listchgs = listchgs + 1;
  1709. }
  1710. }
  1711. }
  1712. }
  1713. async function saveedits(e){ // Save changes made on tabs 2 and 3
  1714. if (e){
  1715. if (listchgs == 0){
  1716. if (!confirm("No changes detected. Save anyway?")){
  1717. e.target.blur();
  1718. return;
  1719. }
  1720. } else {
  1721. if (!confirm("Save changes to block list?")){
  1722. e.target.blur();
  1723. return;
  1724. }
  1725. }
  1726. }
  1727. var slist, i, sp, ttemp, ptemp;
  1728. slist = document.getElementById("ghhsitelist");
  1729. ttemp = "";
  1730. ptemp = "";
  1731. for (i=0;i<slist.children.length;i++){
  1732. if (slist.children[i].nodeName == "LI") {
  1733. sp = slist.children[i].children[1];
  1734. switch (sp.className){
  1735. case "ghhhost ghhblk":
  1736. ttemp += sp.textContent + ":t|";
  1737. break;
  1738. case "ghhhost ghhpb":
  1739. ptemp += sp.textContent + ":p|";
  1740. break;
  1741. default:
  1742. // to be unblocked
  1743. }
  1744. }
  1745. }
  1746. slist = document.getElementById("ghhpbanlist");
  1747. for (i=0;i<slist.children.length;i++){
  1748. if (slist.children[i].nodeName == "LI") {
  1749. sp = slist.children[i].children[1];
  1750. switch (sp.className){
  1751. case "ghhhost ghhblk":
  1752. ttemp += sp.textContent + ":t|";
  1753. break;
  1754. case "ghhhost ghhpb":
  1755. ptemp += sp.textContent + ":p|";
  1756. break;
  1757. default:
  1758. // to be unblocked
  1759. }
  1760. }
  1761. }
  1762. if (!GM4){
  1763. GM_setValue("hideyhosts", "|" + ttemp + ptemp);
  1764. blist = GM_getValue("hideyhosts");
  1765. } else {
  1766. await GM.setValue("hideyhosts", "|" + ttemp + ptemp);
  1767. blist = await GM.getValue("hideyhosts");
  1768. }
  1769. hidehits(null,true);
  1770. refreshSiteList();
  1771. listchgs = 0;
  1772. if (e) e.target.blur();
  1773. }
  1774. function refreshSiteList(){ // Rebuild lists for tabs 2 and 3
  1775. var sarray, slist = '', pblist = '', ulB, ulP, i;
  1776. if (blist.substr(0,1) != "|") blist = "|" + blist;
  1777. sarray = blist.substr(1).split("|");
  1778. for (i=0; i<sarray.length-1; i++){
  1779. if (sarray[i].indexOf(":p")<0) {
  1780. slist += '<li><span class="ghhinfo"></span><span class="ghhhost ghhblk">' + sarray[i].split(':')[0] + '</span></li>';
  1781. } else {
  1782. pblist += '<li><span class="ghhinfo"></span><span class="ghhhost ghhpb">' + sarray[i].split(':')[0] + '</span></li>';
  1783. }
  1784. }
  1785. ulB = document.getElementById("ghhsitelist");
  1786. while (ulB.firstChild) ulB.removeChild(ulB.firstChild);
  1787. ulB.insertAdjacentHTML('beforeend', slist);
  1788. ulP = document.getElementById("ghhpbanlist");
  1789. while (ulP.firstChild) ulP.removeChild(ulP.firstChild);
  1790. ulP.insertAdjacentHTML('beforeend', pblist);
  1791. needupdate = false;
  1792. }
  1793. async function updtaddpos(e){ // Implement change for radio buttons re where to add to list
  1794. var rads = e.target.parentNode.querySelectorAll("input[type='radio']");
  1795. for (var i=0; i<rads.length; i++){
  1796. if (rads[i].checked){
  1797. if (rads[i].value == "sort"){
  1798. if(confirm("Sort lists now? Sorting is irreversible.")){
  1799. if (listchgs > 0) {
  1800. if (confirm("You have unsaved changes to your lists. Save changes and sort, or cancel sorting?")){
  1801. saveedits(null);
  1802. } else {
  1803. fixaddpos();
  1804. return;
  1805. }
  1806. }
  1807. sortlist(null);
  1808. } else {
  1809. fixaddpos();
  1810. return;
  1811. }
  1812. }
  1813. addAt = rads[i].value;
  1814. ghhPrefO.addtolistpos[0] = addAt;
  1815. if (!GM4){
  1816. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1817. } else {
  1818. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1819. }
  1820. break;
  1821. }
  1822. }
  1823. fixaddpos();
  1824. }
  1825. function fixaddpos(){ // Check appropriate radio button re where to add to list
  1826. var rads = document.getElementById("addradios").querySelectorAll("input[type='radio']");
  1827. for (var i=0; i<rads.length; i++){
  1828. if (rads[i].value == addAt){
  1829. rads[i].setAttribute("checked","checked");
  1830. rads[i].checked = true;
  1831. }
  1832. else{
  1833. if (rads[i].hasAttribute("checked")){
  1834. rads[i].removeAttribute("checked");
  1835. rads[i].checked = false;
  1836. }
  1837. }
  1838. }
  1839. }
  1840. async function updtaggress(e){ // Implement change for radio buttons re default domain to block
  1841. var rads = e.target.parentNode.querySelectorAll("input[type='radio']");
  1842. for (var i=0; i<rads.length; i++){
  1843. if (rads[i].checked){
  1844. bAggress = rads[i].value;
  1845. ghhPrefO.aggressiveblock[0] = bAggress;
  1846. if (!GM4){
  1847. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1848. } else {
  1849. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1850. }
  1851. break;
  1852. }
  1853. }
  1854. fixaggblock();
  1855. }
  1856. function fixaggblock(){ // Check appropriate radio button re default domain to block
  1857. var rads = document.getElementById("aggressrads").querySelectorAll("input[type='radio']");
  1858. for (var i=0; i<rads.length; i++){
  1859. if (rads[i].value == bAggress){
  1860. rads[i].setAttribute("checked","checked");
  1861. rads[i].checked = true;
  1862. }
  1863. else{
  1864. if (rads[i].hasAttribute("checked")){
  1865. rads[i].removeAttribute("checked");
  1866. rads[i].checked = false;
  1867. }
  1868. }
  1869. }
  1870. }
  1871. async function updtuistyle(e){ // Store settings for buttons to display
  1872. var mbparts = mbstyle.split("-");
  1873. if (mbparts.length == 1) mbparts.push("ifrN");
  1874. if (mbparts.length == 2) mbparts.push("R");
  1875. if (mbparts.length == 3) mbparts.push("P");
  1876. if (mbparts.length == 4) mbparts.push("Y");
  1877. if (mbparts.length == 5) mbparts.push("H");
  1878. if (e.target.id == "mbiframe") { // Handle iframe checkbox
  1879. var chk = e.target;
  1880. if (chk.checked){
  1881. mbparts[1] = "ifrY";
  1882. } else {
  1883. mbparts[1] = "ifrN";
  1884. }
  1885. mbstyle = mbparts.join("-");
  1886. ghhPrefO.mngbtnstyle[0] = mbstyle;
  1887. if (!GM4){
  1888. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1889. } else {
  1890. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1891. }
  1892. } else { // Handle radio buttons
  1893. if (e.target.getAttribute("name") == "uistyle"){
  1894. var rads = e.target.parentNode.querySelectorAll("input[name='uistyle']");
  1895. for (var i=0; i<rads.length; i++){
  1896. if (rads[i].checked){
  1897. switch (rads[i].value){
  1898. case "blk":
  1899. mbparts[0] = rads[i].value;
  1900. document.getElementById("ghhMngBtn").remove();
  1901. alert("After you close the management pane, click any block button to open it again.");
  1902. break;
  1903. case "mng":
  1904. if(confirm("Display block buttons only when this dialog is open?")) mbparts[0] = "mng";
  1905. else e.target.checked = false;
  1906. break;
  1907. default:
  1908. mbparts[0] = "both";
  1909. if (!document.getElementById("ghhMngBtn")) addMngBtn();
  1910. }
  1911. mbstyle = mbparts.join("-");
  1912. ghhPrefO.mngbtnstyle[0] = mbstyle;
  1913. if (!GM4){
  1914. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1915. } else {
  1916. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1917. }
  1918. break;
  1919. }
  1920. }
  1921. } else { // Handle Management Button position and block button display style
  1922. rads = e.target.parentNode.querySelectorAll("input[name='mngbtnpos']");
  1923. for (i=0; i<rads.length; i++){
  1924. if (rads[i].checked){
  1925. mbparts[2] = rads[i].value;
  1926. mbstyle = mbparts.join("-");
  1927. ghhPrefO.mngbtnstyle[0] = mbstyle;
  1928. if (!GM4){
  1929. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1930. } else {
  1931. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1932. }
  1933. break;
  1934. }
  1935. }
  1936. rads = e.target.parentNode.querySelectorAll("input[name='blockdisp']");
  1937. for (i=0; i<rads.length; i++){
  1938. if (rads[i].checked){
  1939. mbparts[3] = rads[i].value;
  1940. mbstyle = mbparts.join("-");
  1941. ghhPrefO.mngbtnstyle[0] = mbstyle;
  1942. if (!GM4){
  1943. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1944. } else {
  1945. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1946. }
  1947. break;
  1948. }
  1949. }
  1950. rads = e.target.parentNode.querySelectorAll("input[name='blockttip']");
  1951. for (i=0; i<rads.length; i++){
  1952. if (rads[i].checked){
  1953. mbparts[4] = rads[i].value;
  1954. mbstyle = mbparts.join("-");
  1955. ghhPrefO.mngbtnstyle[0] = mbstyle;
  1956. if (!GM4){
  1957. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1958. } else {
  1959. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1960. }
  1961. break;
  1962. }
  1963. }
  1964. rads = e.target.parentNode.querySelectorAll("input[name='blockposit']");
  1965. for (i=0; i<rads.length; i++){
  1966. if (rads[i].checked){
  1967. mbparts[5] = rads[i].value;
  1968. mbstyle = mbparts.join("-");
  1969. ghhPrefO.mngbtnstyle[0] = mbstyle;
  1970. if (!GM4){
  1971. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1972. } else {
  1973. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  1974. }
  1975. window.location.reload();
  1976. break;
  1977. }
  1978. }
  1979. }
  1980. }
  1981. fixuistyle();
  1982. }
  1983. function fixuistyle(){ // Check appropriate radio button re buttons to display
  1984. if (mbstyle.split("-").length == 1) mbstyle = mbstyle + "-ifrN-R-P-Y-H";
  1985. if (mbstyle.split("-").length == 2) mbstyle = mbstyle + "-R-P-Y-H";
  1986. if (mbstyle.split("-").length == 3) mbstyle = mbstyle + "-P-Y-H";
  1987. if (mbstyle.split("-").length == 4) mbstyle = mbstyle + "-Y-H";
  1988. if (mbstyle.split("-").length == 5) mbstyle = mbstyle + "-H";
  1989. var rads = document.getElementById("btnradios").querySelectorAll("input[name^='uistyle']");
  1990. for (var i=0; i<rads.length; i++){
  1991. if (rads[i].value == mbstyle.split("-")[0]){
  1992. rads[i].setAttribute("checked","checked");
  1993. rads[i].checked = true;
  1994. }
  1995. else{
  1996. if (rads[i].hasAttribute("checked")){
  1997. rads[i].removeAttribute("checked");
  1998. rads[i].checked = false;
  1999. }
  2000. }
  2001. }
  2002. var chk = document.getElementById("mbiframe");
  2003. if (mbstyle.split("-")[1] == "ifrY"){
  2004. chk.setAttribute("checked","checked");
  2005. chk.checked = true;
  2006. } else {
  2007. chk.removeAttribute("checked");
  2008. chk.checked = false;
  2009. }
  2010. rads = document.getElementById("btnradios").querySelectorAll("input[name^='mngbtnpos']");
  2011. for (i=0; i<rads.length; i++){
  2012. if (rads[i].value == mbstyle.split("-")[2]){
  2013. rads[i].setAttribute("checked","checked");
  2014. rads[i].checked = true;
  2015. }
  2016. else{
  2017. if (rads[i].hasAttribute("checked")){
  2018. rads[i].removeAttribute("checked");
  2019. rads[i].checked = false;
  2020. }
  2021. }
  2022. }
  2023. rads = document.getElementById("btnradios").querySelectorAll("input[name^='blockdisp']");
  2024. for (i=0; i<rads.length; i++){
  2025. if (rads[i].value == mbstyle.split("-")[3]){
  2026. rads[i].setAttribute("checked","checked");
  2027. rads[i].checked = true;
  2028. }
  2029. else{
  2030. if (rads[i].hasAttribute("checked")){
  2031. rads[i].removeAttribute("checked");
  2032. rads[i].checked = false;
  2033. }
  2034. }
  2035. }
  2036. rads = document.getElementById("btnradios").querySelectorAll("input[name^='blockttip']");
  2037. for (i=0; i<rads.length; i++){
  2038. if (rads[i].value == mbstyle.split("-")[4]){
  2039. rads[i].setAttribute("checked","checked");
  2040. rads[i].checked = true;
  2041. }
  2042. else{
  2043. if (rads[i].hasAttribute("checked")){
  2044. rads[i].removeAttribute("checked");
  2045. rads[i].checked = false;
  2046. }
  2047. }
  2048. }
  2049. rads = document.getElementById("btnradios").querySelectorAll("input[name^='blockposit']");
  2050. for (i=0; i<rads.length; i++){
  2051. if (rads[i].value == mbstyle.split("-")[5]){
  2052. rads[i].setAttribute("checked","checked");
  2053. rads[i].checked = true;
  2054. }
  2055. else{
  2056. if (rads[i].hasAttribute("checked")){
  2057. rads[i].removeAttribute("checked");
  2058. rads[i].checked = false;
  2059. }
  2060. }
  2061. }
  2062. toggleciteline(mbstyle.split("-")[5]);
  2063. }
  2064. async function updtAJAX(e){ // Store settings for AJAX preferences
  2065. var chk = e.target;
  2066. if (chk.id == "chkajax"){
  2067. if (chk.checked){
  2068. bAJAX = "on";
  2069. if (chgMon) chgMon.disconnect();
  2070. else document.body.removeEventListener("DOMSubtreeModified", checkOlist, false);
  2071. setMutationWatch();
  2072. } else {
  2073. bAJAX = "off";
  2074. if (chgMon) chgMon.disconnect();
  2075. else document.body.removeEventListener("DOMSubtreeModified", checkOlist, false);
  2076. }
  2077. } else {
  2078. if (chk.checked){
  2079. bMutOb = "Y";
  2080. if (!chgMon){
  2081. if (bAJAX){
  2082. document.body.removeEventListener("DOMSubtreeModified", checkOlist, false);
  2083. setMutationWatch();
  2084. }
  2085. }
  2086. } else {
  2087. bMutOb = "N";
  2088. if (chgMon) chgMon.disconnect();
  2089. if (bAJAX){
  2090. document.body.removeEventListener("DOMSubtreeModified", checkOlist, false);
  2091. setMutationWatch();
  2092. }
  2093. }
  2094. }
  2095. ghhPrefO.usemutation[0] = bAJAX + "-" + bMutOb;
  2096. if (!GM4){
  2097. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  2098. } else {
  2099. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  2100. }
  2101. fixajaxstyle();
  2102. }
  2103. function fixajaxstyle(){ // Check boxes for AJAX preferences
  2104. var chk = document.getElementById("chkajax");
  2105. if (bAJAX == "on"){
  2106. chk.setAttribute("checked","checked");
  2107. chk.checked = true;
  2108. } else {
  2109. chk.removeAttribute("checked");
  2110. chk.checked = false;
  2111. }
  2112. chk = document.getElementById("chkdom4");
  2113. if (bMutOb == "Y"){
  2114. chk.setAttribute("checked","checked");
  2115. chk.checked = true;
  2116. } else {
  2117. chk.removeAttribute("checked");
  2118. chk.checked = false;
  2119. }
  2120. }
  2121. async function updtpersist(e){ // Store setting for persistence preference
  2122. var chk = e.target;
  2123. if (chk.checked){
  2124. mpopen = "Y" + mpopen.substr(1);
  2125. } else {
  2126. mpopen = "N" + mpopen.substr(1);
  2127. }
  2128. ghhPrefO.mngpaneopen[0] = mpopen;
  2129. if (!GM4){
  2130. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  2131. } else {
  2132. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  2133. }
  2134. fixpanepersist();
  2135. }
  2136. function fixpanepersist(){ // Check box for persistence preference
  2137. var chk = document.getElementById("chkmpopen");
  2138. if (mpopen.substr(0,1) == "Y"){
  2139. chk.setAttribute("checked","checked");
  2140. chk.checked = true;
  2141. } else {
  2142. chk.removeAttribute("checked");
  2143. chk.checked = false;
  2144. }
  2145. }
  2146. async function updt1click(e){ // Store setting for 1-click preferences
  2147. var chk = e.target;
  2148. if (chk.id == "chk1click" || chk.id == "chk1clickbf"){
  2149. if (chk.checked){
  2150. pref1click = "Y" + pref1click.substr(1,2);
  2151. } else {
  2152. pref1click = "N" + pref1click.substr(1,2);
  2153. }
  2154. } else {
  2155. if (chk.checked){
  2156. pref1click = pref1click.substr(0,2) + "Y";
  2157. } else {
  2158. pref1click = pref1click.substr(0,2) + "N";
  2159. }
  2160. }
  2161. ghhPrefO.oneclick[0] = pref1click;
  2162. if (!GM4){
  2163. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  2164. } else {
  2165. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  2166. }
  2167. e.stopPropagation();
  2168. fix1clickstyle();
  2169. }
  2170. function fix1clickstyle(){ // Check boxes for one-click preferences
  2171. var chkMP = document.getElementById("chk1click");
  2172. var chkBF = document.getElementById("chk1clickbf");
  2173. if (pref1click.substr(0,1) == "Y"){
  2174. chkMP.setAttribute("checked","checked");
  2175. chkMP.checked = true;
  2176. if (chkBF){
  2177. chkBF.setAttribute("checked","checked");
  2178. chkBF.checked = true;
  2179. }
  2180. } else {
  2181. chkMP.removeAttribute("checked");
  2182. chkMP.checked = false;
  2183. if (chkBF){
  2184. chkBF.removeAttribute("checked");
  2185. chkBF.checked = false;
  2186. }
  2187. }
  2188. var chk = document.getElementById("chk1pban");
  2189. if (pref1click.substr(2,1) == "Y"){
  2190. chk.setAttribute("checked","checked");
  2191. chk.checked = true;
  2192. } else {
  2193. chk.removeAttribute("checked");
  2194. chk.checked = false;
  2195. }
  2196. }
  2197. async function updtBeta(e){ // Store setting for runbeta preference
  2198. var chk = e.target;
  2199. if (chk.checked){
  2200. betatest = "Y";
  2201. } else {
  2202. betatest = "N";
  2203. }
  2204. ghhPrefO.runbeta[0] = betatest;
  2205. if (!GM4){
  2206. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO));
  2207. } else {
  2208. await GM.setValue("ghhprefs", JSON.stringify(ghhPrefO));
  2209. }
  2210. fixBeta();
  2211. }
  2212. function fixBeta(){ // Check box for runbeta preference
  2213. var chk = document.getElementById("chkbeta");
  2214. if (betatest == "Y"){
  2215. chk.setAttribute("checked","checked");
  2216. chk.checked = true;
  2217. } else {
  2218. chk.removeAttribute("checked");
  2219. chk.checked = false;
  2220. }
  2221. }
  2222. async function chgcaption(e){ // Store button caption changes (but do not immediately refresh)
  2223. var btn, key, input;
  2224. btn = e.target;
  2225. key = e.target.getAttribute("key");
  2226. e.target.blur();
  2227. input = prompt(txts[key][1], txts[key][0]);
  2228. if (!input) return;
  2229. if (input.length > 0 && input != txts[key][0]){
  2230. txts[key][0] = input.replace(/\"/g,"''");
  2231. btn.appendChild(document.createTextNode(txts[key][0]));
  2232. btn.removeChild(btn.firstChild);
  2233. if (!GM4){
  2234. GM_setValue("textstrings", JSON.stringify(txts));
  2235. } else {
  2236. await GM.setValue("textstrings", JSON.stringify(txts));
  2237. }
  2238. }
  2239. }
  2240. async function resetTextStrings(e){ // Reset buttons captions to defaults
  2241. if (confirm("Restore default button captions?")){
  2242. txts = defaultTxts;
  2243. if (!GM4){
  2244. GM_setValue("textstrings", JSON.stringify(txts));
  2245. } else {
  2246. await GM.setValue("textstrings", JSON.stringify(txts));
  2247. }
  2248. alert("Please reload to see the changes.");
  2249. e.target.blur();
  2250. }
  2251. }
  2252. async function exportlist(e){ // Display and populate export form, clean up from any prior use
  2253. if (!document.getElementById("ghhexport")) insertExportForm();
  2254. var expDiv = document.getElementById("ghhexport");
  2255. document.getElementById("ghheximhead").innerHTML = "导出屏蔽列表";
  2256. document.getElementById("ghheximinfo1").innerHTML = "这里显示当前的屏蔽列表。 " +
  2257. "<button type=\"button\" id=\"expgotopreimp\" style=\"display:none\">这里显示旧的屏蔽列表(最后一次导入之前)</button><br /><br />" +
  2258. "左侧列表显示的是原始格式。保存此列表,您可以保留常规屏蔽/永久屏蔽的设置。" +
  2259. "<br /><br />右边是一个简单的域名列表。这样可以很方便的和他人共享。";
  2260. if (!GM4){
  2261. var currlist = GM_getValue("hideyhosts");
  2262. } else {
  2263. currlist = await GM.getValue("hideyhosts");
  2264. }
  2265. document.getElementById("ghhtaleft").value = currlist;
  2266. var domList = currlist.substr(1).replace(/:[tp]\|/g, "\n");
  2267. document.getElementById("ghhtaright").value = domList.replace(/\n*$/, "");
  2268. if (!GM4){
  2269. var preimpolist = GM_getValue("hideyback", "");
  2270. } else {
  2271. preimpolist = await GM.getValue("hideyback", "");
  2272. }
  2273. if (preimpolist.length > 0){
  2274. document.getElementById("expgotopreimp").addEventListener("click",exportoldlist,true);
  2275. document.getElementById("expgotopreimp").style.display = "";
  2276. }
  2277. document.getElementById("ghhleftcontrols").style.display = "none";
  2278. document.getElementById("ghhrightcontrols").style.display = "none";
  2279. document.getElementById("ghhtbldiv").style.display = "none";
  2280. if (document.getElementById("ghhtaright").style.display == "none") document.getElementById("ghhtaright").style.display = "";
  2281. expDiv.style.display = "block";
  2282. e.target.blur();
  2283. }
  2284. function insertExportForm(){
  2285. var dNew, btn, par, ta;
  2286. dNew = document.createElement("div");
  2287. dNew.id = "ghhexport";
  2288. dNew.className = "ghhpane";
  2289. dNew.setAttribute("style","position:fixed;top:10px;left:5%;width:90%;z-index:10000;background:#ddd;padding:1em;font-size:1.25em;display:none;max-height:90vh;overflow-y:auto;");
  2290. dNew.innerHTML = '<button id="exportclose" type="button" style="float: right; margin: 0 0 4px 4px;" class="ghhider">Close</button>' +
  2291. '<p style="margin-top:0; font-weight: bold;" id="ghheximhead"></p>' +
  2292. '<p id="ghheximinfo1"></p>' +
  2293. '<div id="ghhleft" style="width:49%;float:left"><textarea id="ghhtaleft" ' +
  2294. 'spellcheck="false" style="width:100%;height:calc(90vh - 300px);overflow-y:scroll"></textarea>' +
  2295. '<div id="ghhleftcontrols" style="clear:left;display:none"><p><button type="button" id="ghhexp1">Parse List for Import</button></p></div></div>' +
  2296. '<div id="ghhright" style="width:49%;float:right"><textarea id="ghhtaright" ' +
  2297. 'spellcheck="false" style="width:100%;height:calc(90vh - 300px);overflow-y:scroll"></textarea>' +
  2298. '<div id="ghhtbldiv" style="height:calc(90vh - 300px);overflow-y:scroll;overflow-x:scroll;background:#fff;padding:4px 0 0 4px;border:1px solid #aac;margin-top:1px;display:none"></div> ' +
  2299. '<div id="ghhrightcontrols" style="clear:right;display:none"><p id="impradios">Please review the above list for accuracy. If correct, add domains to: <br>' +
  2300. '<label><input type="radio" name="impbtype" value="asis">&nbsp;the list specified under Block Type</label> <br />' +
  2301. '<label><input type="radio" name="impbtype" value="t">&nbsp;the regular block list</label> <br />' +
  2302. '<label><input type="radio" name="impbtype" value="p">&nbsp;the Perma-ban list</label> &nbsp; ' +
  2303. '<button type="button" id="ghhexp2">Import</button> &nbsp; <span style="float:right; font-style:italic; opacity:0.8;">Replace entire blocklist:&nbsp;<input type="checkbox" id="chkimporepl"></span></p></div></div>';
  2304. document.body.appendChild(dNew);
  2305. document.getElementById('exportclose').addEventListener('click', function(){document.getElementById('ghhexport').style.display = 'none';}, true);
  2306. }
  2307. function importlist(e){ // Display import form, clean up from any prior use
  2308. if (!document.getElementById("ghhexport")) insertExportForm();
  2309. var expDiv = document.getElementById("ghhexport");
  2310. document.getElementById("ghheximhead").innerHTML = 'Import Block List';
  2311. document.getElementById("ghheximinfo1").innerHTML = "<strong>As a precaution in case something goes wrong, please use the <button type=\"button\" id=\"impgotoexp\">Export</button> " +
  2312. "feature to copy and save your current list as a backup.</strong> <br /><br />" +
  2313. "To begin, paste your list into the left box below. Then click the Parse List for Import button. This script can import a list in its own native format, or a plain list of domains with a separate domain on each line, or " +
  2314. "separated by spaces. (It also converts the Noise Reduction for Google and Google Domain Blocker formats.)";
  2315. document.getElementById("ghhtaleft").value = "";
  2316. document.getElementById("ghhleftcontrols").style.display = "";
  2317. document.getElementById("ghhrightcontrols").style.display = "none";
  2318. document.getElementById("ghhexp1").addEventListener("click",parseList,true);
  2319. document.getElementById("impgotoexp").addEventListener("click",exportlist,true);
  2320. document.getElementById("ghhtaright").style.display = "none";
  2321. document.getElementById("ghhtbldiv").style.display = "none";
  2322. document.getElementById("chkimporepl").checked = false;
  2323. expDiv.style.display = "block";
  2324. e.target.blur();
  2325. }
  2326. function parseList(e){ // Parse putative domain list and redisplay cleaned up
  2327. var txt, sites = [], bHasTypes = 0, i, tbod, thd, rasis, lbpos, rbpos;
  2328. txt = document.getElementById("ghhtaleft").value;
  2329. if (txt.length < 4){
  2330. alert("Block list too short!");
  2331. return;
  2332. }
  2333. document.getElementById("ghhtbldiv").innerHTML = "";
  2334. // clean up/convert domain list to pipe-delimited
  2335. txt = txt.replace(/(http|https):/g, "");
  2336. txt = txt.replace(/(,|\/|;)/g, "|");
  2337. txt = txt.replace(/\s+/g, "|");
  2338. txt = txt.replace(/\|+/g, "|");
  2339. txt = txt.replace(/[\<\>"'=#\!\u2018\u2019\(\)\{\}]/g, "");
  2340. // strip regex
  2341. txt = txt.replace(/(\+|\*|\$|\\)/g, "");
  2342. while (txt.indexOf("[") > -1 && txt.indexOf("]") > -1){
  2343. lbpos = txt.indexOf("[");
  2344. rbpos = txt.indexOf("]");
  2345. if (lbpos > 0 && rbpos + 1 < txt.length) txt = txt.substring(0,lbpos) + txt.substring(rbpos+1);
  2346. else {
  2347. if (lbpos == 0 && rbpos + 1 < txt.length) txt = txt.substring(rbpos+1);
  2348. else break; // for some reason, entire list is bracketed??
  2349. }
  2350. }
  2351. if (txt.indexOf(":") > -1) bHasTypes = 1;
  2352. sites = txt.split("|");
  2353. for (i=0; i<sites.length; i++){
  2354. if (sites[i].length > 1){
  2355. if (sites[i].indexOf(".") == 0) sites[i] = sites[i].substr(1);
  2356. if (sites[i].indexOf("?") > -1) sites[i] = sites[i].substr(0,sites[i].indexOf("?"));
  2357. if (bHasTypes == 1){
  2358. if (sites[i].indexOf(":t") == sites[i].length - 2 || sites[i].indexOf(":p") == sites[i].length - 2){
  2359. sites[i] = "<tr><td>" + sites[i].replace(":t","</td><td>regular").replace(":p","</td><td>Perma-ban") + "</td></tr>";
  2360. } else {
  2361. if (sites[i].indexOf(":") > -1) sites[i] = sites[i].substr(0, sites[i].indexOf(":"));
  2362. sites[i] = "<tr><td>" + sites[i] + "</td><td>(unspecified)</td></tr>";
  2363. }
  2364. } else { // Plain list
  2365. sites[i] = "<tr><td>" + sites[i] + "</td></tr>";
  2366. }
  2367. }
  2368. }
  2369. tbod = "<tbody>\n" + sites.join("\n") + "</tbody>";
  2370. if (sites.length == 0){
  2371. alert("Unable to parse the list, sorry."); return;
  2372. }
  2373. if (bHasTypes == 1) thd = "<thead><tr><th>Domain</th><th>Block Type</th></tr></thead>";
  2374. else thd = "<thead><tr><th>Domain</th></tr></thead>";
  2375. document.getElementById("ghhtbldiv").innerHTML = "<table cellspacing=\"0\" class=\"ghhtbl\" id=\"ghhparsed\">" + thd + tbod + "</table>";
  2376. document.getElementById("ghhtbldiv").style.display = "";
  2377. rasis = document.getElementById("ghhrightcontrols").querySelectorAll("input[value='asis']")[0];
  2378. if (bHasTypes == 1){
  2379. if (rasis.hasAttribute("disabled")) rasis.removeAttribute("disabled");
  2380. rasis.checked = true;
  2381. rasis.parentNode.style.color = "";
  2382. } else {
  2383. rasis.setAttribute("disabled","disabled");
  2384. rasis.parentNode.style.color = "rgb(172, 168, 153)";
  2385. document.getElementById("ghhrightcontrols").querySelectorAll("input[value='t']")[0].checked = true;
  2386. }
  2387. document.getElementById("ghhrightcontrols").style.display = "block";
  2388. document.getElementById("ghhexp2").addEventListener("click",doImport,true);
  2389. e.target.blur();
  2390. }
  2391. async function doImport(e){ // Add sites from cleaned up domain list to script block lists
  2392. var tbl, rads, i, typeRule, rows, dom, newDoms = "";
  2393. tbl = document.getElementById("ghhparsed");
  2394. if (!tbl){
  2395. alert("Unable to locate table of parsed domains!");
  2396. return;
  2397. }
  2398. if (tbl.parentNode.style.display == "none"){
  2399. alert("Please start the import process again!");
  2400. return;
  2401. }
  2402. rads = document.getElementById("ghhrightcontrols").querySelectorAll("input[type='radio']");
  2403. for (i=0; i<rads.length; i++){
  2404. if (rads[i].checked){
  2405. typeRule = rads[i].value;
  2406. break;
  2407. }
  2408. }
  2409. rows = tbl.getElementsByTagName("tbody")[0].getElementsByTagName("tr");
  2410. for (i=0; i<rows.length; i++){
  2411. dom = rows[i].children[0].textContent;
  2412. if (dom.lastIndexOf(".") < dom.length-2 && dom.indexOf(".") > 0){
  2413. switch (typeRule){
  2414. case "asis":
  2415. if (rows[i].children[1].textContent == "Perma-ban") newDoms += dom + ":p|";
  2416. else newDoms += dom + ":t|";
  2417. break;
  2418. default:
  2419. newDoms += dom + ":" + typeRule + "|";
  2420. }
  2421. rows[i].style.backgroundColor = "#ff0";
  2422. } else {
  2423. rows[i].style.backgroundColor = "#f00";
  2424. }
  2425. }
  2426. if (newDoms != ""){
  2427. // Back up current block list
  2428. if (!GM4){
  2429. GM_setValue("hideyback", blist);
  2430. } else {
  2431. await GM.setValue("hideyback", blist);
  2432. }
  2433. if (document.getElementById("chkimporepl").checked == true){
  2434. if (confirm("Delete current block list and replace it with domains you are importing? (To add to the current block list, click Cancel.)")) {
  2435. blist = "";
  2436. }
  2437. }
  2438. if (blist == "") blist = "|" + newDoms;
  2439. else blist += newDoms;
  2440. // Persist updated block list
  2441. if (!GM4){
  2442. GM_setValue("hideyhosts", blist);
  2443. } else {
  2444. await GM.setValue("hideyhosts", blist);
  2445. }
  2446. if(document.getElementById("ghhmngform").style.display=="block") refreshSiteList();
  2447. hidehits(null,true);
  2448. }
  2449. alert("Import of yellow-highlighted domains completed. Please check the Management Pane to " +
  2450. "view, sort, and/or de-duplicate your imported domains.");
  2451. }
  2452. async function exportoldlist(e){ // Display and populate export form with pre-import list
  2453. if (!document.getElementById("ghhexport")) insertExportForm();
  2454. var expDiv = document.getElementById("ghhexport");
  2455. document.getElementById("ghheximhead").innerHTML = "Export Old (Pre-Import) Block List";
  2456. document.getElementById("ghheximinfo1").innerHTML = "These boxes display your old block list from before the last import. " +
  2457. "<button type=\"button\" id=\"expgotoblist\">Show current block list</button><br /><br />" +
  2458. "On the left, you have the list in its native format. By saving this format, you can preserve your regular/Perma-ban " +
  2459. "block decisions. <br /><br />On the right, you have a simple list of domains. " +
  2460. "This would be a good format for sharing your list with others.";
  2461. if (!GM4){
  2462. var preimpolist = GM_getValue("hideyback", "");
  2463. } else {
  2464. preimpolist = await GM.getValue("hideyback", "");
  2465. }
  2466. document.getElementById("ghhtaleft").value = preimpolist;
  2467. var domList = preimpolist.substr(1).replace(/:[tp]\|/g, "\n");
  2468. document.getElementById("ghhtaright").value = domList.replace(/\n*$/, "");
  2469. document.getElementById("expgotoblist").addEventListener("click",exportlist,true);
  2470. document.getElementById("ghhleftcontrols").style.display = "none";
  2471. document.getElementById("ghhrightcontrols").style.display = "none";
  2472. document.getElementById("ghhtbldiv").style.display = "none";
  2473. if (document.getElementById("ghhtaright").style.display == "none") document.getElementById("ghhtaright").style.display = "";
  2474. expDiv.style.display = "block";
  2475. e.target.blur();
  2476. }
  2477. async function sortlist(e){ // Alpha-sort block list
  2478. if (listchgs > 0) {
  2479. if (confirm("You have unsaved changes to your lists. Save changes and sort, or cancel sorting?")){
  2480. saveedits(null);
  2481. } else {
  2482. return;
  2483. }
  2484. }
  2485. if (blist.substr(0,1) != "|") blist = "|" + blist;
  2486. var sarray = blist.substr(1,blist.length-2).split("|");
  2487. sarray.sort();
  2488. // Persist sorted list
  2489. if (!GM4){
  2490. GM_setValue("hideyhosts", "|" + sarray.join("|") + "|");
  2491. blist = GM_getValue("hideyhosts");
  2492. } else {
  2493. await GM.setValue("hideyhosts", "|" + sarray.join("|") + "|");
  2494. blist = await GM.getValue("hideyhosts");
  2495. }
  2496. refreshSiteList();
  2497. if (e) e.target.blur();
  2498. }
  2499. async function dedup(e){ // De-duplicate block lists
  2500. if (!confirm("If you block example.com, you don't also need to block www.example.com. Remove unnecessary domains from the block list?")) return;
  2501. var barray, i, j, iadd, smain, stest, sremd = "", sques = "";
  2502. if (blist.substr(0,1) != "|") blist = "|" + blist;
  2503. barray = blist.substr(1,blist.length-2).split("|");
  2504. for (i=0; i<barray.length; i++){
  2505. if (barray[i].indexOf(":t") > -1){
  2506. barray[i] = barray[i].substr(0,barray[i].indexOf(":")).split(".").reverse().join(".") + "!t";
  2507. } else {
  2508. if (barray[i].indexOf(":p") > -1){
  2509. barray[i] = barray[i].substr(0,barray[i].indexOf(":")).split(".").reverse().join(".") + "!p";
  2510. } else {
  2511. barray[i] = barray[i].split(".").reverse().join(".") + "!t";
  2512. }
  2513. }
  2514. }
  2515. barray.sort();
  2516. for (i=0; i<barray.length-1; i++){
  2517. iadd = 0;
  2518. for (j=1; j<barray.length-i; j++){
  2519. if (barray[i+j].indexOf(barray[i].substr(0,barray[i].length-2)) != 0) break;
  2520. smain = barray[i].substr(0,barray[i].length-2).split(".").reverse().join(".");
  2521. stest = barray[i+j].substr(0,barray[i+j].length-2).split(".").reverse().join(".");
  2522. if (stest.indexOf(smain) < 0) break;
  2523. if (barray[i].substr(barray[i].length-1) == barray[i+j].substr(barray[i+j].length-1)){
  2524. blist = blist.replace(stest + ":" + barray[i+j].substr(barray[i+j].length-1) + "|", "");
  2525. sremd += "|Removed: " + stest + "; Covered by: " + smain;
  2526. iadd += 1;
  2527. } else {
  2528. stest += (barray[i+j].substr(barray[i+j].length-1) == "t") ? " (regular)" : " (permaban)";
  2529. smain += (barray[i].substr(barray[i].length-1) == "t") ? " (regular)" : " (permaban)";
  2530. sques += "|Didn't remove " + stest + " due to block type difference from " + smain;
  2531. }
  2532. }
  2533. i += iadd;
  2534. }
  2535. if (!GM4){
  2536. GM_setValue("hideyhosts", blist);
  2537. } else {
  2538. await GM.setValue("hideyhosts", blist);
  2539. }
  2540. refreshSiteList();
  2541. // ToDo: Alerts are temporary; nicer display "some day"
  2542. if (sremd != "") alert(sremd.substr(1).replace(/\|/g,"\n"));
  2543. if (sques != "") alert(sques.substr(1).replace(/\|/g,"\n"));
  2544. if (sremd == "" && sques == "") alert("No unnecessary domains found.");
  2545. if (e) e.target.blur();
  2546. }
  2547. async function unwww(e){ // Remove www from beginnings of domains
  2548. if (!confirm("You can block other subdomains on example.com by removing www from the beginning (e.g., blog.example.com). Update the block list?")) return;
  2549. if (blist.substr(0,1) != "|") blist = "|" + blist;
  2550. blist = blist.replace(/\|www\./g, "\|");
  2551. if (!GM4){
  2552. GM_setValue("hideyhosts", blist);
  2553. } else {
  2554. await GM.setValue("hideyhosts", blist);
  2555. }
  2556. refreshSiteList();
  2557. if (e) e.target.blur();
  2558. }
  2559. // Misc functions
  2560. function convertFormat(){
  2561. if (GM4) return; //Legacy only
  2562. if (blist.substr(0,1) != "|") blist = "|" + blist;
  2563. blist = "|" + blist.slice(1).replace(/\|/g,":t|");
  2564. GM_setValue("hideyhosts", blist);
  2565. }
  2566. function convertTxts(strTxts){
  2567. var oldTxts;
  2568. oldTxts = JSON.parse(strTxts);
  2569. txts = defaultTxts;
  2570. if (GM4) return; //Legacy only
  2571. if (txtsPref.indexOf(":[") == -1){ // 0.8x to 0.9x+
  2572. txts.block[0] = oldTxts.block;
  2573. txts.unblock[0] = oldTxts.unblock;
  2574. txts.pban[0] = oldTxts.pban;
  2575. txts.okbtn[0] = oldTxts.okbtn;
  2576. txts.cancelbtn[0] = oldTxts.cancelbtn;
  2577. txts.savebtn[0] = oldTxts.savebtn;
  2578. txts.closebtn[0] = oldTxts.closebtn;
  2579. } else { // 0.9x to 1.1x+
  2580. txts.block[0] = oldTxts.block[0];
  2581. txts.unblock[0] = oldTxts.unblock[0];
  2582. txts.pban[0] = oldTxts.pban[0];
  2583. txts.okbtn[0] = oldTxts.okbtn[0];
  2584. txts.cancelbtn[0] = oldTxts.cancelbtn[0];
  2585. txts.savebtn[0] = oldTxts.savebtn[0];
  2586. txts.closebtn[0] = oldTxts.closebtn[0];
  2587. if (oldTxts.okPbtn) txts.okPbtn[0] = oldTxts.okPbtn[0];
  2588. if (oldTxts.cancelMbtn) txts.cancelMbtn[0] = oldTxts.cancelMbtn[0];
  2589. if (oldTxts.mngbtn) txts.mngbtn[0] = oldTxts.mngbtn[0];
  2590. if (txts.savebtn[0]=="Save Changes") txts.savebtn[0]="Save Lists"; // v1.1
  2591. // 1.1 to 1.2+
  2592. if (oldTxts.eximbtn) txts.eximbtn[0] = oldTxts.eximbtn[0];
  2593. // 1.2 to 1.3+
  2594. if (oldTxts.utilbtn) txts.utilbtn[0] = oldTxts.utilbtn[0];
  2595. if (oldTxts.sortbtn) txts.sortbtn[0] = oldTxts.sortbtn[0];
  2596. if (oldTxts.unwwwbtn) txts.unwwwbtn[0] = oldTxts.unwwwbtn[0];
  2597. if (oldTxts.dedupbtn) txts.dedupbtn[0] = oldTxts.dedupbtn[0];
  2598. // 2.0.9+ (catch-up)
  2599. if (oldTxts.onetime) txts.onetime[0] = oldTxts.onetime[0];
  2600. if (oldTxts.shownotc) txts.shownotc[0] = oldTxts.shownotc[0];
  2601. if (oldTxts.hidenotc) txts.hidenotc[0] = oldTxts.hidenotc[0];
  2602. if (oldTxts.impobtn) txts.impobtn[0] = oldTxts.impobtn[0];
  2603. if (oldTxts.sharebtn) txts.sharebtn[0] = oldTxts.sharebtn[0];
  2604. }
  2605. GM_setValue("textstrings", JSON.stringify(txts)); // requires Fx 3.5+
  2606. }
  2607. function ghhkillevent(e){
  2608. if (e.currentTarget.nodeName == "BUTTON" || e.currentTarget.nodeName == "INPUT") return;
  2609. e.stopPropagation();
  2610. }
  2611. function toggleBlockHiders(str){
  2612. var s = document.getElementById("ghhStyleNoBlock");
  2613. if (str == "S"){
  2614. if (s) s.remove();
  2615. return;
  2616. }
  2617. if (str == "H"){
  2618. if (s) return;
  2619. s = document.createElement("style");
  2620. s.id = "ghhStyleNoBlock";
  2621. s.setAttribute("type", "text/css");
  2622. s.appendChild(document.createTextNode(".ghhb{display:none}"));
  2623. document.body.appendChild(s);
  2624. }
  2625. }
  2626. function refreshListeners(e){ // for AutoPager extension
  2627. var bbtns, bnotc, i, j;
  2628. if (!document.getElementById("navcnt")) return;
  2629. bbtns = document.getElementById("navcnt").querySelectorAll(".ghhb");
  2630. for (i=0;i<bbtns.length;i++){
  2631. bbtns[i].removeEventListener("click",showbfd,true);
  2632. bbtns[i].addEventListener("click",showbfd,true);
  2633. }
  2634. bnotc = document.getElementById("navcnt").querySelectorAll(".ghhd");
  2635. for (i=0;i<bnotc.length;i++){
  2636. bnotc[i].removeEventListener("click",reshow,true);
  2637. bnotc[i].addEventListener("click",reshow,true);
  2638. bbtns = bnotc[i].querySelectorAll("button.ghhider");
  2639. for (j=0;j<bbtns.length;j++){
  2640. if (bbtns[j].getAttribute("title")=="Unblock this site"){
  2641. bbtns[j].removeEventListener("click",unblock,true);
  2642. bbtns[j].addEventListener("click",unblock,true);
  2643. }
  2644. if (bbtns[j].getAttribute("title")=="Permanently hide this site"){
  2645. bbtns[j].removeEventListener("click",permban,true);
  2646. bbtns[j].addEventListener("click",permban,true);
  2647. }
  2648. if (bbtns[j].getAttribute("title")=="Re-hide this hit"){
  2649. bbtns[j].removeEventListener("click",rehide,true);
  2650. bbtns[j].addEventListener("click",rehide,true);
  2651. }
  2652. }
  2653. }
  2654. }
  2655. function convertPrefs(arrPrefs, allnew){
  2656. ghhPrefO = arrPrefs;
  2657. if (GM4) return; // Legacy only
  2658. if (allnew == "true"){ // 1.3.7 to 1.4.x
  2659. var tmp = GM_getValue("shownotc");
  2660. if (tmp){
  2661. if (tmp.length > 0) ghhPrefO.shownotc[0] = tmp;
  2662. GM_deleteValue("shownotc");
  2663. }
  2664. tmp = GM_getValue("mngpaneopen");
  2665. if (tmp){
  2666. if (tmp.length > 0) ghhPrefO.mngpaneopen[0] = tmp;
  2667. GM_deleteValue("mngpaneopen");
  2668. }
  2669. tmp = GM_getValue("mngbtnstyle");
  2670. if (tmp){if (tmp.length > 0){
  2671. if (tmp.indexOf("-")>-1) tmp = "both"; // default ancient pref
  2672. ghhPrefO.mngbtnstyle[0] = tmp;
  2673. GM_deleteValue("mngbtnstyle");
  2674. }}
  2675. tmp = GM_getValue("addtolistpos");
  2676. if (tmp){
  2677. if (tmp.length > 0) ghhPrefO.addtolistpos[0] = tmp;
  2678. GM_deleteValue("addtolistpos");
  2679. }
  2680. tmp = GM_getValue("aggressiveblock");
  2681. if (tmp){
  2682. if (tmp.length > 0) ghhPrefO.aggressiveblock[0] = tmp;
  2683. GM_deleteValue("aggressiveblock");
  2684. }
  2685. tmp = GM_getValue("usemutation");
  2686. if (tmp){
  2687. if (tmp.length > 0) ghhPrefO.usemutation[0] = tmp;
  2688. GM_deleteValue("usemutation");
  2689. }
  2690. } else {
  2691. if (ghhPrefs.indexOf("reserved1")>-1){
  2692. var oldPrefs = JSON.parse(ghhPrefs);
  2693. ghhPrefO.shownotc[0] = oldPrefs.shownotc[0];
  2694. ghhPrefO.mngpaneopen[0] = oldPrefs.mngpaneopen[0];
  2695. ghhPrefO.mngbtnstyle[0] = oldPrefs.mngbtnstyle[0];
  2696. ghhPrefO.addtolistpos[0] = oldPrefs.addtolistpos[0];
  2697. ghhPrefO.aggressiveblock[0] = oldPrefs.aggressiveblock[0];
  2698. ghhPrefO.usemutation[0] = oldPrefs.usemutation[0];
  2699. ghhPrefO.oneclick[0] = oldPrefs.oneclick[0];
  2700. }
  2701. }
  2702. GM_setValue("ghhprefs", JSON.stringify(ghhPrefO)); // requires Fx 3.5+
  2703. }
  2704. function togglebbtn(e){
  2705. var bbtn = e.currentTarget.querySelector('.ghhb');
  2706. if (bbtn){
  2707. if (e.type == "mouseover") bbtn.style.visibility = "";
  2708. else bbtn.style.visibility = "hidden";
  2709. }
  2710. }
  2711. function reQuery(e){
  2712. var ss, rads, i;
  2713. if (e){
  2714. if (e.target.id == "ghhbf5") ss = "+site:";
  2715. else ss = "+-site:";
  2716. rads = e.target.form.querySelectorAll('input[type="radio"]');
  2717. } else {
  2718. ss = "+-site:"; // ALT omit
  2719. rads = document.querySelector('#ghhblockform form').querySelectorAll('input[type="radio"]');
  2720. }
  2721. if (rads.length > 0){
  2722. for (i=0; i<rads.length; i++){
  2723. if(rads[i].checked){
  2724. ss += rads[i].nextElementSibling.textContent;
  2725. reQry(ss);
  2726. break;
  2727. }
  2728. }
  2729. } else console.log("LOG:reQuery fail: no rads");
  2730. }
  2731. function reQry(d){
  2732. if (!d) return;
  2733. var qsp = window.location.href.indexOf("?");
  2734. if (qsp < 0) return;
  2735. var q = window.location.href.substr(qsp+1);
  2736. if (d.substr(0,2) == "+-" && (q.indexOf(d+"%20")>-1 || q.indexOf(d+"&")>-1)) return; // try to block dups, may be overinclusive
  2737. var qa = q.split("&");
  2738. var has_q = false;
  2739. for (var j=qa.length-1; j>=0; j--){
  2740. if (qa[j].split("=")[0] == "q"){
  2741. qa[j] += d;
  2742. has_q = true;
  2743. break;
  2744. } else {
  2745. if (qa[j].indexOf("#q=") > -1){
  2746. qa[j] += d;
  2747. has_q = true;
  2748. break;
  2749. }
  2750. }
  2751. }
  2752. if (has_q) window.location.href = window.location.href.substr(0, window.location.href.indexOf("?")+1) + qa.join("&");
  2753. else console.log("LOG:Unable to add new search term to URL");
  2754. }
  2755. function toggleciteline(posit) {
  2756. var ghhbd_sty = document.getElementById("bbposciteline");
  2757. if (posit == "C"){
  2758. if (!ghhbd_sty){
  2759. ghhbd_sty = document.createElement("style");
  2760. ghhbd_sty.id = "bbposciteline";
  2761. ghhbd_sty.setAttribute("type", "text/css");
  2762. document.body.appendChild(ghhbd_sty);
  2763. }
  2764. // "inline" the action menu
  2765. ghhbd_sty.appendChild(document.createTextNode(".action-menu {vertical-align:baseline !important;} .action-menu .clickable-dropdown-arrow, .action-menu .ab_button, .action-menu > a {display:none !important;} .action-menu-panel, .action-menu-panel ul, .action-menu-panel ol, .action-menu-item {display:inline !important; visibility: visible !important; border:none !important; box-shadow:none !important; background-color:transparent !important; margin:0 !important; padding:0 !important; top:0 !important; height:auto !important; line-height:auto !important;} .action-menu-item a.fl, .action-menu-button {padding:0 0 0 6px !important; display:inline !important;} .action-menu-panel {position:static;} .action-menu-item a.fl:hover {text-decoration:underline !important;} .action-menu + .crc {margin-right: 9px !important;} .action-menu + .crc ._Bs {margin-left: 1px !important;}"));
  2766. // restyle the block button
  2767. ghhbd_sty.appendChild(document.createTextNode(".ghhb {border:none!important; text-decoration:none!important; font-size:1em!important; color:#333!important; padding:0!important; margin-left:8px!important;} .ghhb:hover {background:transparent!important; text-decoration:underline !important;}"));
  2768. } else { // remove citeline rules
  2769. if (ghhbd_sty){
  2770. while(ghhbd_sty.firstChild) ghhbd_sty.removeChild(ghhbd_sty.firstChild);
  2771. }
  2772. }
  2773. }
  2774. function openCustomStyleBar(e){
  2775. // Create fixed div with text input and buttons: Save, Test, Close
  2776. var csb = document.getElementById("ghhcsb");
  2777. if (csb){
  2778. csb.style.display = "block";
  2779. } else {
  2780. csb = document.createElement("div");
  2781. csb.id = "ghhcsb";
  2782. csb.setAttribute("style","position:fixed;bottom:0;left:0;z-index:750;width:100%;background-color:#afa;");
  2783. csb.innerHTML = "<form onsubmit=\"return false;\"><p style=\"margin:0.75em;\"><input id=\"ghhcsbrule\" type=\"text\" style=\"width:80%\"> " +
  2784. "<button type=\"button\" id=\"ghhcsb1\" title=\"Save and Apply\">Save</button> " +
  2785. "<button type=\"button\" id=\"ghhcsb2\" title=\"Test Current Rules\">Test</button> " +
  2786. "<button type=\"button\" id=\"ghhcsb3\" title=\"Close\">Close</button></p></form>";
  2787. document.body.appendChild(csb);
  2788. document.getElementById("ghhcsb1").addEventListener("click",saveCustomStyle,true);
  2789. document.getElementById("ghhcsb2").addEventListener("click",testCustomStyle,true);
  2790. document.getElementById("ghhcsb3").addEventListener("click",closeCustomStyleBar,true);
  2791. }
  2792. document.getElementById("ghhcsbrule").value = custSty;
  2793. }
  2794. async function saveCustomStyle(e){
  2795. // Update preferences and apply change to style#ghhbdcuststy
  2796. custSty = document.getElementById("ghhcsbrule").value;
  2797. if (!GM4){
  2798. GM_setValue("hiderStyles", custSty);
  2799. } else {
  2800. await GM.setValue("hiderStyles", custSty);
  2801. }
  2802. injectCustom();
  2803. document.getElementById("ghhbdcuststy").innerHTML = "";
  2804. document.getElementById("ghhbdcuststy").appendChild(document.createTextNode(custSty));
  2805. }
  2806. function testCustomStyle(e){
  2807. // Add/Edit style#ghhbdcuststy
  2808. injectCustom();
  2809. document.getElementById("ghhbdcuststy").innerHTML = "";
  2810. document.getElementById("ghhbdcuststy").appendChild(document.createTextNode(document.getElementById("ghhcsbrule").value));
  2811. }
  2812. function closeCustomStyleBar(e){
  2813. // Turn off display and reapply saved style to style#ghhbdcuststy
  2814. document.getElementById("ghhcsb").style.display = "none";
  2815. injectCustom();
  2816. document.getElementById("ghhbdcuststy").innerHTML = "";
  2817. document.getElementById("ghhbdcuststy").appendChild(document.createTextNode(custSty));
  2818. }
  2819. function removePBs(e){ // GoogleMonkeyR layout only
  2820. // Schedule Permaban removal (prevent simultaneous/conflicting runs)
  2821. var PBsBlanks = document.querySelectorAll("table#GTR li[blockhidden], table#GTR div.g[blockhidden], table#GTR td:empty");
  2822. if (PBsBlanks.length < 1) return;
  2823. if (t_pb) window.clearTimeout(t_pb);
  2824. t_pb = window.setTimeout(GMRshuffle, 100);
  2825. }
  2826. function GMRshuffle(){ // GoogleMonkeyR layout only
  2827. // Delete Permaban hits
  2828. var PBs = document.querySelectorAll("table#GTR li[blockhidden], table#GTR div.g[blockhidden]");
  2829. if (PBs.length > 0){
  2830. for (var i=PBs.length; i>0; i--) PBs[i-1].remove();
  2831. }
  2832. // Check entire table for empty cells and shuffle contents
  2833. var tbl, row, cell, empties;
  2834. tbl = document.getElementById("GTR");
  2835. for (row=0; row<tbl.rows.length; row++){
  2836. empties = tbl.rows[row].querySelectorAll("td:empty").length;
  2837. if (empties > 0 && empties < tbl.rows[row].cells.length){
  2838. for (cell=0; cell<tbl.rows[row].cells.length; cell++){
  2839. if (tbl.rows[row].cells[cell].childNodes.length == 0){
  2840. if (fillFromNext(tbl.rows[row].cells[cell]) == "STOP"){
  2841. if (t_pb) window.clearTimeout(t_pb);
  2842. t_pb = window.setTimeout(GMRshuffle, 1000);
  2843. return;
  2844. }
  2845. }
  2846. }
  2847. }
  2848. }
  2849. }
  2850. function fillFromNext(tgt){
  2851. var src = getNextCell(tgt, true);
  2852. if (!src) return "STOP";
  2853. while (src.childNodes.length > 0) tgt.appendChild(src.childNodes[0]);
  2854. }
  2855. function getNextCell(aCell, blnNonEmpty){
  2856. var startcell = aCell;
  2857. var retcell;
  2858. var i=0;
  2859. while (i<1000) {
  2860. if (startcell.nextElementSibling){ // not the last cell in the row
  2861. retcell = startcell.nextElementSibling;
  2862. } else {
  2863. if (startcell.parentNode.nextElementSibling){ // last cell in row and there's another row
  2864. retcell = startcell.parentNode.nextElementSibling.cells[0];
  2865. } else {
  2866. return null; // end of table
  2867. }
  2868. }
  2869. if (!retcell){
  2870. return null; // corrupted table structure
  2871. }
  2872. if (blnNonEmpty){
  2873. if (retcell.querySelector("li")){
  2874. return retcell;
  2875. } else {
  2876. startcell = retcell;
  2877. }
  2878. } else {
  2879. return retcell;
  2880. }
  2881. i++;
  2882. }
  2883. }
  2884. // "Add All" feature 2.0.9
  2885. async function addAllNow(e){
  2886. var unb = document.querySelectorAll('[ghhresult="unset"][ghhhost]'), dom = '', pdom = '', domlist = '';
  2887. for (var i=0; i<unb.length; i++){
  2888. // Compute domain based on user preference
  2889. dom = unb[i].getAttribute('ghhhost');
  2890. pdom = dom.substr(dom.indexOf('.') + 1);
  2891. if (pdom.indexOf('.') > -1 && patIPv4.test(dom) != true){
  2892. switch (bAggress){
  2893. case 'all':
  2894. dom = pdom; break;
  2895. case 'www':
  2896. if (dom.substr(0,3) == 'www') dom = pdom; break;
  2897. default:
  2898. // default to full domain
  2899. }
  2900. }
  2901. // Add dom to doms arrray (avoiding duplicates)
  2902. if (doms.includes(dom) !== true) doms.push(dom);
  2903. }
  2904. // Add new domains to the currently displayed block list
  2905. if (document.querySelector('button.ghhCurTab').id == 'ghhts3'){ // pban
  2906. domlist = doms.join(':p|') + ':p';
  2907. } else { // regular
  2908. domlist = doms.join(':t|') + ':t';
  2909. }
  2910. if (blist.substr(0,1) != '|') blist = '|' + blist;
  2911. if (addAt == 'end') blist += domlist + '|';
  2912. else blist = '|' + domlist + blist;
  2913. needupdate = true;
  2914. // Store the list
  2915. if (!GM4){
  2916. GM_setValue('hideyhosts', blist);
  2917. } else {
  2918. await GM.setValue('hideyhosts', blist);
  2919. }
  2920. // Apply the change to the results
  2921. hidehits(null,true);
  2922. if (document.getElementById('GTR')) removePBs();
  2923. // Update the dialog
  2924. if (addAt == 'sort') sortlist(null);
  2925. refreshSiteList();
  2926. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址