diff --git a/.gitignore b/.gitignore index b431156..b18b870 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ node_modules -dist .vite diff --git a/README.md b/README.md index 55c3736..8906f3a 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,14 @@ In the age of image noises and slops, It's getting more crucial to filter your s This userscript essentially add that feature +## Install + ## Development ``` $ deno task dev ``` -## Deploy - Build production assets: ``` diff --git a/dist/pixiv-artist-filter.js b/dist/pixiv-artist-filter.js new file mode 100644 index 0000000..377e07c --- /dev/null +++ b/dist/pixiv-artist-filter.js @@ -0,0 +1,109 @@ +(function(){"use strict";const g=``,{fetch:m}=unsafeWindow;let u=a().map(t=>t.userid);unsafeWindow.fetch=async(...t)=>{const[e,i]=t,n=await m(e,i),s=e;if(s.startsWith("/ajax/search/")){const l=()=>n.clone().json().then(r=>(s.startsWith("/ajax/search/illustrations")?r.body.illust.data=r.body.illust.data.filter(({userId:o})=>!u.includes(o)):(s.startsWith("/ajax/search/top")||s.startsWith("/ajax/search/artworks"))&&(r.body.illustManga.data=r.body.illustManga.data.filter(({userId:o})=>!u.includes(o))),{...r}));n.json=l}return n};function a(){return JSON.parse(GM_getValue("ArtistList","[]"))}function x(t){GM_setValue("ArtistList",JSON.stringify(t)),u=a().map(e=>e.userid)}function f(t,e){const i=a();i.findIndex(n=>n.userid===e)===-1&&(i.push({name:t,userid:e}),x(i))}function b(t){const e=a().filter(i=>i.userid!==t);x(e)}function h(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 s=a();const l=[];for(const{name:r,userid:o}of s){const d=document.createElement("div"),c=document.createElement("a");c.target="_blank",c.href=`/users/${o}`,c.text=r;const p=document.createElement("button");p.innerHTML=g,p.onclick=()=>{b(o),d.parentNode?.removeChild(d)},d.append(p,c),l.push(d)}return n.append(...l),n.childNodes};e.onclick=()=>{e.blur();const n=document.createElement("template");n.innerHTML=` +
+ +

Artist Filter List

+
+
+
+ +
+
+
+ `;const s=n.content.firstElementChild;(s?.getElementsByClassName("pxv-artist-grid").item(0)).replaceChildren(...i());const r=s?.getElementsByClassName("pxv-but").item(0);r.onclick=()=>document.body.removeChild(s),document.body.appendChild(s)},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,s=e.getAttribute("data-gtm-value")||"-1";f(n,s),alert(`${e.text} has been added to the filter list.`)}},t.appendChild(i)}function _(){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; + padding: 0px; + border: medium; + outline: none; + background: transparent; + cursor: pointer; + color: rgb(133, 133, 133); + } + + .pxv-artist-grid > div > a { + flex-grow:1; + margin: auto 0; + } + `),setInterval(()=>{if(!window.location.pathname.includes("/tags/"))return;const t=document.getElementsByTagName("nav").item(0);t&&h(t)},1e3),setInterval(()=>{if(!window.location.pathname.includes("/tags/"))return;const t=document.evaluate("//*/div[@open='']",document,null,XPathResult.FIRST_ORDERED_NODE_TYPE);t.singleNodeValue&&v(t.singleNodeValue)},1e3)}_()})(); diff --git a/dist/pixiv-artist-filter.meta.js b/dist/pixiv-artist-filter.meta.js new file mode 100644 index 0000000..2d5e05c --- /dev/null +++ b/dist/pixiv-artist-filter.meta.js @@ -0,0 +1,17 @@ +// ==UserScript== +// @name pixiv-artist-filter +// @description filter unwanted artists from pixiv results +// @version 0.0.1 +// @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== \ No newline at end of file diff --git a/dist/pixiv-artist-filter.user.js b/dist/pixiv-artist-filter.user.js new file mode 100644 index 0000000..766fbaf --- /dev/null +++ b/dist/pixiv-artist-filter.user.js @@ -0,0 +1,127 @@ +// ==UserScript== +// @name pixiv-artist-filter +// @description filter unwanted artists from pixiv results +// @version 0.0.1 +// @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 g=``,{fetch:m}=unsafeWindow;let u=a().map(t=>t.userid);unsafeWindow.fetch=async(...t)=>{const[e,i]=t,n=await m(e,i),s=e;if(s.startsWith("/ajax/search/")){const l=()=>n.clone().json().then(r=>(s.startsWith("/ajax/search/illustrations")?r.body.illust.data=r.body.illust.data.filter(({userId:o})=>!u.includes(o)):(s.startsWith("/ajax/search/top")||s.startsWith("/ajax/search/artworks"))&&(r.body.illustManga.data=r.body.illustManga.data.filter(({userId:o})=>!u.includes(o))),{...r}));n.json=l}return n};function a(){return JSON.parse(GM_getValue("ArtistList","[]"))}function x(t){GM_setValue("ArtistList",JSON.stringify(t)),u=a().map(e=>e.userid)}function f(t,e){const i=a();i.findIndex(n=>n.userid===e)===-1&&(i.push({name:t,userid:e}),x(i))}function b(t){const e=a().filter(i=>i.userid!==t);x(e)}function h(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 s=a();const l=[];for(const{name:r,userid:o}of s){const d=document.createElement("div"),c=document.createElement("a");c.target="_blank",c.href=`/users/${o}`,c.text=r;const p=document.createElement("button");p.innerHTML=g,p.onclick=()=>{b(o),d.parentNode?.removeChild(d)},d.append(p,c),l.push(d)}return n.append(...l),n.childNodes};e.onclick=()=>{e.blur();const n=document.createElement("template");n.innerHTML=` +
+ +

Artist Filter List

+
+
+
+ +
+
+
+ `;const s=n.content.firstElementChild;(s?.getElementsByClassName("pxv-artist-grid").item(0)).replaceChildren(...i());const r=s?.getElementsByClassName("pxv-but").item(0);r.onclick=()=>document.body.removeChild(s),document.body.appendChild(s)},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,s=e.getAttribute("data-gtm-value")||"-1";f(n,s),alert(`${e.text} has been added to the filter list.`)}},t.appendChild(i)}function _(){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; + padding: 0px; + border: medium; + outline: none; + background: transparent; + cursor: pointer; + color: rgb(133, 133, 133); + } + + .pxv-artist-grid > div > a { + flex-grow:1; + margin: auto 0; + } + `),setInterval(()=>{if(!window.location.pathname.includes("/tags/"))return;const t=document.getElementsByTagName("nav").item(0);t&&h(t)},1e3),setInterval(()=>{if(!window.location.pathname.includes("/tags/"))return;const t=document.evaluate("//*/div[@open='']",document,null,XPathResult.FIRST_ORDERED_NODE_TYPE);t.singleNodeValue&&v(t.singleNodeValue)},1e3)}_()})(); diff --git a/package.json b/package.json index f5e674e..85c5f98 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "noproompter", + "name": "pixiv-artist-filter", "description": "filter unwanted artists from pixiv results", "version":"0.0.1" } diff --git a/src/main.ts b/src/main.ts index 2024e7a..164509e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -118,11 +118,6 @@ function AttachSettings(NavNode:HTMLElement) {

Artist Filter List

-
One
-
Two
-
Three
-
Four
-
Five
@@ -273,8 +268,9 @@ function init() { `) const attach_settings = setInterval(() => { - const navNode = document.getElementsByTagName('nav').item(0); + if ( !window.location.pathname.includes('/tags/')) return ; + const navNode = document.getElementsByTagName('nav').item(0); if (navNode){ AttachSettings(navNode) } @@ -282,6 +278,8 @@ function init() { },1000) const pixiv_attach_artist = setInterval( () => { + if ( !window.location.pathname.includes('/tags/')) return ; + const profileModalsearch = document.evaluate("//*/div[@open='']", document,null, XPathResult.FIRST_ORDERED_NODE_TYPE); //const profileModalsearch = document.evaluate("//*/a[contains(text(),'View Profile')]", document,null, XPathResult.FIRST_ORDERED_NODE_TYPE); if ( profileModalsearch.singleNodeValue ) { diff --git a/vite.config.ts b/vite.config.ts index af2d9ee..5c734b5 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -18,7 +18,7 @@ export default defineConfig( ({mode}) => { description, version, namespace: 'noproompter', - match: 'https://www.pixiv.net/*/tags/*', + match: 'https://www.pixiv.net/*', noframes:true, "run-at": "document-start", grant: ['GM.setValue', 'GM.addStyle', 'GM.getValue', 'GM.addElement']