I\'d like to write a Greasemonkey/userscript that automatically adds .compact
to URLs starting with https://pay.reddit.com/ so It automatically redirects me to
The script should do these things:
.compact
URL's will be remembered.document-start
, the script can give better performance in this case.To that end, this script works:
// ==UserScript==
// @name _Reddit, ensure compact site is used
// @match *://*.reddit.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
var oldUrlPath = window.location.pathname;
/*--- Test that ".compact" is at end of URL, excepting any "hashes"
or searches.
*/
if ( ! /\.compact$/.test (oldUrlPath) ) {
var newURL = window.location.protocol + "//"
+ window.location.host
+ oldUrlPath + ".compact"
+ window.location.search
+ window.location.hash
;
/*-- replace() puts the good page in the history instead of the
bad page.
*/
window.location.replace (newURL);
}