【问题标题】:Use Greasemonkey To modify Craigslist's default, search-results sorting?使用 Greasemonkey 修改 Craigslist 的默认搜索结果排序?
【发布时间】:2013-11-12 18:04:48
【问题描述】:

最近,Craigslist 将the results page 上的搜索结果排序更改为“相关性”。它曾经按“日期”排序。

结果页面上有单选按钮,但“相关性”按钮是默认设置的。查看页面上的源代码,有一行显示:

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

我认为,由于我对编码的了解非常有限,value="rel" 值需要更改为“date”。我想使用 Greasemonkey 将默认排序更改回“日期”。


我想有很多像我这样的人觉得“相关性”排序很烦人。现在的“相关性”方式,所有搜索结果都按日期分散。我希望排序是这样的,从最新到最旧的降序。

这可以用 Greasemonkey 脚本完成吗?如果是这样怎么办?有人可以写一个脚本来完成这个吗?改变那一行真的很难吗?

如果这里有人可以提供帮助,我将不胜感激。如果需要更多信息,我可以提供(我希望)。

我在任何编码方面的经验都非常有限。我主要是最终用户。

  • 我已在 Internet 上发布了我的请求,但尚未找到答案。
  • 我使用 Google 搜索了一个“相似”的脚本,我可以 修改以完成我需要的,但一直无法提出 与任何东西。
  • 我访问了 Userscripts 并经历了几十个 现有的脚本来找到我可以工作的东西 修改,找不到任何东西。
  • 我尝试了一些其他脚本 为执行此类操作而编写的用户脚本,但在 不同的网站,我无法让他们在 Craigslist 上工作。

虽然我真的很想,但我不认为我可以在几天内(更不用说几周)学习 javascript 来编写我需要的东西了。

【问题讨论】:

    标签: javascript sorting greasemonkey craigslist


    【解决方案1】:

    更改 &lt;input&gt; 无济于事。您需要单击“最新”按钮。您可以使用this answer 中描述的技术以最可靠的方式完成此操作。

    然而,对于我看到的 Craigslist 搜索页面,例如 this one,排序顺序按钮只是加载具有不同查询参数的页面的链接。例如:

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

    对比:

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

    分别用于相关最新排序。

    这意味着您可以使用URL rewriting 获得所需的排序顺序,而无需加载整个页面两次。

    完整的脚本如下所示:

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

    【讨论】:

      【解决方案2】:

      对于像我这样不知道如何使用 Greasemonkey 的人来说,这里是 Firefox 的分步操作26.0

      1. 突出显示并复制上面的“完整脚本”,以“//”开头,以“}”结尾。
      2. 进入FF Tools>Addons,搜索Greasemonkey,安装并重启FF。
      3. 转到 FF Tools>Greasemonkey>New User Script,将其命名为“Craigslist Relevant” 点击按钮“从剪贴板新建脚本”
      4. 在弹出的窗口中点击“保存”并关闭窗口。
      5. 一条消息是关于 @grant 丢失,但是当我去 CL 并运行搜索时,它成功了!

      谢谢布洛克

      【讨论】:

        【解决方案3】:

        我必须删除 + window.locaiton.hash 才能让它在 chrome 中工作(使用 tampermonkey 而不是greasemonkey)。也许这会对某人有所帮助...

        【讨论】:

          【解决方案4】:

          我刚刚在浏览器的网址末尾添加了&amp;sort=date,它起作用了!!

          原来的网址是:

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

          添加&amp;sort=date后:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-12-22
            • 2021-06-16
            • 1970-01-01
            • 1970-01-01
            • 2011-03-13
            • 1970-01-01
            • 1970-01-01
            • 2011-01-08
            相关资源
            最近更新 更多