// ==UserScript==
// @name xgyw 秀人网查看大图写真
// @namespace http://tampermonkey.net/
// @version 1.3.4
// @description 针对xgyw网站上写真的脚本,同时提供打包下载功能
// @author xzwzz
// @match https://www.xgmn5.top/*/*
// @match https://www.xinggan5.top/*/*
// @match https://www.xiuren009.top/*/*
// @match https://www.ik009.top/*/*
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_xmlhttpRequest
// @grant GM_download
// @require https://update.greasyfork.org/scripts/449471/1413235/Viewer.js
// @require http://libs.baidu.com/jquery/2.0.0/jquery.js
// @require https://update.greasyfork.org/scripts/498742/1399645/jszip1.js
// @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js
// ==/UserScript==
var downloadCnt = 0; //下载中的图片
var photoSize = 200 //图片宽度
let convertPage; //需要显示的page
let imageViewer;//图片的集合
let toolBox;//工具集
let thumbTitle;//相册标题
let webHost;
let switchBtn;
let streams = {
"ik009":{
loadThumbnail:()=>{
var host = self.location.origin;
let addImages;
let items;
addImages = (info,host,document)=>{
var url = info.getAttribute("href")
let pageUrl = url
$.get(pageUrl,function (data) {
var nImages = $(".info-imtg-box p img", data);
for (var index = 0; index < nImages.length; index++) {
var origin = nImages[index];
origin.style.cssText = "width:200px"
info.append(origin)
}
})
}
items = $(".node .sousuo .title a")
for (var index = 0;index<items.length;index++){
let item = items[index];
addImages(item,host,this)
}
},
loadTitle:()=>{
return $(".f-22")[0].innerText;
},
loadPages:()=>{
var newStr = self.location.origin;
let pageUrls = []
let pagination = $(".pagebar")[0];
let pages = $("a", pagination)
for (var i = 0; i < pages.length; i++) {
var page = pages[i];
if (page.innerText == "上一页" || page.innerText == "下一页") {
} else {
let next = newStr + $(page).attr("href")
pageUrls.push(next)
}
}
return pageUrls;
},
imgPattern:".info-imtg-box p img"
},
"xiuren009":{
loadThumbnail:()=>{
var host = self.location.origin;
let addImages;
let items;
console.log(this.imgPattern)
addImages = (info,host,document)=>{
var url = info.getAttribute("href")
let pageUrl = url
$.get(pageUrl,function (data) {
var nImages = $(".main_inner .content p img", data);
for (var index = 0; index < nImages.length; index++) {
var origin = nImages[index];
origin.style.cssText = "width:200px"
info.append(origin)
}
})
}
items = $(".node .sousuo .title a")
for (var index = 0;index<items.length;index++){
let item = items[index];
addImages(item,host,this)
}},
loadTitle:()=>{
return $("title")[0].innerText;
},
loadPages:()=>{
var newStr = self.location.origin;
let pageUrls = []
let pagination = $(".page")[0];
let pages = $("a", pagination)
for (var i = 0; i < pages.length; i++) {
var page = pages[i];
if (page.innerText == "上一页" || page.innerText == "下页") {
} else {
let subfix=$(page).attr("href")
if(subfix){
let next = newStr + subfix
pageUrls.push(next)
}
}
}
return pageUrls
},
imgPattern:".main_inner .content p img"
},
"xgmn5":{
loadThumbnail:()=>{
var host = self.location.origin;
let addImages;
let items;
addImages = (info,host,document)=>{
var url = info.getAttribute("href")
let pageUrl = url
$.get(pageUrl,function (data) {
var nImages = $(".article-content p img", data);
for (var index = 0; index < nImages.length; index++) {
var origin = nImages[index];
origin.style.cssText = "width:200px"
info.append(origin)
}
})
}
items = $(".node .description p a")
for (var index = 0;index<items.length;index++){
let item = items[index];
addImages(item,host,this)
}},
loadTitle:()=>{
var meta = $(".article-meta span a")[0].innerText
var title = $(".article-title")[0].innerText
return meta+"-"+title
},
loadPages:()=>{
var newStr = self.location.origin;
let pageUrls = []
let pagination = $(".pagination")[0];
let pages = $("ul a", pagination)
for (var i = 0; i < pages.length; i++) {
var page = pages[i];
if (page.innerText == "上一页" || page.innerText == "下一页") {
} else {
let next = newStr + $(page).attr("href")
pageUrls.push(next)
}
}
return pageUrls
},
imgPattern:".article-content p img"
},
"xinggan5":{
loadThumbnail:()=>{
var host = self.location.origin;
let addImages;
let items;
addImages = (info,host,document)=>{
var url = info.getAttribute("href")
let pageUrl = url
$.get(pageUrl,function (data) {
var nImages = $(".article-content p img", data);
for (var index = 0; index < nImages.length; index++) {
var origin = nImages[index];
origin.style.cssText = "width:200px"
info.append(origin)
}
})
}
items = $(".node .description p a")
for (var index = 0;index<items.length;index++){
let item = items[index];
addImages(item,host,this)
}},
loadTitle:()=>{
var meta = $(".article-meta span a")[0].innerText
var title = $(".article-title")[0].innerText
return meta+"-"+title
},
loadPages:()=>{
var newStr = self.location.origin;
let pageUrls = []
let pagination = $(".pagination")[0];
let pages = $("ul a", pagination)
for (var i = 0; i < pages.length; i++) {
var page = pages[i];
if (page.innerText == "上一页" || page.innerText == "下一页") {
} else {
let next = newStr + $(page).attr("href")
pageUrls.push(next)
}
}
return pageUrls
},
imgPattern:".article-content p img"
}
}
function searchWebObject(origin){
let key = origin.split(".")[1];
return streams[key]
}
function loadDetailPage(){
console.log("start loading")
initStyle();
'use strict';
console.log("start parsing urls")
let obj = searchWebObject(webHost)
let pageUrls = obj.loadPages()
console.log(pageUrls);
let allImagesP = []
var nImages = $(obj.imgPattern);
for (var index = 1; index < nImages.length; index++) {
var item = $(nImages[index]);
allImagesP.push({index: 0 + "." + index, data: item[0]})
}
console.log(allImagesP);
console.log("start parsing pages")
thumbTitle = obj.loadTitle()
initShowPages()
createButton("下载原图",()=>{
handleBatchDownload(allImagesP,thumbTitle)
})
createButton("切换尺寸",()=>{
if(photoSize==200){
photoSize = 400
}else if(photoSize == 400){
photoSize = 600
}else if(photoSize == 600){
photoSize = 1200
}else if(photoSize == 1200){
photoSize = 200
}
for (var i = 0; i < allImagesP.length; i++) {
var item = $(allImagesP[i].data);
item.attr("width", photoSize);
item.attr("style", "float:left;");
}
})
convertPage.append(imageViewer);
console.log("start load images")
new Promise((ret,reject)=>{
for (var j = 0; j < pageUrls.length; j++) {
downloadCnt++;
var p = pageUrls[j];
requestChildUrl(obj,j, p, allImagesP)
}
ret(true)
}).then((res)=>{
if(allImagesP.length == 0){
switchBtn.click();
}
var inter = setInterval(() => {
if (downloadCnt == 0) {
allImagesP.sort(function (a, b) {
return parseFloat(a.index) - parseFloat(b.index)
})
for (var i = 0; i < allImagesP.length; i++) {
var item = $(allImagesP[i].data);
var imgli = $('<li></li>');
item.attr("width", photoSize);
item.attr("style", "float:left;");
imgli = imgli.append(item);
imageViewer.append(imgli)
}
clearInterval(inter)
}
}, 100)
})
}
function requestChildUrl(webObj,i, page, list) {
$.get(page, function (data) {
var nImages = $(webObj.imgPattern,data)
for (var index = 0; index < nImages.length; index++) {
var item = $(nImages[index]);
list.push({index: i + "." + index, data: item[0]})
}
downloadCnt--;
})
}
function getBase64(image) {
return new Promise((resolve) => {
try {
GM_xmlhttpRequest({
method: "get",
url: image.src,
responseType: "blob",
onload: function (r) {
var blob = r.response;
let oFileReader = new FileReader();
oFileReader.onloadend = function (e) {
let base64 = e.target.result;
if (base64.startsWith("data:image")) {
// zipFilteredImgUrls[urlIndex] = base64;
//zipImgWaitDownload.push(base64);
resolve(base64)
}
};
oFileReader.readAsDataURL(blob);
}
});
} catch (e) {
console.log(e)
}
});
}
// 批量下载
let handleBatchDownload = async (selectImgList,saveName) => {
const data = selectImgList;
try {
var zipFolder = new JSZip();
var zipSubFoler = zipFolder.folder(saveName);
} catch {
}
const cache = {}
const promises = []
await data.forEach(item => {
const promise = getBase64(item.data).then(img => { // 下载文件, 并存成ArrayBuffer对象
try {
let fileExt = img.substring(img.indexOf("image/") + 6, img.indexOf(";"))
fileExt = fileExt.includes("svg") ? "svg" : fileExt;
let filename = `${item.index}.${fileExt}`;
zipSubFoler.file(filename, img.split(",")[1], {base64: true});
console.log("正在转换",filename);
} catch (e) {
console.log("生成base64出错:",e)
}
})
promises.push(promise)
})
Promise.all(promises).then(() => {
console.log("zip started");
zipFolder.generateAsync({type: "blob"})
.then(function (content) {
console.log("zip success!");
// see FileSaver.js
saveAs(content, `${saveName}.zip`);
zipFolder.remove(saveName);
zipSubFoler = zipFolder.folder(saveName);
});
// zip.generateAsync({
// type: "blob"
// }).then(content => { // 生成二进制流
// saveAs(content, "photo.zip") // 利用file-saver保存文件
// })
})
};
//初始化样式
let initStyle = ()=>{
let addStyle = function (aCss) {
let head = document.getElementsByTagName('head')[0];
if (head) {
let style = document.createElement('style');
style.setAttribute('type', 'text/css');
style.textContent = aCss;
head.appendChild(style);
return style;
}
return null;
}
addStyle(`.viewer-close:before,.viewer-flip-horizontal:before,.viewer-flip-vertical:before,.viewer-fullscreen-exit:before,.viewer-fullscreen:before,.viewer-next:before,.viewer-one-to-one:before,.viewer-play:before,.viewer-prev:before,.viewer-reset:before,.viewer-rotate-left:before,.viewer-rotate-right:before,.viewer-zoom-in:before,.viewer-zoom-out:before{background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARgAAAAUCAYAAABWOyJDAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTNui8sowAAAQPSURBVHic7Zs/iFxVFMa/0U2UaJGksUgnIVhYxVhpjDbZCBmLdAYECxsRFBTUamcXUiSNncgKQbSxsxH8gzAP3FU2jY0kKKJNiiiIghFlccnP4p3nPCdv3p9778vsLOcHB2bfveeb7955c3jvvNkBIMdxnD64a94GHMfZu3iBcRynN7zAOI7TG15gHCeeNUkr8zaxG2lbYDYsdgMbktBsP03jdQwljSXdtBhLOmtjowC9Mg9L+knSlcD8TNKpSA9lBpK2JF2VdDSR5n5J64m0qli399hNFMUlpshQii5jbXTbHGviB0nLNeNDSd9VO4A2UdB2fp+x0eCnaXxWXGA2X0au/3HgN9P4LFCjIANOJdrLr0zzZ+BEpNYDwKbpnQMeAw4m8HjQtM6Z9qa917zPQwFr3M5KgA6J5rTJCdFZJj9/lyvGhsDvwFNVuV2MhhjrK6b9bFiE+j1r87eBl4HDwCF7/U/k+ofAX5b/EXBv5JoLMuILzf3Ap6Z3EzgdqHMCuF7hcQf4HDgeoHnccncqdK/TvSDWffFXI/exICY/xZyqc6XLWF1UFZna4gJ7q8BsRvgd2/xXpo6P+D9dfT7PpECtA3cnWPM0GXGFZh/wgWltA+cDNC7X+AP4GzjZQe+k5dRxuYPeiuXU7e1qwLpDz7dFjXKRaSwuMLvAlG8zZlG+YmiK1HoFqT7wP2z+4Q45TfEGcMt01xLoNZEBTwRqD4BLpnMLeC1A41UmVxsXgXeBayV/Wx20rpTyrpnWRft7p6O/FdqzGrDukPNtkaMoMo3FBdBSQMOnYBCReyf05s126fU9ytfX98+mY54Kxnp7S9K3kj6U9KYdG0h6UdLbkh7poFXMfUnSOyVvL0h6VtIXHbS6nOP+s/Zm9mvyXW1uuC9ohZ72E9uDmXWLJOB1GxsH+DxPftsB8B6wlGDN02TAkxG6+4D3TWsbeC5CS8CDFce+AW500LhhOW2020TRjK3b21HEmgti9m0RonxbdMZeVzV+/4tF3cBpP7E9mKHNL5q8h5g0eYsCMQz0epq8gQrwMXAgcs0FGXGFRcB9wCemF9PkbYqM/Bas7fxLwNeJPdTdpo4itQti8lPMqTpXuozVRVXPpbHI3KkNTB1NfkL81j2mvhDp91HgV9MKuRIqrykj3WPq4rHyL+axj8/qGPmTqi6F9YDlHOvJU6oYcTsh/TYSzWmTE6JT19CtLTJt32D6CmHe0eQn1O8z5AXgT4sx4Vcu0/EQecMydB8z0hUWkTd2t4CrwNEePqMBcAR4mrBbwyXLPWJa8zrXmmLEhNBmfpkuY2102xxrih+pb+ieAb6vGhuA97UcJ5KR8gZ77K+99xxeYBzH6Q3/Z0fHcXrDC4zjOL3hBcZxnN74F+zlvXFWXF9PAAAAAElFTkSuQmCC");background-repeat:no-repeat;background-size:280px;color:transparent;display:block;font-size:0;height:20px;line-height:0;width:20px}.viewer-zoom-in:before{background-position:0 0;content:"Zoom In"}.viewer-zoom-out:before{background-position:-20px 0;content:"Zoom Out"}.viewer-one-to-one:before{background-position:-40px 0;content:"One to One"}.viewer-reset:before{background-position:-60px 0;content:"Reset"}.viewer-prev:before{background-position:-80px 0;content:"Previous"}.viewer-play:before{background-position:-100px 0;content:"Play"}.viewer-next:before{background-position:-120px 0;content:"Next"}.viewer-rotate-left:before{background-position:-140px 0;content:"Rotate Left"}.viewer-rotate-right:before{background-position:-160px 0;content:"Rotate Right"}.viewer-flip-horizontal:before{background-position:-180px 0;content:"Flip Horizontal"}.viewer-flip-vertical:before{background-position:-200px 0;content:"Flip Vertical"}.viewer-fullscreen:before{background-position:-220px 0;content:"Enter Full Screen"}.viewer-fullscreen-exit:before{background-position:-240px 0;content:"Exit Full Screen"}.viewer-close:before{background-position:-260px 0;content:"Close"}.viewer-container{-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;bottom:0;direction:ltr;font-size:0;left:0;line-height:0;overflow:hidden;position:absolute;right:0;top:0;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.viewer-container::-moz-selection,.viewer-container ::-moz-selection{background-color:transparent}.viewer-container::selection,.viewer-container ::selection{background-color:transparent}.viewer-container:focus{outline:0}.viewer-container img{display:block;height:auto;max-height:none!important;max-width:none!important;min-height:0!important;min-width:0!important;width:100%}.viewer-canvas{bottom:0;left:0;overflow:hidden;position:absolute;right:0;top:0}.viewer-canvas>img{height:auto;margin:15px auto;max-width:90%!important;width:auto}.viewer-footer{bottom:0;left:0;overflow:hidden;position:absolute;right:0;text-align:center}.viewer-navbar{background-color:rgba(0,0,0,.5);overflow:hidden}.viewer-list{-webkit-box-sizing:content-box;box-sizing:content-box;height:50px;margin:0;overflow:hidden;padding:1px 0}.viewer-list>li{color:transparent;cursor:pointer;float:left;font-size:0;height:50px;line-height:0;opacity:.5;overflow:hidden;-webkit-transition:opacity .15s;transition:opacity .15s;width:30px}.viewer-list>li:focus,.viewer-list>li:hover{opacity:.75}.viewer-list>li:focus{outline:0}.viewer-list>li+li{margin-left:1px}.viewer-list>.viewer-loading{position:relative}.viewer-list>.viewer-loading:after{border-width:2px;height:20px;margin-left:-10px;margin-top:-10px;width:20px}.viewer-list>.viewer-active,.viewer-list>.viewer-active:focus,.viewer-list>.viewer-active:hover{opacity:1}.viewer-player{background-color:#000;bottom:0;cursor:none;display:none;right:0;z-index:1}.viewer-player,.viewer-player>img{left:0;position:absolute;top:0}.viewer-toolbar>ul{display:inline-block;margin:0 auto 5px;overflow:hidden;padding:6px 3px}.viewer-toolbar>ul>li{background-color:rgba(0,0,0,.5);border-radius:50%;cursor:pointer;float:left;height:24px;overflow:hidden;-webkit-transition:background-color .15s;transition:background-color .15s;width:24px}.viewer-toolbar>ul>li:focus,.viewer-toolbar>ul>li:hover{background-color:rgba(0,0,0,.8)}.viewer-toolbar>ul>li:focus{-webkit-box-shadow:0 0 3px #fff;box-shadow:0 0 3px #fff;outline:0;position:relative;z-index:1}.viewer-toolbar>ul>li:before{margin:2px}.viewer-toolbar>ul>li+li{margin-left:1px}.viewer-toolbar>ul>.viewer-small{height:18px;margin-bottom:3px;margin-top:3px;width:18px}.viewer-toolbar>ul>.viewer-small:before{margin:-1px}.viewer-toolbar>ul>.viewer-large{height:30px;margin-bottom:-3px;margin-top:-3px;width:30px}.viewer-toolbar>ul>.viewer-large:before{margin:5px}.viewer-tooltip{background-color:rgba(0,0,0,.8);border-radius:10px;color:#fff;display:none;font-size:12px;height:20px;left:50%;line-height:20px;margin-left:-25px;margin-top:-10px;position:absolute;text-align:center;top:50%;width:50px}.viewer-title{color:#ccc;display:inline-block;font-size:12px;line-height:1;margin:0 5% 5px;max-width:90%;opacity:.8;overflow:hidden;text-overflow:ellipsis;-webkit-transition:opacity .15s;transition:opacity .15s;white-space:nowrap}.viewer-title:hover{opacity:1}.viewer-button{background-color:rgba(0,0,0,.5);border-radius:50%;cursor:pointer;height:80px;overflow:hidden;position:absolute;right:-40px;top:-40px;-webkit-transition:background-color .15s;transition:background-color .15s;width:80px}.viewer-button:focus,.viewer-button:hover{background-color:rgba(0,0,0,.8)}.viewer-button:focus{-webkit-box-shadow:0 0 3px #fff;box-shadow:0 0 3px #fff;outline:0}.viewer-button:before{bottom:15px;left:15px;position:absolute}.viewer-fixed{position:fixed}.viewer-open{overflow:hidden}.viewer-show{display:block}.viewer-hide{display:none}.viewer-backdrop{background-color:rgba(0,0,0,.5)}.viewer-invisible{visibility:hidden}.viewer-move{cursor:move;cursor:-webkit-grab;cursor:grab}.viewer-fade{opacity:0}.viewer-in{opacity:1}.viewer-transition{-webkit-transition:all .3s;transition:all .3s}@-webkit-keyframes viewer-spinner{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}@keyframes viewer-spinner{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}.viewer-loading:after{-webkit-animation:viewer-spinner 1s linear infinite;animation:viewer-spinner 1s linear infinite;border:4px solid hsla(0,0%,100%,.1);border-left-color:hsla(0,0%,100%,.5);border-radius:50%;content:"";display:inline-block;height:40px;left:50%;margin-left:-20px;margin-top:-20px;position:absolute;top:50%;width:40px;z-index:1}@media (max-width:767px){.viewer-hide-xs-down{display:none}}@media (max-width:991px){.viewer-hide-sm-down{display:none}}@media (max-width:1199px){.viewer-hide-md-down{display:none}}`)
addStyle('ul li{list-style-type:none;}');
}
let createButton = (name,event)=>{
let button = $(`<button style="margin-bottom:4px;border:1px solid #fff">${name}</button>`)
button.on("click",event)
toolBox.append(button)
return button
}
let initShowPages = ()=>{
imageViewer = $('<ul id ="viewer"></ul>');
convertPage = $('<div style="position:fixed;left:0;top:0px;right:0;bottom:0;width:100%;height:100%;overflow:auto;background-color:white;z-index:998"></div>');
toolBox = $('<div style="position:fixed;top:100px;right:30px;z-index:999;display:flex;flex-direction:column;"></div>')
switchBtn = createButton("切换显示",()=>{
if(convertPage){
let container = convertPage[0];
let status = container.style.display
if(status=="inline" || !status){
container.style.display = "none"
}else {
container.style.display = 'inline'
}
}
})
$("body").append(toolBox);
$("body").append(convertPage);
$("header").remove()
$(".header").remove()
setTimeout(() => {
new Viewer(document.getElementById('viewer'),{viewed(){}})
}, 3000);
}
setTimeout(function () {
var str3 = self.location.href.toString();
webHost = self.location.origin;
if(str3.indexOf("/plus/search")!=-1){
searchWebObject(webHost).loadThumbnail()
}else{
loadDetailPage();
}
},0)