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

Block unwanted sites from your Google, DuckDuckGo, Startpage.com, Bing and Yahoo search results. v2.1.8 2020-12-13

目前为 2020-12-13 提交的版本。查看 最新版本

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