4chan Gallery

Adds board title, catalog, gallery, and style to the top bar.

Verze ze dne 30. 01. 2017. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name          4chan Gallery
// @version       2.1.3
// @description   Adds board title, catalog, gallery, and style to the top bar.
// @include       http://boards.4chan.org/*
// @include       https://boards.4chan.org/*
// @namespace     https://greasyfork.org/users/3159
// @run-at document-end
// ==/UserScript==         
window.addEventListener('load', function () {

	var bname = document.getElementsByClassName("boardTitle")[0].innerHTML;
	if (bname.indexOf("/ - ") > -1) {
		bname = bname.split("/ - ")[1];
	}
	var path = document.location.pathname.split("/");

	function xc(q, r) {
		a = document.getElementsByClassName("boardList");
		a[0].insertAdjacentHTML(q, r);
		a[1].insertAdjacentHTML(q, r);
		b = document.getElementsByClassName("customBoardList");
		if (b[0]) {
			b[0].insertAdjacentHTML(q, r);
			b[1].insertAdjacentHTML(q, r);
		}
	}
	xc("afterbegin", '[<a href="//boards.4chan.org/' + path[1] + '">' + bname + "</a>] ");
	xc("beforeend", path[2] == "catalog" ? "" : '[<a href="//boards.4chan.org/' + path[1] + '/catalog">Catalog</a>] ');

	function xi(q) {
		var b = document.getElementById(q);
		return b;
	}
	var nr = '<span style="float:right">[<a class=low href=javascript:void(0)>Style</a>]&nbsp<span>';
	xi("navtopright").insertAdjacentHTML("afterend", nr);
	xi("navbotright").insertAdjacentHTML("afterend", nr);

	var themes = ['Yotsuba New', 'Yotsuba B New', 'Futaba New', 'Burichan New', 'Tomorrow', 'Photon'];

	function get() {
		cur = document.cookie.indexOf('ws_style') > -1 ? document.cookie.split('ws_style=')[1].split(';')[0] : 'Yotsuba New';
		for (i = 0; i < themes.length; i++) {
			if (themes[i] == cur) {
				return i;
			}
		}
	}

	function set(a) {
		document.cookie = 'ws_style=' + themes[a];
		if (path[2] == "catalog") {
			location.reload();
		} else {
			location.href = "javascript:setActiveStyleSheet('" + themes[a] + "')";
		}
	}

	function cstyle() {
		if (get() > (themes.length - 2)) {
			set(0);
		}
		else {
			set(get() + 1);
		}
	}
	var low = document.getElementsByClassName("low");
	low[0].onclick = function () {
		cstyle();
	};
	low[1].onclick = function () {
		cstyle();
	};

	if (path[2] == "thread") {
		xc("beforeend", "[<a class=gl href=javascript:void(0)>Gallery</a>] ");
		var s = document.getElementsByClassName("gl");
		for (i = 0; i < s.length; i++) s[i].onclick = function () {
			trigger();
		};
	}

	// code bellow is the gallery, works on most image boards, simply add a way to trigger
	// to test, copy paste code bellow into console then run trigger()

	function trigger() {
		if (find().length) {
			bg.style.display = "block";
			img.style.display = "block";
			ii.style.display = "block";
			ri.style.display = "block";
			larw.style.display = "block";
			rarw.style.display = "block";
            if (!first) ii.innerText = "[ Loading... ]";
			find();
			loader();
		} else {
			endalert();
		}
	}

	function find() {
		var aa = document.getElementsByTagName("a"),
			imgLinks = [];
		for (i = 0; i < aa.length; i++) {
				var link = aa[i].getAttribute("href");
				if (link) {
					ext = link.split(".").pop();
					if ((ext == "jpg" || ext == "png" || ext == "gif") && link.indexOf("google") < 0 && link.indexOf("iqdb") < 0 && link.indexOf("saucenao") < 0) {
						imgLinks.push(link);
					}
				}
			}
		results = imgLinks.filter(function (item, pos) {
				return imgLinks.indexOf(item) == pos;
			});

		var names = document.getElementsByClassName("fileText"),
			title = [];
		for (i = 0; i < names.length; i++) {
				ext = names[i].children[0].getAttribute("href").split(".").pop();
				if (ext == "jpg" || ext == "png" || ext == "gif") {
					n = names[i].children[0].getAttribute("title");
					if (!n) {
						n = names[i].children[0].innerText;
					}
					title.push(n);
				}
			}
		img.src = results[a];
		atitle = title[a] ? title[a] : img.src;
		i2.innerText = "[ " + (a + 1) + "/" + results.length + " ]";
		return results;
	}

	function aii() {
		ii.innerText = "[ " + img.naturalWidth + "x" + img.naturalHeight + " ][ " + atitle + " ]";
	}

	function endalert() {
		if (bg.style.display == "block") {
			b = document.createElement("div");
			c = b.style;
			b.id = "theend";
			for (var d = "0123456789ABCDEF".split(""), a = "#", e = 0; 6 > e; e++) {
				a += d[Math.round(15 * Math.random())];
			}
			c.backgroundColor = a;
			c.cssText += "line-height:50px;width:200px;height:50px;position:fixed;margin:auto;left:0;right:0;top:0;bottom:0;font-size:42px;text-align:center;color:#fff;z-index:10001";
			b.innerText = "The End";
			document.body.appendChild(b);
			setTimeout(function () {
				z = document.getElementById("theend");
				z.parentNode.removeChild(z);
			}, 420);
		}
	}
	var a = 0,
		h = 0,
		first = false,
		atitle, img = new Image(),
		bg = document.createElement("div"),
		larw = document.createElement("div"),
		rarw = document.createElement("div"),
		ii = document.createElement("p"),
                ri = document.createElement("div"),
                i2 = document.createElement("a"),
                dwn = document.createElement("a");
	bg.style.cssText = "opacity:0.9;position:fixed;top:0;left:0;z-index:9999;background-color:black;width:100%;height:100%;display:none";
	bg.onclick = function () {
			bg.style.display = "none";
			img.style.display = "none";
			ii.style.display = "none";
			ri.style.display = "none";
			larw.style.display = "none";
			rarw.style.display = "none";
		};
	document.body.appendChild(bg);
	img.style.cssText = "position:fixed;z-index:10000;max-height:calc(100% - 40px);max-width:calc(100% - 60px);margin:auto;top:0;bottom:0;left:0;right:0;display:none";
	img.onclick = function () {
			if (a < --find().length) {
				ii.innerText = "[ Loading... ]";
				a++;
				find();
			} else {
				endalert();
			}
		};
	img.onload = function () {
			first = true;
			aii();
		};
	document.body.appendChild(img);

	function loader() {
			var timg = new Image();
			timg.src = find()[h];
			timg.onload = function () {
				if (h++ < find().length) {
					loader();
				}
			};
		}
	var iv = "position:fixed;bottom:0;z-index:10000;color:#bababa;margin:0;display:none;";
	ii.style.cssText = iv + "left:0";
	ri.style.cssText = iv + "right:0";
	ii.onclick = function () {
			ii.innerText = "[ Loading... ]";
			a = 0;
			find();
		};
	i2.onclick = function () {
			ii.innerText = "[ Loading... ]";
			a = --find().length;
			find();
		};
        dwn.innerText = "[ ⇩ ]";
        dwn.style.cssText = "color:#bababa !important;text-decoration:none";
        i2.style.cssText = "color:#bababa !important;text-decoration:none";
        dwn.onclick = function () {
                        var link,imgs = document.querySelectorAll(".fileThumb");
                        document.body.innerHTML = "mkdir -p 4curl && cd 4curl && <br />";
                        for (var i = 0; i < imgs.length; i++) {
                            if ( imgs[i].getAttribute("href") ){
                                link = imgs[i].getAttribute("href").split("//")[1];
                                document.body.innerHTML += "curl -O <a download href='" + link + "'>" + link + "</a> && <br />";
                            }
                        }
                        document.body.innerHTML += 'echo "done" <br /><br /> select all and paste into terminal, hit enter, then navigate to folder "4curl"';
       };
	document.body.appendChild(ii);
	document.body.appendChild(ri);
        ri.appendChild(dwn);
        ri.appendChild(i2);
	var arw = "position:fixed;z-index:10000;top:calc(50% - 15px);border-top: 15px solid transparent;border-bottom: 15px solid transparent;display:none;border-";
	larw.style.cssText = arw + "right: 20px solid #bababa;left:5px";
	rarw.style.cssText = arw + "left: 20px solid #bababa;right:5px";
	larw.onclick = function () {
			if (a > 0) {
				ii.innerText = "[ Loading... ]";
				a--;
				find();
			}
		};
	rarw.onclick = function () {
			if (a < --find().length) {
				ii.innerText = "[ Loading... ]";
				a++;
				find();
			} else {
				endalert();
			}
		};
	document.body.appendChild(larw);
	document.body.appendChild(rarw);
	document.addEventListener("keydown", function (e) {
			switch (e.which) {
			case 37:
				if (a > 0 && bg.style.display != "none") {
					ii.innerText = "[ Loading... ]";
					a--;
					find();
				}
				break;
			case 39:
				if (a < --find().length && bg.style.display != "none") {
					ii.innerText = "[ Loading... ]";
					a++;
					find();
				} else {
					endalert();
				}
				break;
			}
		});
});