Last active
February 19, 2021 10:51
-
-
Save rjocoleman/a791033a7edfd0d084d07c73e62e8a2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Reddit default to global geo filter | |
// @description Use geo_filter=GLOBAL by default | |
// @namespace https://gist.github.com/rjocoleman/a791033a7edfd0d084d07c73e62e8a2f/raw/f5bff6c051cf48e04352bea8c17919eba05ec0ea/reddit-global.user.js | |
// @version 0.1.0 | |
// @author rjocoleman | |
// @license MIT | |
// @released 2021-02-19 | |
// @updated 2021-02-19 | |
// @match *://www.reddit.com/* | |
// @match *://old.reddit.com/* | |
// @run-at document-start | |
// ==/UserScript== | |
(() => { | |
'use strict'; | |
// before the DOM has loaded | |
document.addEventListener('DOMContentLoaded', () => { | |
// after the DOM has loaded | |
// only do stuff if we're not logged in | |
if (document.querySelectorAll('a[href*="login"]').length) { | |
const url = new URL(window.location.href) | |
// if we're on the home page or /r/popular | |
if (['', '/r/popular'].includes(url.pathname.replace(/\/+$/, ''))) { | |
// and we haven't explicitly set a geo_filter | |
if (!url.searchParams.has('geo_filter')) { | |
// set GLOBAL | |
url.searchParams.set('geo_filter', 'GLOBAL'); | |
// send us to /r/popular because that's what non-logged in home is | |
url.pathname = '/r/popular'; | |
// reload the page with this geo_filter set | |
location.assign(url); | |
} | |
} | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment