0

Very recently, Craigslist changed the search results sorting on the results page to "relevance". It used to be sorted by "date".

There are radio buttons on the results page, but the "relevance" button is the one that is being defaulted to. Reviewing the source code on the page, there is a line that shows this:

<input type="hidden" name="sort" value="rel">

I think, with my very limited knowledge of coding, that the value="rel" value needs changed to "date". I would like to use Greasemonkey to change the default sorting back to "date".


I think there are plenty of people like me who find the "relevance" sorting very annoying. The way it is now with "relevance", all of the results from a search are scattered by date. I would like the sorting to be how it was, descending, from newest to oldest.

Can this be done with a Greasemonkey script? If so how? Can someone write a script to accomplish this? Is it really difficult to change that one line?

If someone here could help, I would really appreciate it. If there is any more information needed I can provide that(I hope).

I have very limited experience with any coding. I'm just an end user mostly.

  • I have posted my request around the Internet and haven't come up with an answer yet.
  • I have used Google to search for a "similar" script that I could modify to accomplish what I need, but haven't been able to come up with anything.
  • I visited Userscripts and went through dozens of existing scripts to find something that would work that I could modify and couldn't find anything.
  • I tried a few other scripts from Userscripts that were written to do something like this, but on different sites and I couldn't get them to work on Craigslist.

Although I'd really like to, I don't think I can learn javascript in a few days, let alone weeks, to be able to write what I need.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295

4 Answers4

1

Changing that <input> won't help. You would need to click the "Newest" button. You would use techniques as described in this answer to do that in the most robust way.

However, for the Craigslist search pages that I see, for example this one, the sort order buttons are just links that load pages with different query parameters. EG:

?sort=rel&areaID=229&catAbb=sss&query=tools

versus:

?sort=date&areaID=229&catAbb=sss&query=tools

for Relevant versus Newest sorting, respectively.

This means you can use URL rewriting to get the desired sort order and without having to load the whole page twice.

The complete script looks like this:

// ==UserScript==
// @name        Craigslist search, switch "Relevant" to "Date" sorting
// @match       *://*.craigslist.org/search/*
// @run-at      document-start
// @grant       none
// ==/UserScript==

//--- Only fire if "sort=rel" is in the query string.

if ( /\bsort=rel\b/.test (window.location.search) ) {
    var newSrch = window.location.search.replace (
        /\bsort=rel\b/, "sort=date"
    );
    var newURL  = window.location.protocol + "//"
                + window.location.host
                + window.location.pathname
                + newSrch
                + window.location.hash
                ;
    /*-- replace() puts the good page in the history instead of the
        bad page.
    */
    window.location.replace (newURL);
}
Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
1

For those of you like me that don't know how to use Greasemonkey that well if at all here is the step by step for Firefox 26.0:

  1. Highlight and copy the "complete script" above, starting with "//" and ending with "}".
  2. Go to FF Tools>Addons, search for Greasemonkey, install it and restart FF.
  3. Go to FF Tools>Greasemonkey>New User Script, name it something like "Craigslist Relevant" click button "new script from clipboard"
  4. In window that pops up click "save" and close the window.
  5. A message comes about the @grant being missing but when I went to CL and ran a search it worked!

Thank you Brock

MichaC
  • 13,104
  • 2
  • 44
  • 56
Bob Allen
  • 11
  • 2
0

I had to remove the + window.locaiton.hash to get it to work in chrome (using tampermonkey instead of greasemonkey). Maybe that'll help someone...

winryan
  • 1
  • 2
0

I just added &sort=date at the end of the url in my browser, it worked !!

The original url was:

https://newyork.craigslist.org/search/mnh/crg?query=film&is_paid=all

After adding &sort=date:

https://newyork.craigslist.org/search/mnh/crg?query=film&is_paid=all&sort=date

Felipe Augusto
  • 7,733
  • 10
  • 39
  • 73