开发者

Greasemonkey script to change a variable in the URL [duplicate]

This question already has an answer here: Changing a page's UR开发者_JAVA技巧L parameters (1 answer) Closed 5 years ago.

On some pages in Google Analytics, there is a variable shown in the URL. The default value is 10. The URL always looks something like this:

...&trows=10&...

is there a way to change that to trows=100, so that the number of rows displayed by default is 100? Thanks


if (/[\?&]trows=10[^\d]/i.test(document.location.href)) 
    document.location.replace(document.location.href.replace("trows=10","trows=100"));

Use document.location.replace() so that the back button still works.


if (/trows=10(?!\d)/.test(location.href)) 
    location.href=location.href.replace("trows=10","trows=100");

Edit: If you want to use back button to go back to trows=10 page, use .assign method, instead of .replace, but since you want 100 as default, you might not need it.

location.assign(location.href.replace("trows=10","trows=100"));


Yes. You can modify links to the page, reload the page (with a modified parameter) when the "wrong" parameter is in the URL, or both. For the former, XPath is very useful (but not necessary) for finding links. For the latter, you can modify window.location.search.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜