Reddit - Block NSFW

Redirects NSFW subreddits to another site.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name		Reddit - Block NSFW
// @description		Redirects NSFW subreddits to another site.
// @version		1.2
// @include		/^https?://.*\.reddit\.com/r/.*$/
// @license		GPLv3
// @grant		GM_xmlhttpRequest
// @namespace https://greasyfork.org/users/10480
// ==/UserScript==

var redirectUrl = "https://www.reddit.com";	// Set this to 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,
	onload: function(response)
	{
		var json = JSON.parse(response.responseText);
		if (json.data.over18 || json[0].data.children[0].data.over_18)
		{
			window.location.replace(redirectUrl);
		}
	}
});