[英]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.
我大多只是最终用户。
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
的一步一步:
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.