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.6 2019-05-08

当前为 2019-05-09 提交的版本,查看 最新版本

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

QingJ © 2025

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