Files
pixiv-artist-filter/dist/pixiv-artist-filter.user.js
Drunkoatmeal b2ba354133 2026/04/01
Fix delete button not showing up
2026-04-01 12:37:31 +07:00

130 lines
5.3 KiB
JavaScript

// ==UserScript==
// @name pixiv-artist-filter
// @description filter unwanted artists from pixiv results
// @version 0.0.3
// @namespace noproompter
// @match https://www.pixiv.net/*
// @noframes
// @run-at document-start
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_addStyle
// @grant unsafeWindow
// @grant GM.setValue
// @grant GM.addStyle
// @grant GM.getValue
// @grant GM.addElement
// ==/UserScript==
(function(){"use strict";const{fetch:g}=unsafeWindow;let p=a().map(t=>t.userid);unsafeWindow.fetch=async(...t)=>{const[e,i]=t,n=await g(e,i),r=e;if(r.startsWith("/ajax/search/")){const l=()=>n.clone().json().then(o=>(r.startsWith("/ajax/search/illustrations")?o.body.illust.data=o.body.illust.data.filter(({userId:s})=>!p.includes(s)):(r.startsWith("/ajax/search/top")||r.startsWith("/ajax/search/artworks"))&&(o.body.illustManga.data=o.body.illustManga.data.filter(({userId:s})=>!p.includes(s))),{...o}));n.json=l}return n};function a(){return JSON.parse(GM_getValue("ArtistList","[]"))}function x(t){GM_setValue("ArtistList",JSON.stringify(t)),p=a().map(e=>e.userid)}function m(t,e){const i=a();i.findIndex(n=>n.userid===e)===-1&&(i.push({name:t,userid:e}),x(i))}function f(t){const e=a().filter(i=>i.userid!==t);x(e)}function b(t){if(t.pxv_settings_but)return;t.pxv_settings_but=!0;const e=document.createElement("button");e.id="pxv-artist-filter",e.classList.add("pxv-but","pxv-settings-but"),e.textContent="Artist Filter";const i=()=>{const n=document.createElement("template");let r=a();const l=[];for(const{name:o,userid:s}of r){const d=document.createElement("div"),c=document.createElement("a");c.target="_blank",c.href=`/users/${s}`,c.text=o;const u=document.createElement("button");u.innerHTML="X",u.title="remove from filter list",u.onclick=()=>{f(s),d.parentNode?.removeChild(d)},d.append(u,c),l.push(d)}return n.append(...l),n.childNodes};e.onclick=()=>{e.blur();const n=document.createElement("template");n.innerHTML=`
<div class='pxv-screen'>
<dialog class='pxv-dialog' open>
<h1 class="pxv-title">Artist Filter List</h1>
<div class="pxv-artist-grid">
</div>
<form method="dialog">
<button class='pxv-but'>Close</button>
</form>
</dialog>
</div>
`;const r=n.content.firstElementChild;(r?.getElementsByClassName("pxv-artist-grid").item(0)).replaceChildren(...i());const o=r?.getElementsByClassName("pxv-but").item(0);o.onclick=()=>document.body.removeChild(r),document.body.appendChild(r)},t.parentNode.insertBefore(e,t.nextSibling)}function v(t){if(t.pxv_fil_but)return;t.pxv_fil_but=!0;const e=t.parentElement?.querySelector("div a[data-gtm-value]:not(:has(*))"),i=document.createElement("button");i.id="pxv-artist-filter",i.classList.add("pxv-but","pxv-modal-filter-but"),i.textContent="Filter",i.onclick=()=>{if(confirm(`Do you want to filter ${e.text}'s posts ?`)){const n=e.text,r=e.getAttribute("data-gtm-value")||"-1";m(n,r),alert(`${e.text} has been added to the filter list.`)}},t.appendChild(i)}function h(){GM_addStyle(`
.pxv-but {
color: rgb(245, 245, 245);
background-color: rgb(0, 150, 250);
min-width: 64px;
padding: 9px 24px;
line-height: 22px;
border: medium;
border-radius: 100vw;
font-size: 14px;
font-weight: bold;
cursor: pointer;
}
.pxv-settings-but {
margin-left: auto;
margin-right: 12px;
}
.pxv-modal-filter-but {
margin: 5px auto;
padding: 5px 24px;
}
.pxv-but:focus {
outline:none;
box-shadow: rgba(0, 150, 250, 0.32) 0px 0px 0px 4px;
}
.pxv-screen {
z-index: 12;
overflow: auto;
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
display: flex;
align-items: center;
background-color: rgba(0, 0, 0, 0.32);
}
.pxv-dialog {
margin:auto;
border-radius: 24px;
border-width: 0px;
width: 400px;
height: 400px;
background-color: rgb(31, 31, 31);
display:flex;
flex-direction: column;
}
.pxv-dialog .pxv-but {
display: block;
margin: 10px auto;
}
.pxv-title {
font-size: 16px;
text-align: center;
}
.pxv-artist-grid {
display: grid;
grid-template-columns: 1fr 1fr;
max-height: 310px;
overflow-y: scroll;
margin-bottom: auto;
}
.pxv-artist-grid > div {
padding:10px 0;
font-size: 14px;
transition: background-color 0.2s;
display:flex;
}
.pxv-artist-grid > div:hover {
background-color: #3a3a3a;
}
.pxv-artist-grid > div > button {
margin: 0 5px;
width: 20px;
padding: 0px;
outline: none;
background: transparent;
cursor: pointer;
color: rgb(133, 133, 133);
}
.pxv-artist-grid > div > button:hover {
color: rgb(255, 255, 255);
}
.pxv-artist-grid > div > a {
flex-grow:1;
margin: auto 0;
}
`),setInterval(()=>{if(window.location.pathname!=="/search")return;const t=document.getElementsByTagName("nav").item(2);t&&b(t)},1e3),setInterval(()=>{if(window.location.pathname!=="/search")return;const t=document.evaluate("//*/div[@open='']",document,null,XPathResult.FIRST_ORDERED_NODE_TYPE);t.singleNodeValue&&v(t.singleNodeValue)},1e3)}h()})();