// ==UserScript==
// @name 巴哈縮圖強化
// @namespace http://tampermonkey.net/
// @version 0.7.00
// @description 狗才用預設縮圖= =
// @author SmallYue1
// @match https://forum.gamer.com.tw/B.php*
// @match https://forum.gamer.com.tw/C.php*
// @match https://forum.gamer.com.tw/Co.php*
// @match https://forum.gamer.com.tw/post1.php*
// @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.0/jszip.js
// @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js
// ==/UserScript==
var Lists = [], Lists_Img = [], Lists_UnSetted = [];
var zip, img, A_Download, Count_Text, Num_Of_Img_Text,Textarea,Clipboard;
function Find_And_Change()
{
var Match, Popularity, User, User_LowerCase, Time, Tempt;
Match = document.getElementsByTagName('tr');
for(var i = 0; i < Match.length; i++)
{
if(Match[i].className.indexOf('b-list__head') != -1)
{
for(var j = Match[i].children.length-1; j >0 ; j--)
{
Match[i].removeChild(Match[i].children[j]);
}
}
if((Match[i].className.indexOf('b-list__row') != -1) /*&& (Match[i].className.indexOf('edited') == -1)*/)
{
if(Match[i].children.length > 2)
{
Lists.push(Match[i]);
Lists_UnSetted.push("");
Lists_Img.push("");
}
}
}
for(i = 0; i < Lists.length; i++)
{
//if(Lists[i].className.indexOf('edited') == -1)
//{
User = Lists[i].children[2].children[1].innerText;
User_LowerCase = User.toLowerCase();
Time = Lists[i].children[3].children[0].innerText;
Popularity = Lists[i].children[2].children[0].innerText;
var NodeImg = document.createElement('img');
var Node_Div_Img = document.createElement('div');
var Node_A_Div_Img = document.createElement('a');
var NodeP_A_Div_Img_User_NodeTime_NodePopularity = document.createElement('p');
var Node_Div_Img_User_NodeTime_NodePopularity = document.createElement('div');
var NodeTime = document.createElement('p');
var NodePopularity = document.createElement('p');
NodeImg.setAttribute("src", "https://avatar2.bahamut.com.tw/avataruserpic/"+User_LowerCase.split("")[0]+"/"+User_LowerCase.split("")[1]+"/"+User_LowerCase+"/"+User_LowerCase+"_s.png");
Node_Div_Img.appendChild(NodeImg);
Node_Div_Img.setAttribute("class", "nav-member_imgbox");
Node_A_Div_Img.appendChild(Node_Div_Img);
Node_A_Div_Img.append(User);
Node_A_Div_Img.setAttribute("class", "topbar_member-home");
Node_A_Div_Img.setAttribute("href", "https://home.gamer.com.tw/homeindex.php?owner="+User);
Node_A_Div_Img.setAttribute("target", "_blank");
Node_A_Div_Img.setAttribute("style", "display:inline-block;width:100%");
NodeTime.append(" "+Time);
NodeTime.setAttribute("style", "display:inline-block;font-size: 13px");
NodePopularity.append("互動: "+Popularity.split("/")[0]+" 人氣:"+Popularity.split("/")[1]);
NodePopularity.setAttribute("style", "font-size: 11px; color:gray;");
NodeP_A_Div_Img_User_NodeTime_NodePopularity.appendChild(Node_A_Div_Img);
NodeP_A_Div_Img_User_NodeTime_NodePopularity.appendChild(NodeTime);
NodeP_A_Div_Img_User_NodeTime_NodePopularity.appendChild(NodePopularity);
NodeP_A_Div_Img_User_NodeTime_NodePopularity.setAttribute("class","b-list__count__user");
NodeP_A_Div_Img_User_NodeTime_NodePopularity.setAttribute("style","width:100%;text-align:center;vertical-align:middle;display:inline-block;");
Node_Div_Img_User_NodeTime_NodePopularity.appendChild(NodeP_A_Div_Img_User_NodeTime_NodePopularity);
Node_Div_Img_User_NodeTime_NodePopularity.setAttribute("class","TOP-my");
for(var k = Lists[i].children.length-1; k > 1; k--)
{
Lists[i].removeChild(Lists[i].children[k]);
}
if((Lists[i].className.indexOf('b-imglist-item') != -1)&&(Lists[i].children[1].children.length >1))
{
Tempt = Lists[i].children[1].children[0].outerHTML;
Lists[i].children[1].children[0].outerHTML = Lists[i].children[1].children[1].outerHTML;
Lists[i].children[1].children[1].outerHTML = Tempt;
}
Lists[i].children[1].prepend(Node_Div_Img_User_NodeTime_NodePopularity);
Lists[i].children[1].className="";
if(Lists[i].className.indexOf('b-imglist-item') != -1)
{
Lists[i].children[1].children[1].className="";
Lists[i].children[1].children[1].setAttribute('style','display:block;margin-top:5px');
}
if(Lists[i].children[1].children[1].childElementCount > 1)
{
Lists[i].children[1].children[1].children[1].setAttribute('style','padding:5px;padding-bottom:0px;margin-right:20px;');
}
if(Lists[i].children[1].childElementCount > 2)
{
Lists[i].children[1].children[2].setAttribute('style','margin-top:5px;margin-bottom:8px');
if(Lists[i].children[1].children[2].children.length > 0)
{
if(Lists[i].children[1].children[2].children[0].children.length > 0)
{
if(Lists[i].children[1].children[2].children[0].children[0].localName.indexOf('canvas') == -1)
{
Lists_Img[i] = Lists[i].children[1].children[2].children[0];
}
else
{
Lists[i].children[1].children[2].children[0].outerHTML = "";
}
}
else
{
if(Lists[i].children[1].children[2].children[0].className.indexOf('b-list__img') != -1)
{
Lists_Img[i] = Lists[i].children[1].children[2].children[0];
}
}
}
else
{
if(Lists[i].children[1].children[2].className.indexOf('b-list__img') != -1)
{
Lists_Img[i] = Lists[i].children[1].children[2];
}
}
}
if(Lists[i].children[0].children[2] === null)
{
var Node_Span = document.createElement('span');
Node_Span.setAttribute('class','b-list__summary__gp b-gp b-gp--normal');
Node_Span.append("0");
Lists[i].children[0].appendChild(Node_Span);
}
Lists_UnSetted[i] = Node_Div_Img_User_NodeTime_NodePopularity;
if(Lists_Img[i] !== "")
{
if(Lists_Img[i].dataset.thumbnail.indexOf("no-img-") != -1)
{
Lists_Img[i].outerHTML = "";
}
else
{
if((Lists_Img[i].style.length === 0) && (Lists_Img[i].className.indexOf('skeleton') != -1))
{
Lists_Img[i].style = 'background-image: url("'+Lists_Img[i].dataset.thumbnail+'");';
Lists_Img[i].className = 'b-list__img';
}
if(Lists_Img[i].dataset.thumbnail.indexOf("ytimg") != -1)
{
Lists_Img[i].parentNode.removeAttribute('href');
Lists_Img[i].parentNode.onclick = function() {
var New_div = document.createElement('div');
var New_Img_Btn = document.createElement('img');
var New_Iframe = document.createElement('iframe');
New_Img_Btn.src = "https://1.bp.blogspot.com/-aBquCi-gyQw/XXqz_sdh-II/AAAAAAAAAzs/qGjB4yTIIPMfI6gcZjOxw6WFQ4SiXvznwCKgBGAsYHg/s1600/x-symbol%25282%2529.png";
New_Img_Btn.onclick = function(){
this.parentNode.outerHTML = "";
};
New_Iframe.outerHTML = '<iframe frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
New_Iframe.src="https://www.youtube.com/embed/"+this.children[0].dataset.thumbnail.split('/')[4];
New_div.setAttribute('style','background:#FFFF99;height:80%;width:80%;position:fixed;top:15%;left:8%;z-index:1;overflow:auto;');
New_Img_Btn.setAttribute('style','position:fixed;z-index:3;width:16px;height:16px;margin-top:4px;margin-left:4px;');
New_Iframe.setAttribute('style','position: absolute;bottom:0px;left:2%;right:2%;width:96%;height: 95%;');
New_div.appendChild(New_Img_Btn);
New_div.appendChild(New_Iframe);
document.body.prepend(New_div);
};
}
else
{
Lists_Img[i].parentNode.removeAttribute('href');
Lists_Img[i].parentNode.onclick = function() {
var New_div = document.createElement('div');
var New_Img_Btn = document.createElement('img');
var New_Img = document.createElement('img');
New_Img_Btn.src = "https://1.bp.blogspot.com/-aBquCi-gyQw/XXqz_sdh-II/AAAAAAAAAzs/qGjB4yTIIPMfI6gcZjOxw6WFQ4SiXvznwCKgBGAsYHg/s1600/x-symbol%25282%2529.png";
New_Img_Btn.onclick = function(){
this.parentNode.outerHTML = "";
};
New_Img.src = this.children[0].dataset.thumbnail;
New_div.setAttribute('style','background:#FFFF99;height:80%;width:80%;position:fixed;top:15%;left:8%;z-index:1;overflow:auto;');
New_Img_Btn.setAttribute('style','position:fixed;z-index:3;width:16px;height:16px;margin-top:4px;margin-left:4px;');
New_Img.setAttribute('style','width:98%;margin-top:24px;margin-left:1%;z-index:2;');
New_div.appendChild(New_Img_Btn);
New_div.appendChild(New_Img);
document.body.prepend(New_div);
};
}
}
}
Lists_UnSetted[i].setAttribute("style","float:left;width:160px;margin-top:5px;margin-bottom:5px;padding-top:"+((Lists_UnSetted[i].parentNode.offsetHeight)-((Lists_UnSetted[i].offsetHeight+10)))/2+"px;");
Lists_UnSetted[i].parentNode.setAttribute("style","height:"+Lists_UnSetted[i].parentNode.offsetHeight+"px;");
//Lists[i].setAttribute('class','b-list__row b-list-item b-imglist-item edited');
//}
}
}
function Find_And_Download_Image()
{
zip = new JSZip();
zip.file(document.title.replace(/\//g,"_") +".url", "[InternetShortcut]\n" +"URL="+location.href);
img = zip.folder("images");
var Match_Imgs = document.getElementsByTagName('img');
DownloadImage(Match_Imgs);
}
function DownloadImage(Match_Imgs)
{
var xhr = [];
for(var i = 0; i < Match_Imgs.length; i++)
{
if((Match_Imgs[i].getAttribute("data-src") != null) && ((Match_Imgs[i].className.indexOf('lazyloaded') != -1) || (Match_Imgs[i].className.indexOf('lazyload') != -1)) && ((Match_Imgs[i].getAttribute("data-src").indexOf("bahamut") == -1) || ((Match_Imgs[i].getAttribute("data-src").indexOf("truth") != -1) && (Match_Imgs[i].getAttribute("data-src").indexOf("bahamut") != -1))))
{
Num_Of_Img_Text.innerText = parseInt(Num_Of_Img_Text.innerText) + 1;
xhr.push(new XMLHttpRequest());
xhr[i].responseType = 'blob';
xhr[i].MURL = Match_Imgs[i].getAttribute("data-src");
xhr[i].onload = function () {
if(this.statusText == "OK")
{
Count_Text.innerText = parseInt(Count_Text.innerText) + 1;
A_Download.innerText = "下載 "+Count_Text.innerText+" 張圖片中";
img.file(this.responseURL.split("/")[this.responseURL.split("/").length-1],this.response);
}
};
xhr[i].onerror = function () {
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function () {
if(this.statusText == "OK")
{
Count_Text.innerText = parseInt(Count_Text.innerText) + 1;
A_Download.innerText = "下載 "+Count_Text.innerText+" 張圖片中";
img.file(this.responseURL.split("/")[this.responseURL.split("/").length-1],this.response);
}
else if(this.statusText == "Too Many Requests")
{
alert('檔案 '+this.responseURL.split("/")[this.responseURL.split("/").length-1]+' 下載失敗:過多請求,請稍後再試。');
Num_Of_Img_Text.innerText = parseInt(Num_Of_Img_Text.innerText) - 1;
}
else
{
Num_Of_Img_Text.innerText = parseInt(Num_Of_Img_Text.innerText) - 1;
}
};
xhr.open("GET", "https://cors-anywhere.herokuapp.com/"+this.MURL);
xhr.send(null);
};
xhr[i].open("GET", Match_Imgs[i].getAttribute("data-src"));
xhr[i].send(null);
}
else
{
xhr.push("");
}
}
setTimeout(function(){Check();},1000);
console.log("done");
}
function Check()
{
if(parseInt(Num_Of_Img_Text.innerText) == parseInt(Count_Text.innerText))
{
Package();
}
else
{
setTimeout(function(){Check();},1000);
}
}
function Package()
{
if(parseInt(Count_Text.innerText) !== 0)
{
zip.generateAsync({type:"blob",compression:"STORE"}, function updateCallback(metadata) {
A_Download.innerText = "封裝進度: " + metadata.percent.toFixed(2) + " %";
}).then(function(content) {
saveAs(content, document.title.replace(/\//g,"_") + ".zip");
A_Download.innerText = "共下載了 "+Count_Text.innerText+" 張圖片";
Count_Text.setAttribute("style","visibility:hidden;");
});
}
else
{
A_Download.innerText = "沒有符合域名的圖片";
}
}
(function() {
'use strict';
if(location.pathname.indexOf("B.php") != -1)
{
Find_And_Change();
}
else if((location.pathname.indexOf("C.php") != -1) || (location.pathname.indexOf("Co.php") != -1))
{
var Tool_Bar = document.getElementById('BH-menu-path');
A_Download = document.createElement('a');
Count_Text = document.createElement('a');
Num_Of_Img_Text = document.createElement('a');
var Li_A_Download = document.createElement('li');
Li_A_Download.appendChild(A_Download);
A_Download.append("對優質門寶具");
A_Download.onclick = Find_And_Download_Image;
A_Download.setAttribute("id","A_Download");
Count_Text.append("0");
Count_Text.setAttribute("id","Count");
Num_Of_Img_Text.append("0");
Num_Of_Img_Text.setAttribute("id","Num_Of_Img");
if(Tool_Bar !== null)
{
Tool_Bar.children[0].appendChild(Li_A_Download);
document.body.appendChild(Count_Text);
document.body.appendChild(Num_Of_Img_Text);
}
}
else if(location.pathname.indexOf("post1.php") != -1)
{
const iframeWindow = document.getElementsByTagName('iframe')[0].contentWindow;
Textarea = iframeWindow.document.getElementsByTagName("body");
Clipboard = document.createElement('a');
Clipboard.innerText = "";
Clipboard.setAttribute("id","Clipboard");
document.body.appendChild(Clipboard);
iframeWindow.addEventListener('paste', function(e){
console.log(this.document.hasFocus())
if(this.document.hasFocus())
{
var paste = e.clipboardData.getData("text/plain");
Clipboard.innerText = paste;
setTimeout(()=>{
Clipboard.innerText = "";
},1000)
}
}, false);
Textarea[0].addEventListener('input',function(e){
if(this.innerHTML.indexOf("pximg.net") != "-1")
{
this.innerHTML = this.innerHTML.replace(/pximg.net/g,"pixiv.cat");
}
else if(this.innerHTML.indexOf("www.pixiv.net") != "-1")
{
setTimeout(()=>{
var Tempt = Clipboard.innerText.split("=");
Tempt = Tempt[Tempt.length-1];
var Tempt_A = this.getElementsByTagName('a');
for(var i = 0; i < Tempt_A.length; i++)
{
if((Tempt_A[i].innerText.indexOf(Tempt) != -1) && (Tempt_A[i].innerText == Clipboard.innerText) && (Tempt_A[i].innerText != ""))
{
Tempt_A[i].outerHTML = '<img id = "'+Tempt+'" src = "https://pixiv.cat/'+Tempt+'.jpg">';
var Tempt_Img = this.getElementsByTagName("img");
for(var j = 0; j < Tempt_Img.length; j++)
{
if(Tempt_Img[j].id == Tempt)
{
Tempt_Img[j].onerror = function(){
var tempt = this.src;
tempt = tempt.split("/");
tempt = tempt[tempt.length-1];
tempt = tempt.split(".")[0];
this.src = "https://pixiv.cat/"+tempt+"-1.jpg";
}
}
}
}
}
},10);
}
}, false);
}
})();