Adds board title, catalog, gallery, and style to the top bar.
// ==UserScript==
// @name 4chan Gallery
// @version 2.0.0
// @description Adds board title, catalog, gallery, and style to the top bar.
// @include *://boards.4chan.org/*
// @namespace https://greasyfork.org/users/3159
// ==/UserScript==
/* my adblock filters
boards.4chan.org###absbot
boards.4chan.org###blotter
boards.4chan.org###ctrl-top
boards.4chan.org##.boardBanner
boards.4chan.org##.bottomCtrl
boards.4chan.org##.center
boards.4chan.org##.navLinks
boards.4chan.org#HR
44chan */
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=#a>Style</a>] <span>';
xi('navtopright').insertAdjacentHTML('afterend',nr);
xi('navbotright').insertAdjacentHTML('afterend',nr);
document.getElementsByClassName('low')[0].onclick = function(){ccss()};
document.getElementsByClassName('low')[1].onclick = function(){ccss()};
//use cookie? Main.getCookie(style_group)?idk
if (GM_getValue("4theme"));
else GM_setValue("4theme",1);
var links = document.getElementsByTagName('link'),css=[];
for (i=0;i<links.length;i++){
if(links[i].href.indexOf('/css/') > -1){
css.push(links[i]);
}
}
function o(a){if(typeof a != 'undefined')GM_setValue("4theme", a);return GM_getValue("4theme")};
function ccss(a){
a==1 ? css[0].href = css[o()].href : o() > (css.length-2) ? css[0].href=css[o(1)].href : css[0].href = css[o(o()+1)].href;
}
ccss(1);
document.getElementsByName('post')[0].insertAdjacentHTML('afterend','<br>');
if (path[2]=='thread'){
xc('beforeend','[<a class=gl href=#a>Gallery</a>] ');
var s = document.getElementsByClassName('gl');
for (i=0; i < s.length; i++){
s[i].onclick=function(){trigger()};
}
xi('postForm').style.display='none';
xi('togglePostFormLink').style.display='block';
xi('togglePostFormLink').onclick = function(){
xi('postForm').style.display='table';
xi('togglePostFormLink').style.display='none';
}
}
// 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){
find();bg.style.display='block';img.style.display='block';ii.style.display='block';i2.style.display='block';larw.style.display='block';rarw.style.display='block';loader();
}
else endalert();
}
function find(l) {
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);
}
}
}
var sorted = imgLinks.sort(),results = [];
for (i = 0; i < sorted.length; i++) {
if (sorted[i + 1] != sorted[i]) {
results.push(sorted[i]);
}
}
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); //this is for 4chan only
}
}
img.src = results[a];
atitle = (title[a] ? title[a] : img.src);
aii();
i2.innerText='[ ' + (a+1) + '/' + results.length + ' ]';
return results;
}
function aii(){ii.innerText='[ ' + img.width + 'x' + img.height + ' ][ ' + atitle + ' ]'};
function endalert(){
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,atitle,img = new Image(),bg = document.createElement('div'),larw = document.createElement('div'),rarw = document.createElement('div'),ii = document.createElement('p'),i2 = document.createElement('p');
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';i2.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){a++;find()} else endalert()};
document.body.appendChild(img);
function loader(){
var timg = new Image();
timg.src = find()[h];
timg.onload = function(){if(h==0)aii();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';
i2.style.cssText=iv+ 'right:0';
ii.onclick = function(){a=0;find()};
i2.onclick = function(){a=--find().length;find()};
document.body.appendChild(ii);document.body.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){a--;find()}};
rarw.onclick = function(){if(a< --find().length){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'){a--;find()};
break;
case 39:
if(a< --find().length && bg.style.display != 'none'){a++;find()}else endalert();
break;
}
});