Greasy Fork is available in English.
标记一下哪些是看过的,哪些是不想看的。
当前为
// ==UserScript==
// @name manhuagui_readed_mark
// @namespace http://greasyfork.icu/zh-CN/scripts/388742-red-list
// @version 0.0.2
// @description 标记一下哪些是看过的,哪些是不想看的。
// @author shawn
// @license MIT
// @match *://*.manhuagui.com/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// ==/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');
// // 取出 a 标签的 href 属性
// if (redlist.indexOf(href) >= 0) {
// // console.log('in red list: ' + username.innerText);
// lis[i].style = "background-image:url(https://i.loli.net/2019/06/09/5cfbebdfd083a19907.png);background-size:contain;";
// }
// 取出 class 为 updateon 的 span 的内容
let datestr = lis[i].getElementsByClassName('updateon')[0].innerHTML;
// 正则匹配出 datestr 中格式为 2019-10-20 的日期
let isDownloaded = downloaded_list.indexOf(href) >= 0
let isBlocked = blocked_list.indexOf(href) >= 0
if (isDownloaded) {
lis[i].style = "background: greenyellow;"
} else if (isBlocked) {
lis[i].style = "background: orangered;"
}
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 ? 'UnDown' : 'Downed');
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, "")
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 ? 'UnDown' : 'Downed';
}
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, "")
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';
}
}
}
})();