Advertisement
Guest User

Untitled

a guest
Jun 9th, 2025
13
0
4 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Google site: Tool (Site results / Exclude sites)
  3. // @author      Jefferson "jscher2000" Scher
  4. // @namespace   JeffersonScher
  5. // @copyright   Copyright 2025 Jefferson Scher
  6. // @license     BSD with restriction
  7. // @description Easily add site: or -site: to modify your current Google query. v1.5.5 2025-06-08
  8. // @include     http*://www.google.*/*
  9. // @include     http*://encrypted.google.*/*
  10. // @version     1.5.5
  11. // @grant       GM_getValue
  12. // @grant       GM_setValue
  13. // @grant       GM_registerMenuCommand
  14. // @grant       GM.getValue
  15. // @grant       GM.setValue
  16. // @resource    mycon http://www.jeffersonscher.com/gm/src/gfrk-GsT-ver155.png
  17. // @downloadURL https://update.greasyfork.org/scripts/1679/Google%20site%3A%20Tool%20%28Site%20results%20%20Exclude%20sites%29.user.js
  18. // @updateURL https://update.greasyfork.org/scripts/1679/Google%20site%3A%20Tool%20%28Site%20results%20%20Exclude%20sites%29.meta.js
  19. // ==/UserScript==
  20. // DISCLAIMER:     Use at your own risk. Functionality and harmlessness cannot be guaranteed.
  21. var script_about = "https://greasyfork.org/scripts/1679-google-site-tool-site-results-exclude-sites";
  22. /*
  23. Copyright (c) 2025 Jefferson Scher. All rights reserved.
  24.  
  25. 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:
  26.  
  27. 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  28.  
  29. 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.
  30.  
  31. 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.
  32.  
  33. RESTRICTION: USE WITH ANY @include or @match THAT COVERS FACEBOOK.COM IS PROHIBITED AND UNLICENSED.
  34.  
  35. 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.
  36. */
  37. var gst_sty = document.createElement("style");
  38. gst_sty.setAttribute("type", "text/css");
  39. gst_sty.appendChild(document.createTextNode(".ghhpane{position:absolute;color:#333;background-color:#fcfcfc;border:1px solid #ccc;" +
  40.     "border-radius:4px;padding:0.25em 1.5em;font-size:13px;display:none} .ghhd{position:relative;line-height:1.2em;cursor:pointer;} " +
  41.     "#gstSiteForm input[type='radio']{vertical-align:bottom;margin-top:5px;margin-bottom:1px} .gstRadios{line-height:1.2 !important;} " +
  42.     ".gstlinkbtn{border:1px solid #000;border-radius:3px;padding:2px 6px;text-decoration:none !important;cursor:pointer;color:#000;background-color:#d8d8d8;} " +
  43.     ".gstlinkbtn:hover{background-color:#f4f4f4;}"));
  44. document.body.appendChild(gst_sty);
  45. var defaultPrefs, gstPrefs, gstPrefO, seemorelink, stripany, MutOb, chgMon;
  46. gst_Setup();
  47.  
  48. async function gst_Setup(){
  49.   // Get preferences from browser
  50.   defaultPrefs = {
  51.     "seemore":["Y-N","Add See More Results links (Y|N), Open in a new window (Y|N)"],
  52.     "subdomain":["N","Strip leftmost subdomain (Y=all|N=www only)"],
  53.     "reserved2":["X","Y"]
  54.   };
  55.   if (typeof GM_setValue !== "undefined"){
  56.     gstPrefs = GM_getValue("gstPrefs");
  57.   } else { /* synchronous*/
  58.     if (typeof GM.setValue !== "undefined") gstPrefs = await GM.getValue("gstPrefs");
  59.   }
  60.   if (!gstPrefs || gstPrefs.length == 0){
  61.     gstPrefO = defaultPrefs;
  62.   } else {
  63.     if (gstPrefs.indexOf("reserved1") > -1){ // update with new preferences
  64.       gstPrefO = convertPrefs(defaultPrefs, gstPrefs);
  65.       if (typeof GM_setValue !== "undefined"){
  66.         GM_setValue("gstPrefs", JSON.stringify(gstPrefO));
  67.       } else { /* synchronous*/
  68.         if (typeof GM.setValue !== "undefined") await GM.setValue("gstPrefs", JSON.stringify(gstPrefO));
  69.       }
  70.     } else {
  71.       gstPrefO = JSON.parse(gstPrefs);
  72.     }
  73.   }
  74.   seemorelink = gstPrefO.seemore[0];
  75.   stripany = gstPrefO.subdomain[0];
  76.   // == == == Detect added nodes / attach MutationObserver == == ==
  77.   if (document.body){
  78.     // Add click events
  79.     gst_checkNode(document.body);
  80.     // Create form
  81.     if (!document.getElementById("gstSiteForm")) gst_addSiteForm();
  82.     // Watch for changes that could be new instant or AJAX search results
  83.     MutOb = (window.MutationObserver) ? window.MutationObserver : window.WebKitMutationObserver;
  84.     if (MutOb){
  85.       chgMon = new MutOb(function(mutationSet){
  86.         mutationSet.forEach(function(mutation){
  87.           for (var i=0; i<mutation.addedNodes.length; i++){
  88.             if (mutation.addedNodes[i].nodeType == 1){
  89.               gst_checkNode(mutation.addedNodes[i]);
  90.             }
  91.           }
  92.         });
  93.       });
  94.       // attach chgMon to document.body
  95.       var opts = {childList: true, subtree: true};
  96.       chgMon.observe(document.body, opts);
  97.     }
  98.   }
  99. }
  100.  
  101. function gst_checkNode(el){
  102.   if (el.nodeName == "LI" || (el.nodeName == "div" && el.className == "g")) var liels = [el];
  103.   else liels = el.querySelectorAll('li.g, div.g');
  104.   if (liels.length == 0) liels = el.querySelectorAll('#rso div:has(>a), #rso div span:has(>a)'); // v1.5.3
  105.   if (liels.length > 0){
  106.     var i, cites, j, cite, citetext, ael;
  107.     for (i=0; i<liels.length; i++){
  108.       //console.log(liels[i]);
  109.       cites = liels[i].querySelectorAll('cite');
  110.       for (j=0; j<cites.length; j++){
  111.         cite = cites[j];
  112.         if (window.getComputedStyle(cite).visibility != "hidden"){
  113.           citetext = cite.textContent.replace(//g, '/'); // version 1.4.2 - parse alternate cite format
  114.           if (!cite.hasAttribute("sitelistener")){
  115.             if (cite.parentNode.nodeName == "A"){
  116.               // TODO - this is for cites under bunches of news articles; need to exclude Google
  117.             } else {
  118.               ael = liels[i].querySelector('h3 a, .r > a'); // version 1.4.2 - update selector for cite-on-top layout
  119.               if (!ael) ael = liels[i].querySelector("a");
  120.               if (ael){
  121.                 if(ael.hasAttribute("href")){
  122.                   if (ael.getAttribute("href").indexOf("http")==0 || ael.getAttribute("href").indexOf("/interstitial")==0){
  123.                     cite.setAttribute("sitelistener", ael.getAttribute("href").substr(ael.getAttribute("href").indexOf("http")));
  124.                   } else {
  125.                     cite.setAttribute("sitelistener", citetext);
  126.                   }
  127.                 } else {
  128.                   cite.setAttribute("sitelistener", citetext);
  129.                 }
  130.               } else {
  131.                 cite.setAttribute("sitelistener", citetext);
  132.               }
  133.             }
  134.             if (cite.hasAttribute("sitelistener")){
  135.               cite.style.cursor = "pointer";
  136.               cite.setAttribute("title","Limit search to this site or exclude this site");
  137.               // *** version 1.4.0: un-embed the cite div from the result link ***
  138.               if (cite.parentNode.parentNode.nodeName == 'A'){
  139.                 // get div container of cite
  140.                 var citeparent = cite.parentNode;
  141.                 // re-position outside the link (updated for cite-above - 1.4.3)
  142.                 if (citeparent.nextElementSibling && citeparent.nextElementSibling.nodeName == 'BR'){
  143.                   citeparent.parentNode.parentNode.insertBefore(citeparent, citeparent.parentNode);
  144.                 } else {
  145.                   if (citeparent.parentNode.nextElementSibling) citeparent.parentNode.parentNode.insertBefore(citeparent, citeparent.parentNode.nextElementSibling);
  146.                   else citeparent.parentNode.parentNode.appendChild(citeparent);
  147.                 }
  148.                 // move the trailing br outside the link
  149.                 if (citeparent.previousElementSibling && citeparent.previousElementSibling.children[citeparent.previousElementSibling.children.length-1].nodeName == 'BR') citeparent.parentNode.insertBefore(citeparent.previousElementSibling.children[citeparent.previousElementSibling.children.length-1], citeparent);
  150.               } else {
  151.                 // *** version 1.5.2: move cite for the new site icon + title + cite layout ***
  152.                 if (cite == cite.closest('a').querySelector('h3 + div cite')){
  153.                   console.log('Move this guy!');
  154.                   cite.closest('a').parentNode.insertBefore(cite.closest('a h3 + div'), cite.closest('a'));
  155.                 }
  156.               }
  157.               // BEGIN PATCH for unclickable cite in link v1.5.4 5/28/2025
  158.                 var parentA = cite.closest('A, a');
  159.                 if (parentA) var parDiv = parentA.querySelector('h3 + br + div');
  160.                 if (parDiv){
  161.                   // Move cite above the link (visually, no change, hopefully)
  162.                   parDiv.parentNode.before(parDiv);
  163.                  
  164.                   // --- FIX START for misaligned title with file type results ---
  165.                   // For results with file types, the title (H3) can become misaligned.
  166.                   // This fix moves the title (H3) after its sibling BR tag to correct the layout.
  167.                   var titleH3 = parentA.querySelector('h3');
  168.                   if (titleH3) {
  169.                       var lineBreak = titleH3.nextElementSibling;
  170.                       // Ensure the line break exists and is a BR tag before attempting to move the title.
  171.                       if (lineBreak && lineBreak.tagName === 'BR') {
  172.                           lineBreak.after(titleH3);
  173.                       }
  174.                   }
  175.                   // --- FIX END ---
  176.  
  177.                   // Fix the position switching styles
  178.                   parDiv.style.transform = 'none';
  179.                   parDiv.parentNode.style.transform = 'none';
  180.                   if (titleH3) titleH3.style.transform = 'none';
  181.                   // Fix width issue 1.5.5 6/8/2025
  182.                   parDiv.style.width = 'calc(100% - 24px)';
  183.                 }
  184.               // END PATCH
  185.               cite.addEventListener("click", gst_showSiteForm, false);
  186.             }
  187.             if (seemorelink.split("-")[0] == "Y"){
  188.               var divmas = liels[i].querySelector("div.s div.mas");
  189.               if (divmas){
  190.                 divmas.style.marginLeft = "22px";
  191.                 var citehost = citetext;
  192.                 if (citehost.indexOf("http://") == 0) citehost = citehost.substr(7);
  193.                 if (citehost.indexOf("https://") == 0) citehost = citehost.substr(8);
  194.                 if (citehost.indexOf("ftp://") == 0) citehost = citehost.substr(6);
  195.                 if (citehost.indexOf(" ") > 0) citehost = citehost.substr(0, citehost.indexOf(" "));
  196.                 if (citehost.indexOf("/") > 0) citehost = citehost.substr(0, citehost.indexOf("/"));
  197.                 var locnew = gst_reQry("+site:"+citehost, false);
  198.                 if (locnew != "cancel"){
  199.                   var pnew = document.createElement("p");
  200.                   pnew.setAttribute("style", "margin:0.3em 0 0 0;");
  201.                   var linknew = document.createElement("a");
  202.                   linknew.innerHTML = "More results from " + citehost + " »";
  203.                   linknew.href = locnew;
  204.                   pnew.appendChild(linknew);
  205.                   divmas.appendChild(pnew);
  206.                   // v1.1.3 fix links where the URL bar isn't updated until the link is created
  207.                   linknew.setAttribute("citehost", citehost);
  208.                   linknew.addEventListener("mouseover", gst_refreshLink, false);
  209.                   // v1.1.4 add target attribute to open in a new window/tab
  210.                   if (seemorelink.split("-")[1] == "Y"){
  211.                     linknew.setAttribute("target", "_blank");
  212.                     linknew.innerHTML += "»";
  213.                   }
  214.                 }
  215.                 // v1.1.6 hide (duplicate) link Google adds under some results
  216.                 var googmore = divmas.querySelector("div.mas-sc-row");
  217.                 if (googmore) googmore.style.display = "none";
  218.               }
  219.             }
  220.           }
  221.         }
  222.       }
  223.     }
  224.   }
  225. }
  226.  
  227. // Functions relating to the siteForm
  228. function gst_addSiteForm(){
  229.   var sfd = document.createElement("div");
  230.   sfd.id = "gstSiteForm";
  231.   sfd.className = "ghhpane";
  232.   sfd.setAttribute("style","z-index:105;top:-1.15em;")
  233.   sfd.innerHTML = "<form onsubmit=\"return false;\"><p id=\"gstButtons\">" +
  234.     "<a id=\"gstsf1\" class=\"gstlinkbtn\" title=\"This site only\">  +  </a> " +
  235.     "<a id=\"gstsf2\" class=\"gstlinkbtn\" title=\"Exclude this site\">  -  </a> " +
  236.     "<a id=\"gstsf3\" class=\"gstlinkbtn\" title=\"Close pane\">  x  </a></p>" +
  237.     "<p id=\"gstRadios\"></p><p style=\"padding-top:3px;cursor:pointer;color:#00f\" id=\"gstOptionsLink\">Edit Script Options</p>" +
  238.     "<p id=\"gstOptions\" style=\"padding-top:3px;display:none\">Script Options:<br><label title=\"Show 'More results from' link after selected hits\"><input type=\"checkbox\" name=\"chkseemore\" id=\"chkseemore\"> Add " +
  239.     "'More results from' link</label><br>      <label title=\"Open in a new window or tab\"><input type=\"checkbox\" name=\"chksmtarget\" id=\"chksmtarget\"> Open in new window</label><br>" +
  240.     "<label title=\"List domain without leftmost subdomain\"><input type=\"checkbox\" name=\"chkstripany\" id=\"chkstripany\"> First option always omit leftmost subdomain</label></p>" +
  241.     "<p style=\"padding-top:3px\"><strong>Google site: Tool</strong> v1.5.5 (<a href=\"" + script_about + "\" target=\"_blank\">About</a>)<span style=\"font-size:0.8em;color:#aaa\">" +
  242.     "<br>Copyright © 2025 Jefferson Scher</span></p></form>";
  243.   document.body.appendChild(sfd);
  244.   fixseemore();
  245.   fixsubdomain();
  246.   document.getElementById("gstsf3").addEventListener("click",gstcloseform,false);
  247.   document.getElementById("gstRadios").addEventListener("click",gstUpdateLinks,false);
  248.   document.getElementById("gstOptionsLink").addEventListener("click",function(evt){document.getElementById('gstOptions').style.display='block';evt.target.style.display='none';},false);
  249.   document.getElementById("chkseemore").addEventListener("change",updtseemore,false);
  250.   document.getElementById("chksmtarget").addEventListener("change",updtseemore,false);
  251.   document.getElementById("chkstripany").addEventListener("change",updtsubdomain,false);
  252.   document.getElementById("gstSiteForm").addEventListener("click",ghhkillevent,false);
  253. }
  254. function gst_showSiteForm(e) {
  255.   var r1=window.getSelection().getRangeAt(0);
  256.   if (!r1.collapsed){ // Don't show dialog if user selected part of the cite (v1.0.0)
  257.     var r2=document.createRange();
  258.     r2.selectNode(e.currentTarget);
  259.     if (r2.compareBoundaryPoints(r2.END_TO_START, r1)<1 && r2.compareBoundaryPoints(r2.END_TO_END, r1)>-1) return;
  260.   }
  261.   e.preventDefault();
  262.   e.stopPropagation();
  263.   var citetxt, sitecomp, radp, path, k, z, sfrm, tdiv, lt;
  264.   if (!document.getElementById("gstSiteForm")) gst_addSiteForm();
  265.   // Build radios
  266.   citetxt = e.currentTarget.getAttribute("sitelistener");
  267.   if (citetxt.indexOf("http://") == 0) citetxt = citetxt.substr(7);
  268.   if (citetxt.indexOf("https://") == 0) citetxt = citetxt.substr(8);
  269.   if (citetxt.indexOf("ftp://") == 0) citetxt = citetxt.substr(6);
  270.   sitecomp = citetxt.split("/");
  271.   radp = document.getElementById("gstRadios");
  272.   radp.innerHTML = "";
  273.   for (k=0; k<sitecomp.length-1; k++){
  274.     // TODO: do not duplicate a site or -site parameters already in the query?
  275.     if (k == 0){ // check for removing leftmost subdomain
  276.       if (stripany == "Y"){ // try to remove anything
  277.         if (sitecomp[k].split(".").length > 2){
  278.           radp.innerHTML += "<label style=\"white-space:pre\"><input type=\"radio\" name=\"sitestr\" value=\"" + k + "w\" checked=\"checked\"> <span>" +
  279.             sitecomp[k].substr(sitecomp[k].indexOf(".") + 1) + "</span></label>"
  280.           radp.innerHTML += "<br><label style=\"white-space:pre\"><input type=\"radio\" name=\"sitestr\" value=\"" + k + "\"> <span>" +
  281.             sitecomp[k] + "</span></label>"
  282.         } else {
  283.           radp.innerHTML += "<label style=\"white-space:pre\"><input type=\"radio\" name=\"sitestr\" value=\"" + k + "\" checked=\"checked\"> <span>" +
  284.             sitecomp[k] + "</span></label>"
  285.         }
  286.       } else { // try to remove www only
  287.         if (sitecomp[k].substr(0, sitecomp[k].indexOf(".")).toLowerCase() == "www"){
  288.           radp.innerHTML += "<label style=\"white-space:pre\"><input type=\"radio\" name=\"sitestr\" value=\"" + k + "w\" checked=\"checked\"> <span>" +
  289.             sitecomp[k].substr(sitecomp[k].indexOf(".") + 1) + "</span></label>"
  290.           radp.innerHTML += "<br><label style=\"white-space:pre\"><input type=\"radio\" name=\"sitestr\" value=\"" + k + "\"> <span>" +
  291.             sitecomp[k] + "</span></label>"
  292.         } else {
  293.           radp.innerHTML += "<label style=\"white-space:pre\"><input type=\"radio\" name=\"sitestr\" value=\"" + k + "\" checked=\"checked\"> <span>" +
  294.             sitecomp[k] + "</span></label>"
  295.         }
  296.       }
  297.     } else {
  298.       if(sitecomp[k+1] != ""){
  299.         path = "";
  300.         for (z=0; z<k; z++){
  301.           path += sitecomp[z] + "/";
  302.         }
  303.         path += sitecomp[k];
  304.         radp.innerHTML += "<br><label style=\"white-space:pre\"><input type=\"radio\" name=\"sitestr\" value=\"" + k + "\"> <span>" +
  305.           path + "</span></label>"
  306.       }
  307.       if (k == 3) break; // let's not go overboard...
  308.     }
  309.   }
  310.   // Position form
  311.   sfrm = document.getElementById("gstSiteForm");
  312.   tdiv = document.getElementById("ghhtemp");
  313.   if (!tdiv){
  314.     tdiv = document.createElement("div");
  315.     tdiv.id = "ghhtemp";
  316.   }
  317.   lt = e.currentTarget.offsetLeft + 60;
  318.   tdiv.setAttribute("style", "position:relative;left:" + lt + "px;top:0;z-index:100;width:500px;");
  319.   var prnt = e.currentTarget.closest('#rso .g li, #rso .g, [data-async-context^="query:"] .g, #rso div:has(>a), #rso div span:has(>a)'); // v1.5.2 updated for autoload; 1.5.3 added selectors
  320.   if (prnt) prnt.insertBefore(tdiv, prnt.childNodes[0]);
  321.   else e.currentTarget.parentNode.appendChild(tdiv);
  322.   tdiv.appendChild(sfrm);
  323.   // Add link if user clicked part of the cite that's a link
  324.   if (e.target.nodeName == "A"){
  325.     var pnew = document.createElement("p");
  326.     pnew.id = "gstlink";
  327.     var anew = e.target.cloneNode(true);
  328.     pnew.appendChild(anew);
  329.     sfrm.insertBefore(pnew, sfrm.firstChild);
  330.   }
  331.   // Set up the + and - "buttons" (v1.5)
  332.   gstUpdateLinks();
  333.   // Show form
  334.   sfrm.style.display = "block";
  335.   document.getElementById("gstsf1").focus();
  336.   fixseemore();
  337.   return false;
  338. }
  339. function gstcloseform(e){
  340.   if (!e) return;
  341.   var sfrm = document.getElementById("gstSiteForm");
  342.   var tdiv = document.getElementById("ghhtemp");
  343.   sfrm.style.display = "none";
  344.   var plink = document.getElementById("gstlink");
  345.   if (plink) plink.parentNode.removeChild(plink);
  346.   document.body.appendChild(sfrm);
  347.   tdiv.parentNode.removeChild(tdiv);
  348. }
  349. // Misc functions
  350. function ghhkillevent(e){
  351.   if (e.target.nodeName.toLowerCase() == "button" || e.target.nodeName.toLowerCase() == "input") return;
  352.   e.stopPropagation();
  353. }
  354. function gstUpdateLinks(evt){ // v1.5
  355.     var rads = document.querySelectorAll('#gstRadios input[type="radio"]');
  356.     for (var i=0; i<rads.length; i++){
  357.         if(rads[i].checked){
  358.             document.getElementById("gstsf1").href = gst_reQry("+site:" + rads[i].nextElementSibling.textContent, false);
  359.             document.getElementById("gstsf2").href = gst_reQry("+-site:" + rads[i].nextElementSibling.textContent, false);
  360.             break;
  361.         }
  362.     }
  363. }
  364. function gst_reQry(d, go){
  365.   // compute new URL
  366.   if (!d) return;
  367.   var cancel = false;
  368.   var qa = window.location.href.substr(window.location.href.indexOf("?")+1).split("&");
  369.   var updated = false;
  370.   for (var j=qa.length-1; j>=0; j--){
  371.     if (updated == false){
  372.       if (qa[j].split("=")[0] == "q"){
  373.         if (qa[j].indexOf(d) > -1 || qa[j].indexOf(d.replace(":", "%3A")) > -1) cancel = true;
  374.         else var ipq = qa[j];
  375.         var hashpos = qa[j].indexOf('#'); // for auto-loaded results - v1.5.2
  376.         if (hashpos < 0) qa[j] += d;
  377.         else qa[j] = qa[j].substring(0, hashpos) + d + qa[j].substring(hashpos);
  378.         updated = true;
  379.         var substqry = qa[j];
  380.       } else {
  381.         if (qa[j].indexOf("#q=") > -1){
  382.           if (qa[j].indexOf(d) > -1 || qa[j].indexOf(d.replace(":", "%3A")) > -1) cancel = true;
  383.           else ipq = qa[j].substr(qa[j].indexOf("#q=")+1);
  384.           hashpos = qa[j].indexOf('#'); // for auto-loaded results - v1.5.2
  385.           if (hashpos < 0) qa[j] += d;
  386.           else qa[j] = qa[j].substring(0, hashpos) + d + qa[j].substring(hashpos);
  387.           updated = true;
  388.           substqry = qa[j].substr(qa[j].indexOf("#q=")+1);
  389.         }
  390.       }
  391.     } else {
  392.       if (qa[j].split("=")[0] == "q"){
  393.         if (go) qa[j] = ipq;
  394.         else qa[j] = substqry;
  395.       } else {
  396.         if (qa[j].indexOf("#q=") > -1){
  397.           if (go) qa[j] = qa[j].substr(0, qa[j].indexOf("#q=")+1) + ipq;
  398.           else qa[j] = qa[j].substr(0, qa[j].indexOf("#q=")+1) + substqry;
  399.         }
  400.       }
  401.     }
  402.   }
  403.   if (cancel != true) var locnew = window.location.href.substr(0, window.location.href.indexOf("?")+1) + qa.join("&");
  404.   else locnew = "cancel";
  405.   if (go) window.location.href = locnew;
  406.   else return locnew;
  407. }
  408. function updtseemore(e){ // Store settings for See More preference
  409.   var chk = e.target;
  410.   var smparts = seemorelink.split("-");
  411.   if (chk.checked){
  412.     if (chk.id == "chkseemore") smparts[0] = "Y";
  413.     if (chk.id == "chksmtarget"){
  414.       smparts[1] = "Y";
  415.       fixexistinglinks(true);
  416.     }
  417.   } else {
  418.     if (chk.id == "chkseemore") smparts[0] = "N";
  419.     if (chk.id == "chksmtarget"){
  420.       smparts[1] = "N";
  421.       fixexistinglinks(false);
  422.     }
  423.   }
  424.   seemorelink = smparts.join("-");
  425.   gstPrefO.seemore[0] = seemorelink;
  426.   if (typeof GM_setValue !== "undefined"){
  427.     GM_setValue("gstPrefs", JSON.stringify(gstPrefO));
  428.     fixseemore();
  429.   } else { /* asynchronous */
  430.     if (typeof GM.setValue !== "undefined") GM.setValue("gstPrefs", JSON.stringify(gstPrefO)).then(fixseemore());
  431.   }
  432. }
  433. function fixseemore(){ // Check boxes for See More preference
  434.   if (seemorelink.split("-").length == 1) seemorelink = seemorelink + "-N";
  435.   var chk = document.getElementById("chkseemore");
  436.   if (seemorelink.split("-")[0] == "Y"){
  437.     chk.setAttribute("checked","checked");
  438.     chk.checked = true;
  439.   } else {
  440.     chk.removeAttribute("checked");
  441.     chk.checked = false;
  442.   }
  443.   chk = document.getElementById("chksmtarget");
  444.   if (seemorelink.split("-")[1] == "Y"){
  445.     chk.setAttribute("checked","checked");
  446.     chk.checked = true;
  447.   } else {
  448.     chk.removeAttribute("checked");
  449.     chk.checked = false;
  450.   }
  451. }
  452. function fixexistinglinks(blnTargetBlank){
  453.   var seemores = document.querySelectorAll("a[citehost]");
  454.   for (var i=0; i<seemores.length; i++){
  455.     if (seemores[i].hasAttribute("target")){
  456.       seemores[i].removeAttribute("target");
  457.       seemores[i].innerHTML = seemores[i].innerHTML.substr(0, seemores[i].innerHTML.length-1); //»
  458.     }
  459.     if (blnTargetBlank){
  460.       seemores[i].setAttribute("target", "_blank");
  461.       seemores[i].innerHTML += "»";
  462.     }
  463.   }
  464. }
  465. function updtsubdomain(e){ // Store settings for subdomain stripping pref
  466.   var chk = e.target;
  467.   if (chk.checked){
  468.     stripany = "Y";
  469.   } else {
  470.     stripany = "N";
  471.   }
  472.   gstPrefO.subdomain[0] = stripany;
  473.   if (typeof GM_setValue !== "undefined"){
  474.     GM_setValue("gstPrefs", JSON.stringify(gstPrefO));
  475.     fixsubdomain();
  476.   } else { /* asynchronous */
  477.     if (typeof GM.setValue !== "undefined") GM.setValue("gstPrefs", JSON.stringify(gstPrefO)).then(fixsubdomain());
  478.   }
  479.   // TODO: Need to close and re-open dialog to regenerate domain list...
  480. }
  481. function fixsubdomain(){ // Check box for subdomain stripping pref
  482.   var chk = document.getElementById("chkstripany");
  483.   if (stripany == "Y"){
  484.     chk.setAttribute("checked","checked");
  485.     chk.checked = true;
  486.   } else {
  487.     chk.removeAttribute("checked");
  488.     chk.checked = false;
  489.   }
  490. }
  491. function gst_refreshLink(e){
  492.   if (e.target.nodeName != "A") return;
  493.   var locnew = gst_reQry("+site:"+e.target.getAttribute("citehost"), false);
  494.   if (locnew != "cancel") e.target.href = locnew;
  495. }
  496. function convertPrefs(arrPrefs, oldPrefs){
  497.   var gstPrefOtemp = arrPrefs;
  498.   var oldPrefsOtemp = JSON.parse(oldPrefs);
  499.   if (oldPrefs.indexOf("seemore")>-1) gstPrefOtemp.seemore[0] = oldPrefsOtemp.seemore[0];
  500.   if (oldPrefs.indexOf("subdomain")>-1) gstPrefOtemp.subdomain[0] = oldPrefsOtemp.subdomain[0];
  501.   return gstPrefOtemp;
  502. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement