简体   繁体   English

使用Greasemonkey修改Craigslist的默认搜索结果排序?

[英]Use Greasemonkey To modify Craigslist's default, search-results sorting?

Very recently, Craigslist changed the search results sorting on the results page to "relevance". 最近,Craigslist 将结果页面上排序的搜索结果更改为“相关性”。 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". 我认为,由于我对编码的知识非常有限,因此value =“rel”值需要更改为“date”。 I would like to use Greasemonkey to change the default sorting back to "date". 我想使用Greasemonkey将默认排序更改回“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? 这可以用Greasemonkey脚本完成吗? 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. 我访问了Userscripts并浏览了几十个现有的脚本,找到了一些可以修改但无法找到的东西。
  • 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. 我尝试了一些来自Userscripts的其他脚本,这些脚本是为了做这样的事情而编写的,但在不同的网站上,我无法让它们在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. 虽然我真的很喜欢,但我不认为我可以在几天内学习javascript,更不用说几周了,能够写出我需要的东西。

Changing that <input> won't help. 改变<input>将无济于事。 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. 但是 ,对于我看到的Craigslist搜索页面,例如这个 ,排序顺序按钮只是加载具有不同查询参数的页面的链接。 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. 这意味着您可以使用URL重写来获得所需的排序顺序,而无需将整个页面加载两次。

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);
}

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 : 对于像我这样不熟悉如何使用Greasemonkey的人 ,如果这里是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. 转到FF工具>插件,搜索Greasemonkey,安装它并重新启动FF。
  3. Go to FF Tools>Greasemonkey>New User Script, name it something like "Craigslist Relevant" click button "new script from clipboard" 转到FF工具> Greasemonkey>新用户脚本,将其命名为“Craigslist Relevant”点击按钮“从剪贴板中新建脚本”
  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! 有关@grant丢失的消息,但当我去CL并运行搜索时,它有效!

Thank you Brock 谢谢Brock

I had to remove the + window.locaiton.hash to get it to work in chrome (using tampermonkey instead of greasemonkey). 我不得不删除+ window.locaiton.hash以使其在chrome中工作(使用tampermonkey而不是greasemonkey)。 Maybe that'll help someone... 也许那会帮助别人......

I just added &sort=date at the end of the url in my browser, it worked !! 我刚刚在浏览器的url末尾添加了&sort=date ,它工作了!

The original url was: 原始网址是:

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

After adding &sort=date : 添加&sort=date

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM