fix: watch url changes
This commit is contained in:
parent
528f19e5b5
commit
7e07d807d5
@ -2,10 +2,10 @@
|
|||||||
// @name AI notifier for Pixiv
|
// @name AI notifier for Pixiv
|
||||||
// @description Notify you when an AI artwork is detected (through tags) on Pixiv
|
// @description Notify you when an AI artwork is detected (through tags) on Pixiv
|
||||||
// @namespace tretrauit-dev
|
// @namespace tretrauit-dev
|
||||||
// @match *://www.pixiv.net/*/artworks/*
|
// @match *://www.pixiv.net/*
|
||||||
// @icon https://upload.wikimedia.org/wikipedia/commons/7/7e/Pixiv_Icon.svg
|
// @icon https://upload.wikimedia.org/wikipedia/commons/7/7e/Pixiv_Icon.svg
|
||||||
// @grant none
|
// @grant none
|
||||||
// @version 1.0.1
|
// @version 1.0.2
|
||||||
// @author tretrauit
|
// @author tretrauit
|
||||||
// @run-at document-idle
|
// @run-at document-idle
|
||||||
// @homepageURL https://gitlab.com/tretrauit/scripts
|
// @homepageURL https://gitlab.com/tretrauit/scripts
|
||||||
@ -13,8 +13,10 @@
|
|||||||
// @downloadURL https://git.tretrauit.me/tretrauit/scripts/raw/branch/main/userscripts/pixiv-ai-notifier.user.js
|
// @downloadURL https://git.tretrauit.me/tretrauit/scripts/raw/branch/main/userscripts/pixiv-ai-notifier.user.js
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
console.log("AI notifier for Pixiv is running...");
|
function checkAI() {
|
||||||
setTimeout(() => {
|
if (!window.location.pathname.includes("/artworks/")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const tagElms = document.querySelectorAll(".gtm-new-work-tag-event-click");
|
const tagElms = document.querySelectorAll(".gtm-new-work-tag-event-click");
|
||||||
for (const elm of tagElms) {
|
for (const elm of tagElms) {
|
||||||
if (elm.parentElement.parentElement.textContent.toLowerCase().includes("ai")) {
|
if (elm.parentElement.parentElement.textContent.toLowerCase().includes("ai")) {
|
||||||
@ -22,4 +24,22 @@ setTimeout(() => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1000);
|
}
|
||||||
|
|
||||||
|
// Stack Overflow thingy
|
||||||
|
let previousUrl = "";
|
||||||
|
|
||||||
|
const observer = new MutationObserver(() => {
|
||||||
|
if (window.location.href !== previousUrl) {
|
||||||
|
console.log(`URL changed from ${previousUrl} to ${window.location.href}`);
|
||||||
|
previousUrl = window.location.href;
|
||||||
|
// do your thing
|
||||||
|
setTimeout(checkAI, 1000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const config = { subtree: true, childList: true };
|
||||||
|
|
||||||
|
// start observing change
|
||||||
|
console.log("AI notifier for Pixiv is running...");
|
||||||
|
observer.observe(document, config);
|
||||||
|
setTimeout(checkAI, 1000);
|
Loading…
Reference in New Issue
Block a user