Created
March 2, 2016 21:20
-
-
Save Markyparky56/ce5026ab1f3851aaf0ae to your computer and use it in GitHub Desktop.
Tampermonkey Compatible Reddit NSFW Sub Redirector
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 - Block NSFW | |
// @description Redirects NSFW subreddits to another site. | |
// @version 1.0 | |
// @include /^https?://.*\.reddit\.com/r/.*$/ | |
// @license GPLv3 | |
// @grant GM_xmlhttpRequest | |
// @namespace https://github.com/Markyparky56 | |
// ==/UserScript== | |
var redirectUrl = "https://www.reddit.com"; // Set this to the url you want to redirect to. | |
var url = document.URL; | |
if (url.substring(url.length-1) != "/") | |
{ | |
url = url + "/"; | |
} | |
var jsonUrl = url + "about.json"; | |
GM_xmlhttpRequest( | |
{ | |
method: "GET", | |
url: jsonUrl, | |
synchronous: true, | |
onload: | |
function OnGet(result) | |
{ | |
var json = JSON.parse(result.responseText); | |
if(json.data.over18) | |
{ | |
window.location.replace(redirectUrl); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment