本文介绍了Greasemonkey:向URL添加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
检测当前URL是否已经到达紧凑型站点。 如有必要,请加载页面的精简版本。 小心锚网址(以片段或哈希(#... )) 将不需要的页面保留在浏览器历史记录之外,以便后退按钮正常工作。只会记住 pact 网址。 运行 document-start ,在这种情况下,脚本可以提供更好的性能。
Detect if the current URL is already to the compact site.
Load the compact version of the page if necessary.
Beware of "anchor" URLS (they end with "fragments" or "hashes" (#...) ) and account for them.
Keep the unwanted pages out of the browser history so that the back button works well. Only pact URL's will be remembered.
By running at document-start, the script can give better performance in this case.
我想编写一个Greasemonkey / userscript,自动将 pact 添加到以 pay.reddit/ 所以它会自动将我重定向到移动版。
I'd like to write a Greasemonkey/userscript that automatically adds pact to URLs starting with pay.reddit/ so It automatically redirects me to the mobile version.
我去过查看类似的用户脚本,特别是这个用户脚本: userscripts/scripts/review/112568试图弄清楚如何编辑替换模式,但我缺乏这个领域的技能。
I've been looking at similar userscripts, particularly this one: userscripts/scripts/review/112568 trying to figure out how to edit the replacement pattern, but I lack skills in this domain.
如何编写一个从 pay.reddit/* 到 pay.reddit/*pact ?
谢谢
推荐答案脚本应该做这些事情:
为此,此脚本有效:
// ==UserScript== // @name _Reddit, ensure compact site is used // @match *://*.reddit/* // @run-at document-start // @grant none // ==/UserScript== var oldUrlPath = window.location.pathname; /*--- Test that "pact" is at end of URL, excepting any "hashes" or searches. */ if ( ! /\pact$/.test (oldUrlPath) ) { var newURL = window.location.protocol + "//" + window.location.host + oldUrlPath + "pact" + window.location.search + window.location.hash ; /*-- replace() puts the good page in the history instead of the bad page. */ window.location.replace (newURL); }更多推荐
Greasemonkey:向URL添加参数
发布评论