4chan Gallery

Adds a gallery mode and title to customBoardList.

当前为 2014-10-20 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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

function s(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>]');
s("glink").onclick=function(){view()};
s("glink2").onclick=function(){view()};
s('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 arw = 'position:absolute;z-index:10000;top:calc(50% - 15px);border-top: 15px solid transparent;border-bottom: 15px solid transparent;display:none;'
s('inner').insertAdjacentHTML('afterend','<div id="larrow" style="' + arw + 'border-right: 20px solid #bababa;left:5px"></div>');
s('inner').insertAdjacentHTML('afterend','<div id="rarrow" style="' + arw + 'border-left: 20px solid #bababa;right:5px"></div>');
s('larrow').onclick=function(){if(a>0){a--;s('inner').children[0].src = array()[a];nbr()}};
s('rarrow').onclick=function(){if(a<(array().length-1)){a++;s('inner').children[0].src = array()[a];nbr();pre()}};
s('larrow').insertAdjacentHTML('afterend','<p id="n" style="color:white;margin:0;position:absolute;bottom:0;right:0;z-index:10000;display:none">[' + (a+1) + '/' + array().length + ']</p>');
s('bg').onclick=function(){this.style.display = 'none';s('inner').style.display = 'none';s('larrow').style.display = 'none';s('rarrow').style.display = 'none';s('n').style.display = 'none'};

function view(){
	s('bg').style.display = 'block';
	s('inner').style.display = 'block';
	s('larrow').style.display = 'block';
	s('rarrow').style.display = 'block';
	s('n').style.display = 'block';
	if (a<1){
		var img = new Image();
		img.style.cssText="position:absolute;z-index:10000;max-height:calc(100% - 40px);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 = array()[0];
		img.onclick = function(){
			if (a < (array().length - 1)){
				a++;
				img.src = array()[a];
				nbr();pre();
			}
		}
		s('inner').appendChild(img);
                pre();
	}
	
}
function nbr(){
	s('n').innerHTML = '[' + (a+1) + '/' + array().length + ']';
}
function array(){
	var imgs = document.getElementsByClassName('fileThumb'),b=[];
	for (var c=0;c<imgs.length;c++){
		if((imgs[c].getAttribute('href').indexOf('webm')) < 0){
			b.push(imgs[c].getAttribute('href'));
		}
	}
	return b;
}
function pre(){
	var img2 = new Image();
	img2.src = array()[a+1];
}
document.addEventListener("keydown", function(e){
	switch(e.which){
		case 39:
			if(a<(array().length-1)){a++;s('inner').children[0].src = array()[a];nbr();pre()};
			break;
		case 37:
			if(a>0){a--;s('inner').children[0].src = array()[a];nbr()};
			break;
	}
});
}
}, 1000);