// ==UserScript== // @name 漫画柜漫画列表筛选标记工具 // @namespace https://greasyfork.org/zh-CN/scripts/388742-red-list // @icon https://www.mhgui.com/favicon.ico // @version 0.0.5 // @description 标记一下哪些是看过的,哪些是不想看的。 // @author shawn // @license MIT // @match *://*.manhuagui.com/* // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @downloadURL none // ==/UserScript== function load(name) { let xhr = new XMLHttpRequest(), okStatus = document.location.protocol === "file:" ? 0 : 200; xhr.open('GET', name, false); xhr.overrideMimeType("text/html;charset=utf-8");//默认为utf-8 xhr.send(null); return xhr.status === okStatus ? xhr.responseText : null; } (function () { 'use strict'; let downloaded_listName = 'downloaded-list'; let blocked_listName = 'blocked-list'; let buttonName = 'redbutton'; // delete all //GM_deleteValue('red-list');console.log('list:' + GM_getValue('red-list', 'empty'));return; let path = location.pathname if (path.startsWith('/list/')) { let downloaded_list = GM_getValue(downloaded_listName, "").split(';'); let blocked_list = GM_getValue(blocked_listName, "").split(';'); // 帖子详情页 let ul = document.getElementById('contList'); // 添加导出按钮 let expbuttonName = "btn_exp" let button_container = document.getElementsByClassName('book-list')[0]; let btn_down = document.createElement('input'); btn_down.setAttribute('type', 'button'); btn_down.setAttribute('id', expbuttonName); btn_down.setAttribute('value', '导出下载列表'); btn_down.setAttribute('class', 'super normal button'); button_container.insertBefore(btn_down, ul); // onclick 传递 href document.getElementById(expbuttonName).onclick = function () { let str1 = GM_getValue(downloaded_listName, "") let str2 = GM_getValue(blocked_listName, "") // 配置字符串 let stringData = str1 + "||^^||" + str2 // dada 表示要转换的字符串数据,type 表示要转换的数据格式 const blob = new Blob([stringData], { type: "text/plain;charset=utf-8" }) // 根据 blob生成 url链接 const objectURL = URL.createObjectURL(blob) // 创建一个 a 标签Tag const aTag = document.createElement('a') // 设置文件的下载地址 aTag.href = objectURL // 设置保存后的文件名称 + 日期 + 时间 aTag.download = "漫画柜" + new Date().toLocaleDateString() + '.txt' // 给 a 标签添加点击事件 aTag.click() // 释放一个之前已经存在的、通过调用 URL.createObjectURL() 创建的 URL 对象。 // 当你结束使用某个 URL 对象之后,应该通过调用这个方法来让浏览器知道不用在内存中继续保留对这个文件的引用了。 URL.revokeObjectURL(objectURL) } // 添加导入按钮 let impbuttonName = "btn_imp" let btn_imp = document.createElement('input'); btn_imp.setAttribute('type', 'button'); btn_imp.setAttribute('id', impbuttonName); btn_imp.setAttribute('value', '导入下载列表'); btn_imp.setAttribute('class', 'super normal button'); button_container.insertBefore(btn_imp, ul); document.getElementById(impbuttonName).onclick = function () { // 弹出一个输入框,输入之前导出的配置字符串 let stringData = prompt("请复制之前导出的文件内容到此", "") let list = stringData.split("||^^||") if (list.length != 2) { alert("导入失败,数据格式不正确") return } let downloaded_list = list[0].split(";") let blocked_list = list[1].split(";") GM_setValue(downloaded_listName, downloaded_list.join(";")) GM_setValue(blocked_listName, blocked_list.join(";")) alert("导入成功,请刷新页面") } // 取出所有的li let lis = ul.getElementsByTagName('li'); let len = lis.length; for (let i = 0; i < len; i++) { let href = lis[i].getElementsByClassName('bcover')[0].getAttribute('href'); // 取出 class 为 updateon 的 span 的内容,里面内容为“更新于:2023-02-198.7 ” let updateon = lis[i].getElementsByClassName('updateon')[0] let datestr = updateon.innerHTML; // 获取评分 let score = parseFloat(updateon.getElementsByTagName('em')[0].innerHTML) score = parseFloat(score) // 正则匹配出 datestr 中格式为 2019-10-20 的日期 let date = datestr.match(/\d{4}-\d{2}-\d{2}/)[0] // 根据评分和日期判断是否需要屏蔽 // 日期不超过 1 个月的 let date1 = new Date(date) let date2 = new Date() let days = (date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24) let isDownloaded = downloaded_list.indexOf(href) >= 0 let isBlocked = blocked_list.indexOf(href) >= 0 if (isDownloaded) { lis[i].style = "background: greenyellow;border: 2px solid greenyellow;margin-right: 24px;" } else if (isBlocked) { lis[i].style = "background: orangered;border: 2px solid orangered;margin-right: 24px;" } else if (days < 30) { // 最近有更新,可能是未完结,标记为黄色外框 lis[i].style = "border: 2px solid yellow;margin-right: 24px;" } else if (score < 6) { // 评分低于 6,标记为红色外框 lis[i].style = "border: 2px solid red;margin-right: 24px;" } else if (score > 9) { // 高分,标记为绿色外框 lis[i].style = "border: 2px solid #8eefdf;margin-right: 24px;" } else { lis[i].style = "border: 2px solid #35ff0000;margin-right: 24px;" } let buttonName = "btn_down_" + i let button_container = lis[i].getElementsByClassName('updateon')[0]; let btn_down = document.createElement('input'); btn_down.setAttribute('type', 'button'); btn_down.setAttribute('id', buttonName); btn_down.setAttribute('value', isDownloaded ? 'UnMark' : 'Mark'); btn_down.setAttribute('class', 'super normal button'); button_container.appendChild(btn_down); // onclick 传递 href document.getElementById(buttonName).onclick = function () { let strlist = GM_getValue(downloaded_listName, "") let isDownloaded = strlist.split(';').indexOf(href) >= 0 console.log(buttonName + " onclick isDownloaded = " + isDownloaded) document.getElementById(buttonName).value = GM_getValue(downloaded_listName, '').split(';').indexOf(href) >= 0 ? 'UnMark' : 'Mark'; if (isDownloaded) { GM_setValue(downloaded_listName, strlist.replace(';' + href, '')); lis[i].style = "" } else { GM_setValue(downloaded_listName, strlist + ';' + href); lis[i].style = "background: greenyellow;" } document.getElementById(buttonName).value = GM_getValue(downloaded_listName, '').split(';').indexOf(href) >= 0 ? 'UnMark' : 'Mark'; } let buttonBlockName = "btn_block_" + i let btn_block = document.createElement('input'); btn_block.setAttribute('type', 'button'); btn_block.setAttribute('id', buttonBlockName); btn_block.setAttribute('value', isBlocked ? 'UnBlock' : 'Block'); btn_block.setAttribute('class', 'super normal button'); button_container.appendChild(btn_block); // onclick 传递 href document.getElementById(buttonBlockName).onclick = function () { let strlist = GM_getValue(blocked_listName, "") let isBlocked = strlist.split(';').indexOf(href) >= 0 if (isBlocked) { GM_setValue(blocked_listName, strlist.replace(';' + href, '')); lis[i].style = "" } else { GM_setValue(blocked_listName, strlist + ';' + href); lis[i].style = "background: orangered;" } document.getElementById(buttonBlockName).value = GM_getValue(blocked_listName, '').split(';').indexOf(href) >= 0 ? 'UnBlock' : 'Block'; } } } })();