DeviantBlocker

DeviantArt gallery - block images from selected artists

2016-06-02 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name DeviantBlocker
// @namespace brandrock.co.za
// @author Peter Brand
// @description DeviantArt gallery - block images from selected artists
// @license GNU GPLv3
// @include http://www.deviantart.com/
// @include http://www.deviantart.com/?*
// @include http://browse.deviantart.com/*
// @include http://www.deviantart.com/browse/*
// @include https://www.deviantart.com/
// @include https://www.deviantart.com/?*
// @include https://browse.deviantart.com/*
// @include https://www.deviantart.com/browse/*
// @version 2.0
// @grant GM_getValue
// @grant GM_setValue
// @run-at document-end
// ==/UserScript==

// @grant GM_log
(function() {
	//var blacklist = '|';
	var blacklist = GM_getValue('DAGbl2', '|');
	var thumbs = document.getElementsByTagName('IMG');

	//scan all IMG elements that have a data-sigil attribute (seems unique to gallery images)
	for(var i = thumbs.length; i--;) {
		var img = thumbs[i];
		if (img.getAttribute('data-sigil')){
			var a = img.parentNode;
			var div = a.parentNode; //is a span now
			var userid = a.href;
			if (userid.indexOf("://") > -1) {
				userid = userid.split('/')[2];
			}
			userid = userid.split('.')[0];
			//create a button on the page to toggle the state of the artist
			var elem = document.createElement('button');
			elem.type = 'button';
			elem.userid = userid;
			img.userid = userid;
			elem.title = 'Click to hide/show images from this artist';
			elem.innerHTML = 'x'; //userid;
			var useridD = '|' + userid + '|'
			if (blacklist.indexOf(useridD) > -1){
				imgHide(img);
				elem.isBlocked = true;
			} else {
				elem.isBlocked = false;
			}
			elem.addEventListener('click', function(e){
				artistToggle(e, this);
			});
			elem.style.zIndex = '99';
			elem.style.position = 'absolute';
			elem.style.bottom ='0px';
			elem.style.right ='0px';
			div.appendChild(elem);
		}
	}

	function artistToggle(e, button) {
		//show or hide the images for this artist
		if (button.isBlocked){
			//remove from blacklist string - could have used an array, but string is fast enough
			blacklist = blacklist.replace(button.userid + '|', '');
			GM_setValue('DAGbl2', blacklist);
			//scan page for all images for this artist and show them
			for(var i = thumbs.length; i--;) {
				var img = thumbs[i];
				if(img.userid == button.userid){
					imgShow(img);
				}
			}
			button.isBlocked = false;
		} else {
			//add to blacklist
			blacklist = blacklist + button.userid + '|';
			GM_setValue('DAGbl2', blacklist);
			//scan page for all images for this artist and hide them
			for(var i = thumbs.length; i--;) {
				var img = thumbs[i];
				if(img.userid == button.userid){
					imgHide(img);
				}
			}
			button.isBlocked = true;
		}
		var event = e || window.event;
		if (!event) return;
		event.cancelBubble = true;
		if (event.stopPropagation) event.stopPropagation();
	}
	
	function imgHide(img){
		img.style.opacity = '0.05';
	}
	
	function imgShow(img){
		img.style.opacity = '1';
	}
	
})();