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

On chrome violentmonkey, the script fails with GM_addStyle being undefined. Thankfully, it's easy enough to fix.

GM_addStyle ends up being undefined because violent monkey implements GM_getValue and also because of JavaScript's function declaration hoisting. This bit of code is self-fulfilling in the sense that GM_addStyle will ALWAYS be undefined by virtue of the function being declared as it is:

var GM4 = (typeof GM_getValue === "undefined") ? true : false;
if (GM4){
  function GM_addStyle(txt){
    var s=document.createElement('style');
    s.appendChild(document.createTextNode(txt));
    document.body.appendChild(s);
  }
}

You can avoid function declaration hoisting by changing it to something like:

if (typeof GM_addStyle === "undefined"){
  GM_addStyle = function(txt){
    var s=document.createElement('style');
    s.appendChild(document.createTextNode(txt));
    document.body.appendChild(s);
  }
}

You can also get rid of the GM4 variable entirely (and all those if..else in the script) with those 2 function aliases for getValue & setValue:

if (typeof GM_getValue === "undefined"){
    GM_getValue=GM.getValue
}
if (typeof GM_setValue === "undefined"){
    GM_getValue=GM.getValue
}

Oops, didnt see the part where GM.getvalue and GM.setValue are async ... so forget the second part

Thanks. I don't know how I missed that. I found it easier to stop using GM_addStyle() across the board than to figure out function hoisting. New version posted.