Imgur: Hide non-mature content

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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