// ==UserScript==
// @name MrCong全量加載
// @namespace http://tampermonkey.net/
// @version 0.42
// @description mrCong全量加載,啦啦啦
// @author LARA_SSR
// @match https://mrcong.com/*/
// @exclude https://mrcong.com/tag/*
// @exclude https://mrcong.com/category/*
// @exclude https://mrcong.com/sets/*
// @exclude https://mrcong.com/top*/*
// @exclude https://mrcong.com/tim-kiem/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// @license MIT
// @require https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
// @require https://cdn.staticfile.org/viewerjs/1.10.4/viewer.min.js
// ==/UserScript==
(async function () {
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;
}
let addScriptModule = function (aScript) {
let head = document.getElementsByTagName('head')[0];
if (head) {
let script = document.createElement('script');
script.setAttribute('type', 'module');
script.textContent = aScript;
head.appendChild(script);
return script;
}
return null;
}
let addScript = function (aScript) {
let head = document.getElementsByTagName('head')[0];
if (head) {
let script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.textContent = aScript;
head.appendChild(script);
return script;
}
return null;
}
async function addScriptCss() {
let fancyboxLink = "https://cdn.jsdelivr.net/npm/@fancyapps/ui@4.0/dist/fancybox.css";
let fancyboxData = await Get(fancyboxLink);
addStyle(fancyboxData);
}
// let addScriptCssResult = await addScriptCss();
addScriptCss();
let open = 'Default';
switch (open) {
case 'Fullscreen':
addStyle(`
a[data-fancybox] img{cursor:zoom-in}
.fancybox__container{--carousel-button-bg:rgb(0 0 0 / 44%);--carousel-button-svg-width:24px;--carousel-button-svg-height:24px;--carousel-button-svg-stroke-width:2.5;--carousel-button-svg-filter:none}
.fancybox__nav{--carousel-button-svg-width:22px;--carousel-button-svg-height:22px;--carousel-button-svg-stroke-width:3}
.fancybox__nav .carousel__button.is-prev{left:30px}
.fancybox__nav .carousel__button.is-next{right:30px}
.carousel__button.is-close{top:30px;right:30px}
.fancybox__slide{padding:0}
.fancybox__thumbs{position:absolute;bottom:0;left:0;right:0;z-index:10}
.fancybox__thumbs .carousel__slide{padding:20px 10px;overflow:visible}
.fancybox__thumb{border-radius:6px;box-shadow:0 4px 6px -1px rgba(0,0,0,0.3),0 2px 4px -1px rgba(0,0,0,0.26)}
.is-nav-selected .fancybox__thumb{transform:scale(1.25)}
.is-nav-selected .fancybox__thumb::after{display:none}
`);
addScriptModule(`
import{Fancybox}from"https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.esm.js";Fancybox.bind('[data-fancybox="images"]',{Toolbar:false,animated:false,dragToClose:false,showClass:false,hideClass:false,closeButton:"top",Image:{click:"close",wheel:"slide",zoom:false,fit:"cover",},Thumbs:{minScreenHeight:0,},});
`);
break;
case 'Default':
addStyle(`
a[data-fancybox] img{cursor:zoom-in;}
`);
addScriptModule(`
import{Fancybox}from"https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.esm.js";Fancybox.bind('[data-fancybox="images"]',{Thumbs:{Carousel:{fill:false,center:true,},},});
`);
break;
case 'Background':
addStyle(`
a[data-fancybox] img{cursor:zoom-in;}.fancybox__backdrop::after{content:"";position:absolute;width:10%;height:10%;filter:blur(2px);left:50%;top:50%;transform:scale(11);opacity:0.3;background-image:var(--bg-image);background-size:cover;background-repeat:no-repeat;background-position:center center;}.fancybox__container{--fancybox-bg:#000;--fancybox-thumbs-width:48px;--fancybox-thumbs-ratio:1;--carousel-button-bg:rgb(91 78 76 / 74%);--carousel-button-svg-width:24px;--carousel-button-svg-height:24px;--carousel-button-svg-stroke-width:2.5;}.fancybox__nav{--carousel-button-svg-width:24px;--carousel-button-svg-height:24px;}.fancybox__nav .carousel__button.is-prev{left:20px;}.fancybox__nav .carousel__button.is-next{right:20px;}.carousel__button.is-close{right:auto;top:20px;left:20px;}.fancybox__slide{padding:8px 88px;}.fancybox__thumbs .carousel__slide{padding:8px 8px 16px 8px;}.is-nav-selected::after{display:none;}.fancybox__thumb{border-radius:6px;opacity:0.4;}.fancybox__thumb:hover,.is-nav-selected .fancybox__thumb{border-radius:6px;opacity:1;}.is-nav-selected .fancybox__thumb::after{display:none;}
`)
addScriptModule(`
import{Fancybox}from"https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.esm.js";Fancybox.bind('[data-fancybox="images"]',{dragToClose:false,Toolbar:false,closeButton:"top",Image:{zoom:false,},on:{initCarousel:(fancybox)=>{const slide=fancybox.Carousel.slides[fancybox.Carousel.page];fancybox.$container.style.setProperty("--bg-image",\`url("\${slide.$thumb.src}")\`)},"Carousel.change":(fancybox,carousel,to,from)=>{const slide=carousel.slides[to];fancybox.$container.style.setProperty("--bg-image",\`url("\${slide.$thumb.src}")\`)},},});
`);
break;
case 'FollowCursor':
addStyle(`
a[data-fancybox]img{cursor:zoom-in;}.fancybox__container{--fancybox-color:#999;--fancybox-bg:#fff;--carousel-button-svg-width:32px;--carousel-button-svg-height:32px;--carousel-button-svg-stroke-width:1.2;--carousel-button-svg-filter:none;}.fancybox__nav{--carousel-button-svg-width:36px;--carousel-button-svg-height:36px;--carousel-button-svg-stroke-width:1;}.has-image[data-image-fit="contain-w"]{padding:0;overflow:hidden;}
`)
addScriptModule(`
import{Fancybox}from"https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.esm.js";Fancybox.bind('[data-fancybox="images"]',{animated:false,showClass:false,hideClass:false,dragToClose:false,closeButton:"top",Thumbs:false,Toolbar:false,Carousel:{Panzoom:{touch:false,},},Image:{zoom:false,wheel:false,click:"close",fit:"contain-w",},on:{ready:(fancybox,slide)=>{fancybox.clientY=(fancybox.options.event&&fancybox.options.event.clientY)||0;fancybox.$container.addEventListener("mousemove",(e)=>{fancybox.clientY=e.clientY;fancybox.trigger("mousemove");});},"done Carousel.change":(fancybox)=>{fancybox.trigger("mousemove");},mousemove:(fancybox)=>{const slide=fancybox.getSlide();if(!slide||!slide.$image||slide.state!=="done"){return;}
const $el=slide.$el;const imageHeight=slide.$image.clientHeight;const style=window.getComputedStyle($el);const paddingTop=parseFloat(style.paddingTop);const paddingBottom=parseFloat(style.paddingBottom);const viewportHeight=$el.clientHeight-paddingTop-paddingBottom;const pointerY=fancybox.clientY-paddingTop;$el.scrollTop=(pointerY*(imageHeight-viewportHeight))/viewportHeight;},},});
`);
break;
case 'ClassicDesign':
addStyle(`
a[data-fancybox] img{cursor:zoom-in;}.fancybox__container{--fancybox-bg:rgba(17,6,25,0.85);}.fancybox__container .fancybox__content{box-sizing:content-box;padding:1rem;background:#fff;border-radius:6px;color:#374151;box-shadow:0 8px 23px rgb(0 0 0 / 50%);}.fancybox__caption{max-width:80%;--fancybox-opacity:1;}
`)
addScriptModule(`
import{Fancybox}from"https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.esm.js";Fancybox.bind('[data-fancybox="images"]',{Thumbs:false,Toolbar:false,Image:{zoom:false,click:false,wheel:"slide",},});
`);
break;
};
//获取页数
let paginationClass = "div .page-link";
let length = 0;
let paginationExist = false;
$(paginationClass).each(function () {
if (paginationExist == true) {
return false;
}
length = $(this).find("a").length;
paginationExist = true;
//console.log(linkArr);
console.log("页数:" + length);
});
//标题
addStyle(`
.titleHrefs,.postTagHrefs {
border:1px solid;
border-radius:4px;
margin-bottom:1px;
}
#title_info {
color:pink;
border:1px solid;
border-color:rgba(0,0,0,0);
border-bottom-color:pink;
}
#separate {
color:white;
}
#downHref>a {
color:pink;
border:1px solid;
border-color:rgba(0,0,0,0);
border-bottom-color:#815c94;
}
.titleHrefs>div,.postTagHrefs>div {
display:inline;
}
#spanitemdiv {
color:#FFFAF0;
}
#spanitem {
color:#FFFAF0;
}
`);
let titleHrefs = $("<div class = titleHrefs></div>");
let postTagHrefs = $("<div class = postTagHrefs></div>");
await new Promise(function (resolve) {
$("#crumbs a").each(function (index, value) {
let hrefDiv = $("<div class = hrefDiv></div>")
let title = $(this).attr("id", "title_info");
hrefDiv.append(title)
titleHrefs.append(hrefDiv);
// console.log(title);
let p3 = $("<div id = separate>\xa0/\xa0</div>");
titleHrefs.append(p3);
});
$(".post-tag a").each(function (index, value) {
let hrefDiv = $("<div class = hrefDiv></div>")
let title = $(this).attr("id", "title_info");
hrefDiv.append(title)
postTagHrefs.append(hrefDiv);
// console.log(title);
let p3 = $("<div id = separate>\xa0/\xa0</div>");
postTagHrefs.append(p3);
});
resolve();
});
let password = $("strong+input[value]").attr('value');
console.log("Password: " + password);
let patt = /(?<=Dung lượng: )(\d+|([1-9]\d*\.?\d+))[A-Za-z]*(B|b)/g
let inerBoxStr = $(".box-inner-block").text()
// console.log(inerBoxStr);
let imgSize = inerBoxStr.match(patt)[0];
console.log(imgSize);
let downHref;
let p3;
//let p3 =$("<b id = separate>\xa0/\xa0</b>")
$("p[style] a").each(function (index, value) {
downHref = $("<div id = downHref></div>");
let itemTitleHref = $("<a>图片下载</a>").attr("href", $(this)[0].href).text(`图片下载链接[ ${index+1} ]`);
downHref.append(itemTitleHref);
titleHrefs.append(downHref);
p3 = $("<div id = separate>\xa0/\xa0</div>");
downHref.after(p3);
})
//titleHrefs.append(p3)
p3 = $("<div id = separate>\xa0/\xa0</div>");
titleHrefs.append($("<div id = spanitem></div>").text(`解压密码: (${password})`))
p3 = $("<div id = separate>\xa0/\xa0</div>");
titleHrefs.append(p3);
titleHrefs.append($("<div id = spanitem></div>").text(`图片大小: (${imgSize})`))
p3 = $("<div id = separate>\xa0/\xa0</div>");
titleHrefs.append(p3);
let SpanItemDiv = $("<div id = spanitemdiv></div>")
let spanItem = $("span[itemprop]").text();
// console.log(spanItem);
SpanItemDiv.append(spanItem);
titleHrefs.append(SpanItemDiv);
addStyle(`
ul li {
list-style-type:none;
}
body {
background:#4a4035;
font-family:-apple-system,BlinkMacSystemFont,Tahoma,Arial,"Hiragino Sans GB","Microsoft YaHei",sans-serif;
}
#viewer {
padding:0px;
margin:0px;
}
.imgbox {
width:100%;
position:relative;
overflow:hidden;
box-sizing:border-box;
padding:1px;
}
.imgnum {
position:absolute;
font-size:90%;
left:5px;
top:5px;
background:#17A1FF;
background:rgba(23,161,255,0.5);
z-index:100;
padding:0px 5px 1px 5px;
color:#f9f9f9;
color:rgba(249,249,249,1);
border-radius:2px;
}
.imgs {
width:100%;
float:left;
border-radius:4px;
}
`);
var os = function () {
var ua = navigator.userAgent, //获取浏览器UA
isWindowsPhone = /(?:Windows Phone)/.test(ua),
isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone,
isAndroid = /(?:Android)/.test(ua),
isFireFox = /(?:Firefox)/.test(ua),
isChrome = /(?:Chrome|CriOS)/.test(ua),
isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox && /(?:Tablet)/.test(ua)),
isPhone = /(?:iPhone)/.test(ua) && !isTablet,
isPc = !isPhone && !isAndroid && !isSymbian;
return {
isTablet: isTablet,
isPhone: isPhone,
isAndroid: isAndroid,
isPc: isPc
};
}();
if (os.isAndroid) //判断是否Android
{
addStyle(`
body{
font-family: fantasy,sans-serif;
}`);
}
'use strict';
$("body").empty();
let i = 1;
let str3 = self.location.href;
let newStr = str3.replace(/-anh.+/g, "");
let link = "";
let viewer2 = $('<ul id ="viewer"></ul>');
$("body").append(viewer2);
viewer2.append(titleHrefs);
let n = 0;
do {
link = newStr + "-anh/" + i;
let data = await Get(link);
let image = $(".content img", data);
image.each(function (index, item) {
n++;
let imgli = $('<li class = "imgbox"></li>');
let imageItem = '<a data-fancybox="images" href="' + $(this)[0].src + '"><img width= "100%" style="float: left;border-radius: 8px; margin: 1px" src="' + $(this)[0].src + '" ></a>';
//序号
let stringNum = "<div class = 'imgnum'>{imgnum}</div>";
let newStringNum = stringNum.replace('{imgnum}', `${n}`)
imgli = imgli.prepend($(newStringNum));
imgli = imgli.append(imageItem);
viewer2.append(imgli)
});
i = i + 1;
if (i === (length + 2)) {
$(document).ready(function () {
$("#viewer").after(postTagHrefs);
});
}
} while (i < length + 2);
// setTimeout(() => {
// let viewer3 = new Viewer(document.getElementById('viewer'), {
// //inline:true,
// viewed() {}
// });
// }, 3000);
// Your code here...
let imgCount = $("#viewer img").length;
console.log("imgCount: " + imgCount);
$(".imgnum").each(function (index, value) {
if (index < imgCount) {
// console.log($(this));
$(this).text(`[${index+1}/${imgCount}]`)
} else {
return false;
}
})
//删除标题最后一个"/"
$(document).ready(function () {
// $(".titleHrefs div").eq(-1).remove();
$(".postTagHrefs #separate").eq(-1).remove();
});
function Get(link) {
return new Promise(function (resolve) {
$.get(link, data => {
resolve(data);
})
});
}
})();