Imgur: Hide non-mature content

Adds a button to Imgur.com that hides all non-mature image links on the page

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        Imgur: Hide non-mature content
// @namespace   
// @description Adds a button to Imgur.com that hides all non-mature image links on the page
// @include     http://imgur.com/
// @include     http://imgur.com/new/*
// @include     http://imgur.com/hot/*
// @include     http://imgur.com/t/*
// @version     1
// @grant       none
// @author      drgonzo67
// ==/UserScript==

document.getElementById('tags-current-list').style.display="none";
var secondaryNavPanel = document.getElementById('secondary-nav');
//alert(secondaryNavPanel);
var newItem = document.createElement("a");
var newItemText = document.createTextNode("Hide non-mature content");
newItem.setAttribute('onclick', "hideNonMatureElements();");
newItem.appendChild(newItemText);
secondaryNavPanel.appendChild(newItem);

var scriptCode = '\
function hideNonMatureElements() {\n\
	var cards = document.getElementsByClassName("cards");\n\
	for (var i in cards) {\n\
		var cardsHTML = cards[i].innerHTML;\n\
		var pieces = cardsHTML.match(/div id=\\"(.+)\\" class/g);\n\
		var imageIds = [];\n\
		for (var j in pieces) {\n\
			imageIds.push(pieces[j].split("\\"")[1]);\n\
		}\n\
		for (var j in imageIds) {\n\
			var imageId = imageIds[j];\n\
      if (document.getElementById(imageId).style.display==\"none\") continue;\n\
			var imageUrl = "http://imgur.com/gallery/" + imageId;\n\
			$.ajax({ url: imageUrl, async: false, success: function(data) {\n\
					var isMature = /mature-indicator/.test(data);\n\
					if (!isMature) {\n\
						document.getElementById(imageId).style.display=\"none\";\n\
					}\n\
			 }\n\
			});\n\
		}\n\
	}\n\
}';

var s = document.createElement("script");
s.innerHTML = scriptCode;
document.head.appendChild(s);