动漫之家
// ==UserScript==
// @name 动漫之家
// @namespace http://tampermonkey.net/
// @version 134
// @description 去除动漫之家日漫界面广告,改变阅读界面样式,增加目录功能,检测漫画是否屏蔽
// @author 52lcx
// @match https://manhua.idmzj.com/*
// @match https://www.idmzj.com/
// @icon https://www.google.com/s2/favicons?sz=64&domain=idmzj.com
// @resource animate_css https://cdn.jsdelivr.net/npm/animate.css@4.1.1/animate.min.css
// @resource element_css https://unpkg.com/element-ui@2.15.0/lib/theme-chalk/index.css
// @require https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.min.js
// @require https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js
// @require https://cdn.jsdelivr.net/npm/jquery.cookie@1.4.1/jquery.cookie.js
// @require https://cdn.jsdelivr.net/npm/jquery_lazyload@1.9.3/jquery.lazyload.min.js
// @require https://unpkg.com/element-ui@2.15.0/lib/index.js
// @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js
// @run-at document-start
// @connect i.idmzj.com
// @license GNU General Public License v3.0 or later
// @grant GM_getResourceText
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @grant GM_download
// @grant unsafeWindow
// @connect images.idmzj.com
// @require https://scriptcat.org/lib/513/2.0.0/ElementGetter.js
// ==/UserScript==
// 跳转到日漫页面
if (window.location.href == 'https://www.idmzj.com/') { window.location.href = 'https://manhua.idmzj.com/' }
//漫画加载时自动滚动到顶部
if(location.href.match(/\d+/)){
window.scrollTo(0,0)}
//删除二维码
GM_addStyle('img[src="https://static.dmzj.com/public/images/app_tro_manhua.jpg"] { visibility: hidden !important; }');
GM_addStyle('a[href="http://www.dmzj.com/app/pc.html"] { pointer-events: none !important; cursor: default !important; }');
//去广告
var ad_list = ["#index_ad", "#ad_iphone", "#ad_code_close", "#ads_right", "#adpc", ".float_code", "#left_ads", ".hotrmbox","#top_ads", "#ads-manhuaright",
"#ads-manhua", "#top_ad", "#conf_ad", ".header-box",, "#focus"];
for (var i = 0; i < ad_list.length; i++) {
GM_addStyle(ad_list[i] + " {display:none !important;}");
}
//日间模式
GM_addStyle(".mainNav,.header-box,.display_graybg,body,.dark_mode .newbody{background:#edecea !important;}")
//夜间模式
GM_addStyle(".dark_mode .mainNav,.dark_mode .header-box,.dark_mode .display_graybg,.dark_mode body,.dark_mode .newbody{background:#212121 !important;}")
//漫画双叶排布
GM_addStyle('.page_double .scrollbar-demo-item{justify-content:center;flex-direction: row-reverse;display: flex;flex-wrap: wrap;}')
GM_addStyle('.page_double .scrollbar-demo-item img{height:100vh !important;}')
elmGetter.each('.redhotl#prev_chapter', document, () => {
var link = document.querySelector('.redhotl#prev_chapter');
if (link) {
link.removeEventListener('click', caidan1);
link.addEventListener('click', function () {
$('html').removeClass('dark_mode')
$('#info').remove()
$('#sidebar').remove()
document.exitFullscreen();
})
}
});
var uid = localStorage.getItem("uidNumber");
look(uid)
elmGetter.each('.r1', document, () => {
// 获取漫画名称+uid+comic_py+url
var linkElements = document.getElementsByClassName("btn2");
if (linkElements.length > 0) {
var linkElement = linkElements[0];
var href = linkElement.getAttribute('href');
var text = href.split('/')[1];
}
if(!uid)
{var uidElement = $('p[data-v-687068a4].r1');
var hrefAttributeValue = uidElement.find('a[data-v-687068a4]').attr('href');
var uidNumber = hrefAttributeValue.match(/hisUid=(\d+)/);
var uid=uidNumber[1]
localStorage.setItem("uidNumber",uid)
}
var all_url = `https://manhua.idmzj.com/api/v1/comic2/comic/detail?uid=${uid}&comic_py=${text}`;
var comic=document.querySelector(".comic_gd_li")
if(comic)
{ console.log("存在")
mulu(all_url)}else{
console.log("不存在")
setTimeout(function(){
mulu(all_url)},5000)}
})
elmGetter.each('.scrollbar-demo-item', document, () => {
window.scrollTo(0, 0)
// 删除图片链接
var manga_name= location.href.match(/\/([a-z]+)\//)[1]// 获得了名字
var number = location.href.match(/\d+/)[0] // 获得了数字
localStorage.setItem(manga_name,number)
var links = document.querySelectorAll('a[id]');
links.forEach(function (link) {
link.removeAttribute("href");
})
var length = document.querySelector('.scrollbar-demo-item').querySelectorAll('a').length;
caidan1(length)
});
elmGetter.each('.cartoon_online_border', document, reply => {
/// 浏览历史
//检测漫画是否观看过
var page_name=location.href.match(/\/([a-z]+)\//)[1]
if(localStorage.getItem(page_name)){var k=localStorage.getItem(page_name)
var list_=[]
var currentMulu = document.querySelectorAll('.cartoon_online_border li a');
currentMulu.forEach(link => {
var li=link.href
var num=li.match(/\d+/)[0]
list_.push(num)
});
//找到index
var index=list_.findIndex(num=>num===k)
var real=currentMulu[index]
var name=real.textContent
var href=real.href
//创建链接
var a=document.createElement('a')
a.href=href
a.textContent=name
//创建表格
var tr=document.createElement('tr')
tr.innerHTML=`<th>上次看到:</th><td></td>`
tr.querySelector('td').append(a)
document.querySelector('.anim-main_list > table:nth-child(1) > tbody:nth-child(1)').append(tr)}
//*****************************//
var links = document.querySelectorAll('.cartoon_online_border a');
links.forEach(function (link) {
link.addEventListener('click', function () {
$('html').addClass('dark_mode');
});
});
});
//左右键切换章节
elmGetter.each('.display_right',document,()=>{
document.addEventListener('keydown', function(event) {
if (event.key === 'ArrowLeft') {
event.preventDefault();
document.querySelector(".display_left a").click();
}
if (event.key === 'ArrowRight') {
event.preventDefault();
document.querySelector(".display_right a").click();
}
});
})
if (location.href.search(/\/\d+\.shtml/) >= 0) {
$('html').addClass('dark_mode');
//预加载图片
$('img').lazyload();
}
if ($.cookie('dark_mode') === undefined) { $.cookie('dark_mode', true, { expires: 999999, path: '/' }); }
if ($.cookie('page_double') === undefined) { $.cookie('page_double', true, { expires: 999999, path: '/' }); }
if ($.cookie('fullscreen') === undefined) { $.cookie('fullscreen', true, { expires: 999999, path: '/' }) }
if ($.cookie('fanyemodeval') === undefined) { $.cookie('fanyemodeval', 2, { expires: 999999, path: '/' })}
function caidan1(length) {
//读取cookie
var dark_mode = $.cookie('dark_mode') == 'true';
var page_double = $.cookie('page_double') == 'true';
var fullscreen = $.cookie('fullscreen') == 'false';
var fanye = $.cookie('fanyemodeval') == '2'
//翻页模式
if (fanye) {
$.cookie('fanyemodeval', 2, { expires: 999999, path: '/' });
} else {
$.cookie('fanyemodeval', 1, { expires: 999999, path: '/' });
$('#info').remove()
}
var now_full = true;
document.addEventListener("contextmenu", function(event) {
if (now_full) {
info_app.full=false
document.documentElement.requestFullscreen();
now_full = false;
} else {
info_app.full=true
event.preventDefault();
document.exitFullscreen();
now_full = true;
}
});
//暗夜模式
if (dark_mode) {
$('html').addClass('dark_mode');
} else {
$('html').removeClass('dark_mode');
}
//双页显示
if (page_double) {
$('html').addClass('page_double');
} else {
$('html').removeClass('page_double');
}
function download(){
info_app.downloading=false
var script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.6.0/jszip.min.js';
script.onload = function() {
setTimeout(function(){
generateZip()},10000)
};
document.head.appendChild(script);
function generateZip() {
var zip = new JSZip();
var imgs = document.querySelectorAll(".scrollbar-demo-item img");
var links = [];
imgs.forEach(img => {
links.push(img.getAttribute("src"));
});
var text=document.head.querySelector("title").innerText.split(" ").slice(0,2).join(" ")
links.forEach(function(link, index) {
GM_xmlhttpRequest({
method: "GET",
url: link,
responseType: "arraybuffer",
onload: function(response) {
if (response.status == 200) {
zip.file(index + 1 + ".jpg", response.response, { binary: true });
info_app.count++;
console.log(info_app.count)
if (info_app.count == links.length) {
info_app.finish=false
info_app.count=0
zip.generateAsync({ type: "blob" }).then(function(content) {
var link = document.createElement('a');
link.download = text+'.zip';
link.href = window.URL.createObjectURL(content);
link.click();
});
}
}
info_app.finish=true
info_app.download=true
},
onerror:function(){alert("下载失败,请重试🤗")}
});
});
}
}
//获取当前页码
var imgs = $(".scrollbar-demo-item a img");
var last_img = imgs[length - 1]
window.addEventListener('wheel', ID)
function ID() {
imgs.each(function (i, img) {
// 判断鼠标位置是否在当前图片区域内
if (window.pageYOffset > img.offsetTop - 5 && window.pageYOffset < img.offsetTop + img.offsetHeight) {
info_app.img_id = i + 1;
if (pageYOffset > last_img.offsetTop + last_img.offsetHeight - 5) { info_app.img_id = length; }
}
});
};
setInterval(ID, 100);
Vue.directive('highlight-scale',{
bind(el,binding,vnode){
el.addEventListener('mouseover',function(){
this.style.transform="scale(1.2)";
this.style.textShadow = "0 0 10px #fff"; })
el.addEventListener('mouseleave',function(){
this.style.transform="scale(1.0)";
this.style.textShadow="none"
})
}})
let info = `
<div id="info" @mouseover="show=1" @mouseleave="show=0" >
<transition name="custom-classes-transition" enter-active-class="animate__animated animate__fadeIn" leave-active-class="animate__animated animate__fadeOut">
<template v-if="show"><div id="info_download" class="info_item" @click="switch_download" v-highlight-scale style="cursor:pointer:">{{message_download}}</div></template>
</transition>
<transition name="custom-classes-transition" enter-active-class="animate__animated animate__fadeIn" leave-active-class="animate__animated animate__fadeOut">
<template v-if="show"><div id="info_full" class="info_item" @click="switch_full" v-highlight-scale style="cursor:pointer:">{{message_full}}</div></template>
</transition>
<transition name="custom-classes-transition" enter-active-class="animate__animated animate__fadeIn" leave-active-class="animate__animated animate__fadeOut">
<template v-if="show"><div id="info_place" class="info_item" @click="switch_place" v-highlight-scale style="cursor:pointer;">{{message_place}}</div></template>
</transition>
<transition name="custom-classes-transition" enter-active-class="animate__animated animate__fadeIn" leave-active-class="animate__animated animate__fadeOut">
<template v-if="show"><div id="info_fanye" class="info_item" @click="switch_fanye" v-highlight-scale style="cursor:pointer;">{{message_fanye}}</div></template>
</transition>
<transition name="custom-classes-transition" enter-active-class="animate__animated animate__fadeIn" leave-active-class="animate__animated animate__fadeOut">
<template v-if="show"><div id="info_rtml" class="info_item" @click="switch_mulu" v-highlight-scale style="cursor:pointer;">{{message_mulu}}</div></template>
</transition>
<transition name="custom-classes-transition" enter-active-class="animate__animated animate__fadeIn" leave-active-class="animate__animated animate__fadeOut">
<template v-if="show"><div id="info_page" class="info_item" @click="switch_page" v-highlight-scale style="cursor:pointer;">{{message_page}}</div></template>
</transition>
<transition name="custom-classes-transition" enter-active-class="animate__animated animate__fadeIn" leave-active-class="animate__animated animate__fadeOut">
<template v-if="show"><div id="info_switch" class="info_item" @click="switch_night" v-highlight-scale style="cursor:pointer;">{{message_switch}}</div></template>
</transition>
<template><div id="info_count" class="info_item">{{message_count}}</div></template>
</div>`;
let $info = $(info);
$("body").append($info);
let info_style = `
#info {
bottom: 2%;
right: 2%;
padding: 5px 5px;
background: rgba(48,48,48,.7) !important;
position: fixed;
color: rgba(255,255,255,.7);
border-radius: 3px;
z-index:99999;
}
.info_item{
padding:5px 0px;
width:120px;
cursor: pointer;
}`;
GM_addStyle(info_style);
var info_app = new Vue({
el: '#info',
data: {
fanye: fanye,
full: fullscreen,
dark: dark_mode,
page: page_double,
show: 0,
finish:true,
img_id: 1,
img_id_all: length,
place:true,
full: true,
download:true,
downloading:true,
count:0
},
computed: {
message_download:function(){
return this.finish ? (this.download ? "🌐下载本话" : "正在下载" + this.count) : "🥰马上完成";
},
message_place:function(){
return this.place?"🔽直达底部":"🔼返回顶部"},
message_fanye: function () {
return this.fanye ? '↔左右翻页' : '↕上下翻页'
},
message_full: function () {
return this.full ? '🔒进入全屏' : '🔓退出全屏'
},
message_mulu: function () {
return ("📖返回目录")
},
message_switch: function () {
return this.dark ? '☀️日间模式' : '🌙夜间模式'
},
message_page: function () {
return this.page ? '1️⃣单页排布' : '2️⃣双页排布'
},
message_count: function () {
return this.img_id + '/' + length
},
},
methods: {
switch_download:function(){
this.finish=true
if(!info_app.downloading){alert("请勿重复点击😋")
return}
this.download=!this.download
if(!this.download){
download()
}
}
,
switch_place:function(){
this.place=!this.place
if(!this.place){window.scrollTo(0, document.body.scrollHeight);}
else{window.scrollTo(0,0)}
},
switch_fanye: function () {
this.fanye = !this.fanye
if (this.fanye) {
$.cookie('fanyemodeval', 2, { expires: 999999, path: '/' });
location.reload();
} else {
location.reload();
$('#info').remove()
$.cookie('fanyemodeval', 1, { expires: 999999, path: '/' });
}
}
,
switch_full: function () {
this.full = !this.full;
if (!this.full) {
document.documentElement.requestFullscreen();
} else {
document.exitFullscreen();
}
}
,
switch_mulu: function () {
document.querySelector("#prev_chapter.redhotl").click()
},
switch_night: function () {
this.dark = !this.dark
$.cookie('dark_mode', this.dark, { expires: 999999, path: '/' });
if (this.dark) {
$('html').addClass('dark_mode');
} else {
$('html').removeClass('dark_mode');
}
},
switch_page: function () {
this.page = !this.page
$.cookie('page_double', this.page, { expires: 999999, path: '/' });
if (this.page) {
$('html').addClass('page_double');
} else {
$('html').removeClass('page_double');
}
},
}
})
}
function mulu(all_url) {
//修改element-ui样式
GM_addStyle('.el-menu{border-right:0px !important;}')
GM_addStyle('.el-drawer__wrapper{width:20%;}')
GM_addStyle('.el-drawer{background:transparent !important;}')
GM_addStyle('.el-drawer__body{background:rgba(0,0,0,.8) !important;overflow-y: auto}')
const animate_css = GM_getResourceText("animate_css");
const element_css = GM_getResourceText("element_css");
GM_addStyle(animate_css);
GM_addStyle(element_css);
GM_addStyle(':root{--animate-duration:500ms;}');
let ch_id = 0;
var items = [];
//修改滚动条样式
GM_addStyle('::-webkit-scrollbar {width: 4px;height: 0px;}')
GM_addStyle('::-webkit-scrollbar-thumb {background-color: rgb(48,48,48);border-radius: 2px;}')
// 添加侧边目录栏
let sidebar = `
<div id="sidebar" @mouseleave="drawer=false">
<div id="toggle" @mouseover="drawer=true" v-highlight-scale style="top:0px;left:0px;height:100vh;width:200px;position: fixed;"></div>
<el-drawer
title="我是标题"
:size="size"
:modal="modal"
:visible="drawer"
:with-header="false"
:direction="direction"
@open="handleOpen"
>
<el-menu background-color="transparent" text-color="#fff" active-text-color="#ffd04b" @select="handleSelect">
<template v-for="(item, index) in items">
<el-menu-item :index="index.toString()" :class="{ 'selected-chapter': select === index }">{{item.title}}</el-menu-item>
</template>
</el-menu>
</el-drawer>
</div>`;
var isloading =false
let $sidebar = $(sidebar);
$("body").append($sidebar);
var sidebar_app = new Vue({
el: '#sidebar',
data: {
drawer: false,
size: '80%',
modal: false,
direction: 'ltr',
items: items,
select: -1,
index: 0
},
methods: {
handleSelect(key) {
var selectedChapter = this.items[key];
var chapterLink = document.querySelector(".btn2").href + selectedChapter.id + '.shtml#1';
location.href = chapterLink;
this.select = key;
GM_addStyle('.el-menu>li:nth-child(' + (parseInt(this.select) + 1) + '){background:rgba(255,165,0,.5) !important}');
},
handleOpen() {
var chapter_all = null;
if(isloading){
move()
return}
open()
function open() {
if (chapter_all) {
processChapterList(chapter_all);
} else if(!isloading){
isloading=true
// 加载目录数据
$.ajax({
url: all_url,
success: function (data) {
chapter_all = data.data.comicInfo.chapterList;
processChapterList(chapter_all);
},
});
}
}
function processChapterList(chapterList) {
chapterList.forEach(function (chapter) {
chapter.data.forEach(function (chapterData) {
items.unshift({
title: chapterData.chapter_title,
id: chapterData.chapter_id,
});
});
});
move()
}
function move(){
if(!items){return}
var old_url=""
var new_url=location.href
if(old_url==new_url){
sidebar_app.index = index;
for (let i = 1; i <= items.length; i++) {
GM_addStyle('.el-menu>li:nth-child(' + i + '){background:transparent !important}');}
GM_addStyle('.el-menu>li:nth-child(' + (index + 1) + '){background:rgba(255,165,0,.5) !important}');scroll(index);}
else
{ const url = location.href
const match = url.match(/\/(\d+)\.shtml/);
if (match && match[1]) {
const number = match[1];
var index = items.findIndex(item => item.id == number);
if (index != -1) {
sidebar_app.index = index;
for (let i = 1; i <= items.length; i++) {
GM_addStyle('.el-menu>li:nth-child(' + i + '){background:transparent !important}');
}
GM_addStyle('.el-menu>li:nth-child(' + (index + 1) + '){background:rgba(255,165,0,.5) !important}');
}
scroll(index);
}}}
function scroll(index) {
setTimeout(function(){
$('.el-drawer__body').animate({scrollTop:0}, 0);
$('.el-drawer__body').animate({scrollTop:$('.el-menu>li:nth-child('+(index-1)+')').offset().top-$('.el-drawer__body').offset().top}, 100);
},0)
}
}
,
},
});
}
//检测漫画是否屏蔽
var last =""
function look(uid){
if(uid==null){return}
var titles = [];
var links = document.querySelectorAll(".pictextst");
if(links.length==0){return}
var now=links[links.length - 1].textContent.trim();
links.forEach(function(link) {
titles.push(link.textContent);
});
if(now==last){return}else{
remove_txt()
}
last=now
var move=false
window.scrollTo(0,0)
var links1 = document.querySelectorAll(".picborder a");
links1.forEach((link1) => {
var text = link1.getAttribute("href").split("/");
var look_url = `https://manhua.idmzj.com/api/v1/comic2/comic/detail?uid=${uid}&comic_py=${text[1]}`;
fetch(look_url)
.then((response) => response.json())
.then((jsonData) => {
var list = jsonData.data.comicInfo;
if (list.chapterList === null) {
var index = titles.findIndex(title => title === list.title);
if (index !== -1) {
add_txt(index); // 添加标记
}
}
});
});
}
function add_txt(index) {
var element = document.querySelectorAll(".numfont")[index];
if (!element.nextSibling) {
var span = document.createElement("span");
span.appendChild(document.createTextNode("已被屏蔽"));
span.className = "add_txt";
span.style.textAlign = "right";
span.style.marginRight = "60px";
span.style.color = "#000";
element.parentNode.insertBefore(span, element.nextSibling);
}
}
function remove_txt(){
var spans=document.querySelectorAll(".add_txt")
spans.forEach(span=>{span.remove()})
}
elmGetter.each(".mhupdate", document, () => {
setInterval(function(){look(uid)}, 3000);
});