Greasemonkey script to change a variable in the URL [duplicate]
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? Thanksif (/[\?&]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.
精彩评论