Google Hit Hider by Domain (Search Filter / Block Sites)

Block unwanted sites from your Google, DuckDuckGo, Startpage.com, Bing and Yahoo search results. v2.3.5 2025-03-21

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

QingJ © 2025

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