Imgur: Hide non-mature content

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);