UKBouldering.com

technical => computers, technology and the internet => Topic started by: Bubba on January 29, 2009, 11:36:55 am

Title: I just had a geekgasm - my first Greasemonkey script!
Post by: Bubba on January 29, 2009, 11:36:55 am
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...
Title: Re: I just had a geekgasm - my first Greasemonkey script!
Post by: slackline on January 29, 2009, 12:08:04 pm
 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.
Title: Re: I just had a geekgasm - my first Greasemonkey script!
Post by: tomtom on January 29, 2009, 12:46:17 pm
I'm just amused by the phrase geekgasm!   8)
though should it not be geekasm?
Title: Re: I just had a geekgasm - my first Greasemonkey script!
Post by: Bubba on January 29, 2009, 12:47:54 pm

Hmm yeah, geekasm would probably be better :)

Title: Re: I just had a geekgasm - my first Greasemonkey script!
Post by: Obi-Wan is lost... on January 30, 2009, 06:06:15 pm
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
Title: Re: I just had a geekgasm - my first Greasemonkey script!
Post by: Bubba on January 30, 2009, 06:14:19 pm
- 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)*
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)*
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...
Title: Re: I just had a geekgasm - my first Greasemonkey script!
Post by: Obi-Wan is lost... on January 30, 2009, 06:19:04 pm
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'!
Title: Re: I just had a geekgasm - my first Greasemonkey script!
Post by: Bubba on January 30, 2009, 06:26:47 pm

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