// ==UserScript== // @name 拷贝漫画PC显示评论 // @namespace http://tampermonkey.net/ // @version 1.4 // @description 改自Byaidu的拷贝漫画增强插件,只保留评论的加载和发送功能,并重做了ui // @author ljw2487 // @match *://*.copymanga.com/* // @match *://*.copymanga.org/* // @match *://*.copymanga.net/* // @match *://*.copymanga.info/* // @match *://*.copymanga.site/* // @match *://*.copymanga.tv/* // @match *://copymanga.com/* // @match *://copymanga.org/* // @match *://copymanga.net/* // @match *://copymanga.info/* // @match *://copymanga.site/* // @match *://copymanga.tv/* // @license GNU General Public License v3.0 or later // @resource element_css https://unpkg.com/element-ui@2.15.0/lib/theme-chalk/index.css // @resource animate_css https://unpkg.com/animate.css@4.1.1/animate.min.css // @require https://unpkg.com/vue@2.6.12/dist/vue.min.js // @require https://unpkg.com/element-ui@2.15.0/lib/index.js // @require https://unpkg.com/axios@0.27.2/dist/axios.min.js // @require https://unpkg.com/store.js@1.0.4/store.js // @require https://unpkg.com/jquery@3.5.1/dist/jquery.min.js // @require https://unpkg.com/jszip@3.1.5/dist/jszip.min.js // @require https://unpkg.com/file-saver@2.0.5/dist/FileSaver.min.js // @require https://unpkg.com/crypto-js@4.1.1/crypto-js.js // @grant GM_addStyle // @grant GM_getResourceText // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @run-at document-body // @downloadURL none // ==/UserScript== // 更新了在漫画详情页显示已读章节的字样 // retry 拦截器 axios.interceptors.response.use(undefined, (err) => { return new Promise((resolve)=>{setTimeout(()=>{resolve()},1000)}).then(() => axios(err.config)); }); function route() { console.log('LOAD SUCCESSED', window.document.title) // /comic/gengjuesezhuanshengtaiguotoule/chapter/bf86c68c-195a-11ec-943d-00163e0ca5bd if (/^\/comic\/.*\/.*$/.test(location.pathname)) comicPage(1) else if (/^\/comic\/[^\/]*$/.test(location.pathname)) tablePage(1); else if (/^\/h5\/comicContent\/.*\/.*$/.test(location.pathname)) comicPage(0) else if (/^\/h5\/details\/comic\/[^\/]*$/.test(location.pathname)) tablePage(0); } route() /////////////////////////////////////////////////////////////////////// async function loadCSS(){ var element_css, animate_css; if (typeof(GM_getResourceText)=='undefined'){ await axios.get('https://unpkg.com/element-ui@2.15.0/lib/theme-chalk/index.css') .then(function (response) { element_css = response.data; }) await axios.get('https://unpkg.com/animate.css@4.1.1/animate.min.css') .then(function (response) { animate_css = response.data; }) }else{ element_css = GM_getResourceText("element_css"); animate_css = GM_getResourceText("animate_css"); } GM_addStyle(element_css); GM_addStyle(animate_css); } ///////////////////////////////////////////////////////////////////// async function tablePage(isPC) { // loadCSS() let comicName if (isPC) { comicName = window.location.pathname.split('/')[2] console.log("isPC=", isPC, comicName) } else { comicName = window.location.pathname.split('/')[4] return console.log("isPC=", isPC, comicName, "H5模式自带历史功能所以终止函数") } let token = await cookieStore.get('token'); if (!token) return console.log("未登录 -> 所以访问不到历史记录") let findTarget = function(result) { let targetElement = document.getElementsByClassName('table-default-right')[0] if (targetElement) { return modifyDom(targetElement, result) } else { console.log('targetElement Not Found') // 若未找到target元素的话则进行监听,但按理说请求队列到这一步时target元素已经加载了 // 创建一个 MutationObserver 实例,监听目标节点的子节点变化 var observer = new MutationObserver(function(mutationsList) { for (var mutation of mutationsList) { if (mutation.type === 'childList' && mutation.addedNodes.length > 0 && mutation.target.className === "upLoop") { // 检查是否有新添加的节点是具有类名为 'table-default-right' 的元素 // var addedNodes = Array.from(mutation.addedNodes); // var tableDefaultRightElements = addedNodes.filter(function(node) { // return node.classList && node.classList.contains('table-default-right'); // }); // if (tableDefaultRightElements.length > 0) { // console.log(2, tableDefaultRightElements) // 停止监听 // observer.disconnect(); // } // 而当upLoop找到时,target元素相当于是肯定能找到了,所以不需要上面的方法了 targetElement = document.getElementsByClassName('table-default-right')[0] } } modifyDom(targetElement, result) observer.disconnect(); }); // 选择需要观察变化的节点 let targetNode = document.getElementsByTagName('main')[0] // 配置观察器的选项 let config = { childList: true, subtree: true }; // 开始观察 observer.observe(targetNode, config); } } let modifyDom = function (element, res) { let span = document.createElement('span') let a = document.createElement('a') span.innerText = "已阅读到:" if (res) { a.href = `/comic/${res.path_word}/chapter/${res.chapter_id}` a.target = "_blank" a.innerText = res.chapter_name } else { a.href = '#' a.innerText = '未阅读' a.style.cssText = 'pointer-events: none; color: gray; text-decoration: none;' } element.insertBefore(a, element.firstChild); element.insertBefore(span, element.firstChild); } await axios.get('https://api.mangacopy.com/api/v3/comic2/' + comicName + '/query?platform=1&_update=true',{ headers: {'authorization': 'Token ' + token.value} }).then(function (response) { console.log('res', response) let result = response.data.results.browse if (result) findTarget(result) else findTarget(false) }).catch(function (err) { console.log('err', err) }); } async function comicPage(isPC) { loadCSS() var comic, chapter, htmlBody, newDiv, newStyle if (isPC) comic = window.location.pathname.split('/')[2] else comic = window.location.pathname.split('/')[3] chapter = window.location.pathname.split('/')[4] console.log('Comic:', comic,'|| Chapter:', chapter) // htmlBody = document.getElementsByTagName('body')[0] console.log(htmlBody) newDiv = document.createElement('div') newDiv.innerHTML = `