Greasemonkey userscript to hide Google results by domain

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Greasemonkey userscript to hide Google results by domain

Post by jscher2000 »

Edit: There are updated versions of this attachment down the thread. Latest is v0.83 in Post 41873.

In the exceedingly popular thread Add-on to exclude domains from right-click?, I hypothesized a Greasemoney userscript that would hide selected hits in a search results page. I've created a version 0.1 of such a userscript. If you are a Greasemonkey user, why not give it a try?

Some general notes:

(1) Pale-colored buttons reading XX should appear next to the page title in your results. Click this button to add that domain to the blacklist. On the next reload, those hits should be suppressed as described in #2.
(2) Results for blacklisted domains are replaced with a button that lets you view the result if you want to. This is a one-time viewing; the domain still will be suppressed on the next page load.
(3) If your blacklist becomes messed up, you can edit or clear it in about:config (there is no other UI for managing the list).
(4) bigresource.com is blacklisted by default, but after you add one of your own, you can edit that out if you wish.

Although not getting unwanted hits in the first place is more efficient, this tool works on any Google results page regardless of how you got there. At least until they change it again.
google_hit_hider_user_js.zip
You do not have the required permissions to view the files attached to this post.
Last edited by jscher2000 on 05 Feb 2011, 17:22, edited 3 times in total.

User avatar
StuartR
Administrator
Posts: 12823
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Greasemonkey userscript to hide Google results by domain

Post by StuartR »

I tried installing this, but cannot see any pale colored buttons.

Greasemonkey said that it had installed the script, but I don't know how to check. What should I be searching for under about:config?

Any suggestions of what I might have done wrong?

Edited to add
I have definitely managed to install the script...
You do not have the required permissions to view the files attached to this post.
StuartR


User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Greasemonkey userscript to hide Google results by domain

Post by jscher2000 »

Stuart, thanks for trying it.

By any chance is your default Google page a .co.uk page? In that case, please edit the URL in the Included Pages box to the correct URL (or feel free to add it as a second URL). I think there must be a way to add that into the script file, but the header section was auto-generated so I don't know the syntax.

If you are searching on google.com, then hmmm, do you see any script errors in the Error Console (Tools menu)? Click Clear to get rid of all the old errors, then run the search again and see if there are any problems.

User avatar
StuartR
Administrator
Posts: 12823
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Greasemonkey userscript to hide Google results by domain

Post by StuartR »

Jefferson,

I added http://www.google.co.uk/search*" onclick="window.open(this.href);return false; to the included pages, cleared the error console and tried again. The error console now shows this...
ErrorConsole.png
You do not have the required permissions to view the files attached to this post.
StuartR


User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Greasemonkey userscript to hide Google results by domain

Post by jscher2000 »

StuartR wrote:I added http://www.google.co.uk/search*" onclick="window.open(this.href);return false; to the included pages, cleared the error console and tried again. The error console now shows this...
I'm at a loss. Either something is blocking the script or you're getting a different page structure than I get... Can you email me the rendered page source for a sample search? Select all, right-click, View Selection Source, then paste into a blank text document for mailing.

(Also, at the top of the console, click the red X Error button to filter for script errors.)

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Greasemonkey userscript to hide Google results by domain

Post by jscher2000 »

Okay, I see the problem. When you use Instant search, the page does not reload, so the script does not run again. I somehow need to hook the script into the relevant events for Instant search....

{Day turns to night...}

Well, that was a deep dive! :D
google_hit_hider2_user_js.zip
You do not have the required permissions to view the files attached to this post.

User avatar
StuartR
Administrator
Posts: 12823
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Greasemonkey userscript to hide Google results by domain

Post by StuartR »

This version installed OK, and has two entries for google.co.uk, but it still behaves the same.
ExampleSearch.png
ErrorConsole.png
You do not have the required permissions to view the files attached to this post.
StuartR


User avatar
Argus
GoldLounger
Posts: 3081
Joined: 24 Jan 2010, 19:07

Re: Greasemonkey userscript to hide Google results by domain

Post by Argus »

Jefferson,
I didn't post earlier but; you have another user here; just adding cheers, as you look at that. :smile:

I looked at the first one (I've not used Greasemonkey earlier; yep I know, not the kind of beta tester one would want :laugh:), and as it looked as in Stuart's first screen shot, I understood that I had to add something, so added the google.se URL under included, similar to the above, but got no change in the results.

But now.
Woo hoo; your second works (though it wrote over my google.se :grin:). I didn't bother to add it again for a test; since I've a UK bookmark, and just tried it.
2011-01-22_A.png
But, if I enable JavaScript for google.co.uk (it wasn't in NoScript), it doesn't work (checked back and forth, enabled disabled in new tabs); I don't know perhaps I've missed something. Perhaps it is this with JavaScripts for Google.co.uk and "Instant search" as you say. (BTW Instant search or real time, whatever (I don't like it or need it that much) isn't enabled in the .se I think. But as I said, my short test on v0.2 only included the .uk.)
You do not have the required permissions to view the files attached to this post.
Byelingual    When you speak two languages but start losing vocabulary in both of them.

User avatar
StuartR
Administrator
Posts: 12823
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Greasemonkey userscript to hide Google results by domain

Post by StuartR »

Argus,

I get the same behaviour as you, if I disable google.co.uk in NoScript then I can see the XX links.
StuartR


User avatar
Argus
GoldLounger
Posts: 3081
Joined: 24 Jan 2010, 19:07

Re: Greasemonkey userscript to hide Google results by domain

Post by Argus »

Jefferson,
Addendum:
It works directly on the .se with scripts enabled; as I mentioned earlier there is no real-time search there yet, perhaps the difference. So, something with their real-time tinkering, me think.

(Gee, why do we need real-time search? Just because something is possible, doesn't mean we have to implement it, build it, sell it. The .se has the previous version of "search help", some sort of auto complete. OK, can be to some help, or fun for those interested in what other people have searched, but I guess there are other tools for that. So every second letter, or so, I type the status bar flicker and away goes another batch of bytes into the tubes; just how many scrambled words would that be per day? "wnidos 7", no, "WIdows 7", argh ...; "indows 7", now slowly "Windows 7", yes! Now Enter! :grin: )
Byelingual    When you speak two languages but start losing vocabulary in both of them.

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Greasemonkey userscript to hide Google results by domain

Post by jscher2000 »

NoScript disables instant search, so that is effective but doesn't really count as a win.

I should have realized that Google is a very complex application... I noticed that sometimes Google presents a page without a name, i.e., it could be /search?, /webhp?, or /#, which I hadn't noticed before. I think that appears after logging in or logging out. I almost always use Google logged out...

So I edited the domains again (for all http://www.google.com" onclick="window.open(this.href);return false; / http://www.google.co.uk" onclick="window.open(this.href);return false; / http://www.google.se" onclick="window.open(this.href);return false;). :blackteeth:

I don't know whether I've managed to test all the possibilities, because I never set up an iGoogle home page, but hopefully this covers it? :crossfingers:
google_hit_hider3.user.js.zip
You do not have the required permissions to view the files attached to this post.

User avatar
StuartR
Administrator
Posts: 12823
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Greasemonkey userscript to hide Google results by domain

Post by StuartR »

THANK YOU
This version works well, even with google.co.uk enabled in NoScript.

I do hope it was a good learning experience and not just frustrating.
StuartR


User avatar
Argus
GoldLounger
Posts: 3081
Joined: 24 Jan 2010, 19:07

Re: Greasemonkey userscript to hide Google results by domain

Post by Argus »

All OK, so far for on co.uk. :thumbup:

By the way; the blocked sites; is it only the:

Code: Select all

greasemonkey.scriptvals.http://jeffersonscher.com//Google Hit Hider.hideyhosts
that needs to be edited if removing any?

I noticed that there is a checkbox for completely removal, if uninstalling; and it worked when changed versions earlier. Blocked sites were not blocked. (As a true developer you should now point my question to Greasemonkey and that I should read their help file. :grin:)
2011-01-22_B.png
Thanks for adding .se.
You do not have the required permissions to view the files attached to this post.
Byelingual    When you speak two languages but start losing vocabulary in both of them.

User avatar
StuartR
Administrator
Posts: 12823
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Greasemonkey userscript to hide Google results by domain

Post by StuartR »

Argus,

According to the original post
(3) If your blacklist becomes messed up, you can edit or clear it in about:config (there is no other UI for managing the list).
StuartR


User avatar
Argus
GoldLounger
Posts: 3081
Joined: 24 Jan 2010, 19:07

Re: Greasemonkey userscript to hide Google results by domain

Post by Argus »

Yep, I had read that; and I did filter for something I knew; a name on a blocked site and got a few hits, but only one for Greasemonkey, so I guess that answers it. But still, I'm new to Greasemonkey and this, so I thought I better ask.

So one can say that we have one setting for individual, and associated preferences for all blocked (including the userscript).
Byelingual    When you speak two languages but start losing vocabulary in both of them.

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Greasemonkey userscript to hide Google results by domain

Post by agibsonsw »

Can I ask for a brief description of how 'Greasemonkey' is able to tap into/modify a site please? I'm intrigued.

Google instant search is a bit of a pain. On the whole I think I'd rather do without it..
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Greasemonkey userscript to hide Google results by domain

Post by jscher2000 »

StuartR wrote:I do hope it was a good learning experience and not just frustrating.
Yes, I learned way more about GreaseMonkey (and of course Google search results) than I knew before. I'll try not to do evil with the new knowledge.
Argus wrote:By the way; the blocked sites; is it only the:

Code: Select all

greasemonkey.scriptvals.http://jeffersonscher.com//Google Hit Hider.hideyhosts
that needs to be edited if removing any?
Yes, apparently each Firefox preference can hold megabytes of data, so there was no point in making lots of separate ones. As you can see, it's just a string with a pipe character between each domain (and one at the beginning and end). It wouldn't be terribly hard to create a UI for this list, but since an additional button would need to be inserted into each Google results page, it would wipe away yet another tiny slice of life away for each search. :sad:
agibsonsw wrote:Can I ask for a brief description of how 'Greasemonkey' is able to tap into/modify a site please? I'm intrigued.
Firefox extensions can do pretty much anything... more specifically, your code runs when the page has finished loading. (Whether that's a DOM load or complete load of all images, etc., I haven't double-checked.) Documentation on GreaseMonkey is a bit weak. The old tutorial we all used many years ago is no longer updated, and the wiki is hard to navigate. O'Reilly's free online content is useful, but time-consuming to navigate. But, here it is:

Official Site: Greasespot product info, GreaseSpot community wiki
Official GM userscript archive: Userscripts.org: Power-ups for your browser *
Old Intro book (online or PDF): Dive Into Greasemonkey
O'Reilly Commons wiki: Greasemonkey Hacks

* I probably should contribute this script if it proves stable. :smile:

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Greasemonkey userscript to hide Google results by domain

Post by jscher2000 »

I should have known that I was not the only person to ever write a Greasemonkey userscript for this. In fact, there have been many efforts over the years. These are some I found in a search, but not surprisingly, there are about a zillion scripts for Google sites:
I'm going to have to up my game if I want to play with these folks. :grin:

(Based on comments on these scripts, I think it probably should be the user's preference whether a button is available for suppressed results. No one approach seems to please everyone.)

User avatar
Argus
GoldLounger
Posts: 3081
Joined: 24 Jan 2010, 19:07

Re: Greasemonkey userscript to hide Google results by domain

Post by Argus »

I haven't looked at those yet; I'm happy with your userscript, and I think I didn't, so I'll do it now: thank you! :smile:

I think you are right; if one think about it, Google ... yes, there must be a "zillion" different attempts to do something with their search results. :grin:
Byelingual    When you speak two languages but start losing vocabulary in both of them.

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Greasemonkey userscript to hide Google results by domain

Post by jscher2000 »

Okay, here is an enhanced version. A few things to note:
  • There is an unblock button for each blocked hit to make it easier to change your mind (or play around).
  • There is a button to completely hide hits from blocked domains. (No undo for that yet, you will need to use about:config to switch that back. Filter on hidey and you'll see the preference.)
  • The button appearance is more low-key and unobtrusive.
One technical change: The "namespace" was changed from my URL to my name. Since there's no connection between the script and my site, that seemed better. But it means that this version will store preferences separately from the earlier version. If you already accumulate a block list, you can use about:config to copy and paste it from the old preference to the new one. (Block a domain first so you can have them both set up.) Edit: Because the script has the same name, you may actually have to uninstall the old one first. Sorry for the inconvenience. I'll know better the next time.

This is pretty functional now. It would be nice to get a full 10 useful results, rather than getting 8 or 6 or even fewer, but... my wizardry level falls short of that objective.

Edit: Sometimes after unblocking the second of two hidden hits in a row, the first hidden result disappears. A refresh restores the missing item. Must be a bug, but I'm unable to track it down tonight.
google_hit_hider5_user_js.zip
You do not have the required permissions to view the files attached to this post.