UKBouldering.com

I just had a geekgasm - my first Greasemonkey script! (Read 2515 times)

Bubba

Offline
  • *****
  • Global Moderator
  • forum hero
  • Posts: 15367
  • Karma: +286/-6
I've recently been perusing Freecycle to see what bargains come up.

Part of the problem with browsing the lists is that all the "wanted" and "offered" posts are mixed in together and there doesn't seem to be a way to show just either one....or am I just being stupid?

Anyway, I wrote a GM script to hide all the "wanted" requests so I could just see what is being offered and what has been taken. Freecycle joy!

Here it is for anyone else who would find it useful:

Code: [Select]
// ==UserScript==
// @name           Freecycle - hide wanted
// @namespace      [url]http://ukbouldering.com/gm/[/url]
// @description    Hides wanted requests from the freecycle yahoo groups message listings
// @include        [url]http://groups.yahoo.com/group/Sheffield-FreeCycle/messages[/url]*
// @include        [url]http://groups.yahoo.com/group/Sheffield-FreeCycle/messages/[/url]*
// ==/UserScript==

var allTDs, thisTD, lc, pn;
allTDs = document.evaluate(
    "//td[@class='message']",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);
for (var i = 0; i < allTDs.snapshotLength; i++) {
    thisTD = allTDs.snapshotItem(i);
    // do something with thisTD
lc = thisTD.textContent.toLowerCase();
if (lc.indexOf('wanted')>= 0) {
    pn = thisTD.parentNode;
    pn.parentNode.removeChild(pn);
}
}

edit: damn forum software is automatically putting [url] tags into the namespace/include meta-data - remove them before using...
« Last Edit: January 29, 2009, 12:02:10 pm by Bubba »

slackline

Offline
  • *****
  • forum hero
  • Posts: 18863
  • Karma: +633/-26
    • Sheffield Boulder
 8)  Don't use freecycle much myself, but this will make it far easier perusing it and I've a few friends who are regular denizens there who will no doubt find this very handy.

tomtom

Offline
  • *****
  • forum hero
  • Posts: 20289
  • Karma: +642/-11
I'm just amused by the phrase geekgasm!   8)
though should it not be geekasm?

Bubba

Offline
  • *****
  • Global Moderator
  • forum hero
  • Posts: 15367
  • Karma: +286/-6

Hmm yeah, geekasm would probably be better :)


Obi-Wan is lost...

Offline
  • *****
  • forum hero
  • Posts: 3164
  • Karma: +138/-3
Sounds clever, never used GM before. Where do you copy/paste the code? In 'new user script'? Talk me though it please!

edit: kind of got it working, but it only seems to work for the first page of messages.

Clever all the same
« Last Edit: January 30, 2009, 06:16:05 pm by Obi-Wan is lost... »

Bubba

Offline
  • *****
  • Global Moderator
  • forum hero
  • Posts: 15367
  • Karma: +286/-6
- Install GM
- Right click the logo
- Select "new user script"
- give it any old name, namespace and description
- in the "includes" box, put in the following:
http://groups.yahoo.com/group/Sheffield-FreeCycle/messages*
http://groups.yahoo.com/group/Sheffield-FreeCycle/messages/*

you of course can also put in other groups - i use rotherham/chesterfield too. In fact, you could probably just specify:
http://groups.yahoo.com/group*
http://groups.yahoo.com/group/*

but i've not tried that.

- click "ok"
- it might prompt you to select an editor - i just use wordpad
- paste my code into the file
- save and close
- go to the freecycle messages page
- right click the GM monkey
- if the script is showing at the top with a tick next to it you should be in business

Hope that's enough info :)

I suspect the possibilities for GM are endless - this was really just something for me to do as a very basic intro to GM scripting that had some sort of use too...

Obi-Wan is lost...

Offline
  • *****
  • forum hero
  • Posts: 3164
  • Karma: +138/-3
Sweet, sorted. Missed out the asterisks.

V clever. Now we just need to work out how to cross off the 'offered' with a respective 'taken'!

Bubba

Offline
  • *****
  • Global Moderator
  • forum hero
  • Posts: 15367
  • Karma: +286/-6

Yeah, that would be really handy but probably quite tricky to code.

I guess you'd have to:

- strip the "wanted" text from the title
- do a search for the stripped text
- detect if a result with  "taken" in it was returned
- if so, remove one or both <tr>s from the page

Probably be a performance horrorshow.


 

SimplePortal 2.3.7 © 2008-2024, SimplePortal