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

Block unwanted sites from your Google, DuckDuckGo and Startpage.com search results. For Firefox+Greasemonkey or Chrome+Tampermonkey. v1.6.9 2015-09-13

当前为 2015-09-13 提交的版本,查看 最新版本

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

QingJ © 2025

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