Last active
December 6, 2022 02:28
-
-
Save exo-pla-net/47ba13b9a63d3f1c578da1e094b5b61e to your computer and use it in GitHub Desktop.
Tampermonkey: Never Login to Reddit
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
// Want to browse reddit but never make a reddit account? | |
// Sick of reddit trying to force you to login to see NSFW content? | |
// This script will let you browse reddit as you please, and whenever you | |
// encounter a page demanding your to login, it will automatically swap your page to the | |
// old.reddit.com version, which doesn't force a login. | |
// ==UserScript== | |
// @name Anti-reddit login | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author exo-pla-net | |
// @match https://www.reddit.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=reddit.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function sleepForMilliseconds(milliseconds) { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve('resolved'); | |
}, milliseconds); | |
}); | |
} | |
function swapToOld(){ | |
let currentUrl = window.location.href | |
let oldUrl = currentUrl.replace('www', 'old') | |
window.location.replace(oldUrl); | |
} | |
async function main(){ | |
console.log("Checking for 18 year old wall...") | |
let buttons = null | |
while(true){ | |
buttons = document.querySelectorAll("button"); | |
if (buttons.length > 0) break; | |
console.log("Page is still loading...") | |
await sleepForMilliseconds(100) | |
} | |
buttons = [...buttons]; // convert to array | |
let button18wall = null | |
for(let i=0 ; i<buttons.length; i++){ | |
console.log(buttons[i]); | |
if (buttons[i].textContent.trim() === "I'm not over 18") | |
button18wall = buttons[i]; | |
} | |
if(button18wall!=null) | |
swapToOld(); | |
} | |
main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment