DeviantBlocker

DeviantArt gallery - block images from selected artists

15.12.2015 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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 1.3
// @grant GM_getValue
// @grant GM_setValue
// @run-at document-end
// ==/UserScript==

// @grant GM_log

(function() {
	var blacklist = GM_getValue('DAGbl', '|');
	var thumbs = document.getElementsByTagName('IMG');

	//scan all IMG elements that have a data-src attribute (seems unique to gallery images)
	for(var i = thumbs.length; i--;) {
		var img = thumbs[i];
		if (img.getAttribute('data-src')){
			var div = img.parentNode;
			//walk up parents to find the container div that has the user name and id
			while (!(div.tagName == 'DIV' && div.getAttribute('userid')>'')) {
				div = div.parentNode;
			}
			//save the name and id, use id to block as name can change
			var username = div.getAttribute('username');
			var userid = div.getAttribute('userid');
			//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 = username;
			var useridD = '|' + userid + '|'
			if (blacklist.indexOf(useridD) > -1){
				imgHide(img);
				elem.isBlocked = true;
			} else {
				elem.isBlocked = false;
			}
			elem.addEventListener('click', function(){
				artistToggle(this);
			});
			catSpan = div.querySelector(".category");
			catSpan.parentNode.insertBefore(elem, catSpan);
		}
	}

	function artistToggle(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('DAGbl', 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('DAGbl', 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;
		}
	}
	
	function imgHide(img){
		//opacity is used so that the image can still trap mouseover/out
		//setting style.visibilty does not detect mouse
		img.style.opacity = '0.05';
		img.addEventListener('mouseover', function (){
			this.style.opacity = '1';
		}, false);
		img.addEventListener('mouseout', function (){
			this.style.opacity = '0.05';
		}, false);
	}
	
	function imgShow(img){
		//show the image and remove the anoymous events
		//it is assumed that our events are the first in the list (true for now until DA decides differently)
		img.style.opacity = '1';
		var fn =  getEventListeners(img.mouseover[0].listener);
		if (fn)	img.removeEventListener('mouseover', fn, false);
		fn =  getEventListeners(img.mouseout[0].listener);
		if (fn) img.removeEventListener('mouseout', fn, false);
	}
	
})();