Skip to content

Instantly share code, notes, and snippets.

@Markyparky56
Created March 2, 2016 21:20
Show Gist options
  • Save Markyparky56/ce5026ab1f3851aaf0ae to your computer and use it in GitHub Desktop.
Save Markyparky56/ce5026ab1f3851aaf0ae to your computer and use it in GitHub Desktop.
Tampermonkey Compatible Reddit NSFW Sub Redirector
// ==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