4chan Gallery

Adds a gallery mode and title to customBoardList.

Fra og med 27.09.2014. Se den nyeste version.

// ==UserScript==
// @name       		4chan Gallery
// @version    		1.0.1
// @description  	Adds a gallery mode and title to customBoardList.
// @include 		*://boards.4chan.org/*
// @namespace 		https://greasyfork.org/users/3159
// ==/UserScript==

function $(q){var b = document.getElementById(q);return b}
setTimeout(function(){
var boardname = document.getElementsByClassName('boardTitle')[0].innerHTML.split('/ - ')[1];
var boardlink = document.location.href.split('thread/')[0];
var cb = document.getElementsByClassName('customBoardList'),a = 0;
cb[0].insertAdjacentHTML('afterbegin','[<a href="' + boardlink + '">' + boardname + '</a>] ');
cb[1].insertAdjacentHTML('afterbegin','[<a href="' + boardlink + '">' + boardname + '</a>] ');

if (document.location.href.indexOf('/thread/') > 0){
cb[0].insertAdjacentHTML('beforeend','[<a id="glink" href="#">Gallery</a>]');
cb[1].insertAdjacentHTML('beforeend','[<a id="glink2" href="#">Gallery</a>]');
$("glink").onclick=function(){view()};
$("glink2").onclick=function(){view()};
$('bottom').insertAdjacentHTML('afterend','<div id="bg" style="opacity:0.9;position:fixed;top:0;left:0;z-index:9999;background-color:black;width:100%;height:100%;display:none"></div><div id="inner""></div>');
var imgs = document.getElementsByClassName('fileThumb');
var arw = 'position:absolute;z-index:10000;top:calc(50% - 30px);border-top: 15px solid transparent;border-bottom: 15px solid transparent;display:none;'
$('inner').insertAdjacentHTML('afterend','<div id="larrow" style="' + arw + 'border-right: 20px solid #bababa;left:5px"></div>');
$('inner').insertAdjacentHTML('afterend','<div id="rarrow" style="' + arw + 'border-left: 20px solid #bababa;right:5px"></div>');
$('larrow').onclick=function(){if(a>0){a--;$('inner').children[0].src = imgs[a].getAttribute('href')}};
$('rarrow').onclick=function(){if(a<(imgs.length-1)){a++;$('inner').children[0].src = imgs[a].getAttribute('href')}};
$('bg').onclick=function(){this.style.display = 'none';$('inner').style.display = 'none';$('larrow').style.display = 'none';$('rarrow').style.display = 'none'};

function view(){
	$("bg").style.display = 'block';
	$("inner").style.display = 'block';
        $("larrow").style.display = 'block';
        $("rarrow").style.display = 'block';
	if (a<1){
		var img = new Image();
		img.style.cssText="position:absolute;z-index:10000;max-height:95%;max-width:calc(100% - 60px);top:0;bottom:0;margin-top:auto;margin-bottom:auto;margin-left:auto;margin-right:auto;left:0;right:0";
		img.src = imgs[0].getAttribute('href');
		img.onclick = function(){
			if (a < (imgs.length - 1)){
				a++;
				img.src = imgs[a].getAttribute('href');
			}
		}
		$("inner").appendChild(img);
	}
	
}
}
}, 1000);