// ==UserScript== // @license MIT // @name Pixiv AI Tag // @description 对Pixiv中的AI生成图像添加一个标注 // @author BAKAOLC // @version 0.0.3 // @icon http://www.pixiv.net/favicon.ico // @match https://www.pixiv.net/* // @namespace none // @grant none // @noframes // @downloadURL none // ==/UserScript== const selector = [ { url: /pixiv.net\/(cate_r18|manga|en\/$|$)/, sel: "ul div>div>div:nth-of-type(1)>a", }, { url: /pixiv.net\/(en\/)?artworks/, sel: "ul div>div>div>a, main nav div>div>div>a", }, { url: "pixiv.net/bookmark_new_illust", sel: "ul div>div>div>a" }, { url: "pixiv.net/contest", sel: ".thumbnail-container>a" }, { url: "pixiv.net/discovery", sel: "ul div>div>div:nth-of-type(1)>a" }, { url: "pixiv.net/new_illust", sel: "ul div>div:nth-of-type(1)>div>a" }, { url: "pixiv.net/ranking", sel: ".ranking-image-item>a" }, { url: /pixiv.net\/request($|\/(complete|creators)\/(illust|manga|ugoira))/, sel: "ul div>div:nth-of-type(1)>a", }, { url: /pixiv.net\/(en\/)?tags/, sel: "ul div>div>div>a" }, { url: /pixiv.net\/(en\/)?users/, sel: "ul div>div:nth-of-type(1)>div:nth-of-type(1)>a, ul div>div div>div:nth-of-type(1)>a:nth-child(1)", }, { url: /pixiv.net\/user\/\d+\/series\/\d+/, sel: "ul div>div>div>a" }, ]; let query_delay = 0; let query_array = [] (function () { add_style(); selector.map( (rule) => (rule.sel = rule.sel .split(",") .map((n) => n + '[href*="/artworks/"]:not(.add_ai_tag)') .join(",")) ); if (query_delay > 0) { start_interval(); new MutationObserver(function () { let rule = selector.find((s) => location.href.match(s.url)); let illusts = rule ? document.querySelectorAll(rule.sel) : []; if (illusts.length) add_ai_tag_delay(illusts); }).observe(document.body, { childList: true, subtree: true }); } else { new MutationObserver(function () { let rule = selector.find((s) => location.href.match(s.url)); let illusts = rule ? document.querySelectorAll(rule.sel) : []; if (illusts.length) add_ai_tag(illusts); }).observe(document.body, { childList: true, subtree: true }); } })(); function add_style() { document.head.insertAdjacentHTML('beforeend', ` `); } function start_interval() { setInterval(async function () { if (query_array.length > 0) { let data = query_array.shift(); query_illust(data.id, data.node); } }, query_delay) return datas; } async function add_ai_tag_delay(illusts) { illusts.forEach(async (a) => { a.classList.add("add_ai_tag"); let id = a.href.split("/artworks/").pop(); query_array.push({ id: id, node: a }) }); } async function add_ai_tag(illusts) { illusts.forEach(async (a) => { a.classList.add("add_ai_tag"); let id = a.href.split("/artworks/").pop(); query_illust(id, a); }); } async function query_illust(id, node) { let json = await ( await fetch( "https://www.pixiv.net/ajax/illust/" + id, { credentials: "omit" } ) ).json(); if (json.body.aiType == 2) { add_ai_tag_view(node); } } function add_ai_tag_view(node) { node.querySelector("div.sc-rp5asc-13").insertAdjacentHTML( "afterbegin", `