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

Block unwanted sites from your Google, DuckDuckGo, Startpage.com, Bing and Yahoo search results. v2.0.4 2019-03-24

当前为 2019-03-25 提交的版本,查看 最新版本

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

QingJ © 2025

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