fix: better tag filter

Also formatted it with biomejs

I didn't realize that Honkai Star R(ai)l has AI in it 💀
This commit is contained in:
tretrauit 2024-03-07 00:39:56 +07:00
parent 7e07d807d5
commit c28408cabc
8 changed files with 262 additions and 250 deletions

View File

@ -14,14 +14,14 @@
const REDIRECT_PAGE = "https://anonyviet.com/tieptucdentrangmoi/?url="; const REDIRECT_PAGE = "https://anonyviet.com/tieptucdentrangmoi/?url=";
for (const element of document.getElementsByTagName("a")) { for (const element of document.getElementsByTagName("a")) {
try { try {
if (element.getAttribute("href").startsWith(REDIRECT_PAGE)) { if (element.getAttribute("href").startsWith(REDIRECT_PAGE)) {
element.setAttribute( element.setAttribute(
"href", "href",
decodeURIComponent( decodeURIComponent(
element.getAttribute("href").substring(REDIRECT_PAGE.length), element.getAttribute("href").substring(REDIRECT_PAGE.length),
), ),
); );
} }
} catch (_) {} } catch (_) {}
} }

View File

@ -13,20 +13,20 @@
// ==/UserScript== // ==/UserScript==
setTimeout(() => { setTimeout(() => {
const header = document.querySelector( const header = document.querySelector(
".src-components-common-TopBar-assets-__pc_---top---uiHfPh", ".src-components-common-TopBar-assets-__pc_---top---uiHfPh",
); );
if (header != null) { if (header != null) {
header.remove(); header.remove();
console.log("Removed header"); console.log("Removed header");
} }
setTimeout(() => { setTimeout(() => {
const watermark = document.querySelector( const watermark = document.querySelector(
".src-components-pages-assets-__kv_---kv-slogan---IBwwuz.kv-slogan", ".src-components-pages-assets-__kv_---kv-slogan---IBwwuz.kv-slogan",
); );
if (watermark != null) { if (watermark != null) {
watermark.remove(); watermark.remove();
console.log("Removed watermark"); console.log("Removed watermark");
} }
}, 5000); }, 5000);
}, 5000); }, 5000);

View File

@ -13,26 +13,26 @@
// ==/UserScript== // ==/UserScript==
setTimeout(function () { setTimeout(function () {
const tblContent = document const tblContent = document
.getElementsByClassName("table_block")[0] .getElementsByClassName("table_block")[0]
.getElementsByTagName("tbody")[0].children; .getElementsByTagName("tbody")[0].children;
// Replace the export IP:Port button // Replace the export IP:Port button
const btns = document.getElementsByClassName("export")[0]; const btns = document.getElementsByClassName("export")[0];
const exportBtn = btns.children[0]; const exportBtn = btns.children[0];
const fakeExportBtn = exportBtn.cloneNode(true); const fakeExportBtn = exportBtn.cloneNode(true);
fakeExportBtn.removeAttribute("href"); fakeExportBtn.removeAttribute("href");
fakeExportBtn.addEventListener("click", () => { fakeExportBtn.addEventListener("click", () => {
var proxyStr = ""; var proxyStr = "";
for (let proxyContent of tblContent) { for (let proxyContent of tblContent) {
const proxyContentChildren = proxyContent.children; const proxyContentChildren = proxyContent.children;
const proxyIp = proxyContentChildren[0].innerHTML; const proxyIp = proxyContentChildren[0].innerHTML;
const proxyPort = proxyContentChildren[1].innerHTML; const proxyPort = proxyContentChildren[1].innerHTML;
proxyStr += proxyIp + ":" + proxyPort + "\n"; proxyStr += proxyIp + ":" + proxyPort + "\n";
} }
navigator.clipboard.writeText(proxyStr); navigator.clipboard.writeText(proxyStr);
alert("Copied IP:Port list to clipboard."); alert("Copied IP:Port list to clipboard.");
}); });
exportBtn.remove(); exportBtn.remove();
btns.prepend(fakeExportBtn); btns.prepend(fakeExportBtn);
}, 5000); }, 5000);

View File

@ -14,86 +14,86 @@
// ==/UserScript== // ==/UserScript==
function init() { function init() {
const chest = document.getElementsByClassName("chest")[0]; const chest = document.getElementsByClassName("chest")[0];
const chestStatus = document.getElementsByClassName("chest__btn btn")[0]; const chestStatus = document.getElementsByClassName("chest__btn btn")[0];
const openWheelBtn = document.getElementsByClassName("wheel__btn")[0]; const openWheelBtn = document.getElementsByClassName("wheel__btn")[0];
const upgradeBtn = document.getElementsByClassName("card__upgrade")[0]; const upgradeBtn = document.getElementsByClassName("card__upgrade")[0];
// Has string characters need to be removed first. // Has string characters need to be removed first.
const requiredScore = document const requiredScore = document
.getElementsByClassName("card__note")[0] .getElementsByClassName("card__note")[0]
.getElementsByTagName("strong")[0]; .getElementsByTagName("strong")[0];
const currentScore = document const currentScore = document
.getElementsByClassName("card__data")[0] .getElementsByClassName("card__data")[0]
.getElementsByTagName("span")[1]; .getElementsByTagName("span")[1];
function toInt(str) { function toInt(str) {
return parseInt(str.replace(/[^0-9]/g, "")); return parseInt(str.replace(/[^0-9]/g, ""));
} }
function upgradeRank() { function upgradeRank() {
if (toInt(currentScore.innerHTML) >= toInt(requiredScore.innerHTML)) { if (toInt(currentScore.innerHTML) >= toInt(requiredScore.innerHTML)) {
upgradeBtn.click(); upgradeBtn.click();
} }
} }
function receiveRankReward() { function receiveRankReward() {
const rewards = document.getElementsByClassName("milestone available"); const rewards = document.getElementsByClassName("milestone available");
for (const reward of rewards) { for (const reward of rewards) {
if (reward.className.includes("claimed")) { if (reward.className.includes("claimed")) {
continue; continue;
} }
reward.click(); reward.click();
} }
} }
function spinWheel() { function spinWheel() {
const spinBtn = document.getElementsByClassName("popup-wheel__btn")[0]; const spinBtn = document.getElementsByClassName("popup-wheel__btn")[0];
const spinLeft = spinBtn.children[1].getElementsByTagName("strong")[0]; const spinLeft = spinBtn.children[1].getElementsByTagName("strong")[0];
function doSpin() { function doSpin() {
spinBtn.click(); spinBtn.click();
setTimeout(() => { setTimeout(() => {
if (parseInt(spinLeft.innerHTML) > 0) { if (parseInt(spinLeft.innerHTML) > 0) {
setTimeout(doSpin, 1000); setTimeout(doSpin, 1000);
} }
}, 3000); }, 3000);
} }
doSpin(); doSpin();
const closeBtn = document.getElementsByClassName("close")[0]; const closeBtn = document.getElementsByClassName("close")[0];
closeBtn.click(); closeBtn.click();
} }
function wheel() { function wheel() {
if ( if (
!openWheelBtn.className.includes("animate__tada") || !openWheelBtn.className.includes("animate__tada") ||
document.getElementById("wheel") != null document.getElementById("wheel") != null
) { ) {
return; return;
} }
console.log("click chest"); console.log("click chest");
openWheelBtn.click(); openWheelBtn.click();
setTimeout(spinWheel, 1000); setTimeout(spinWheel, 1000);
} }
function receiveScore() { function receiveScore() {
if (chestStatus.innerHTML === "Nhận") { if (chestStatus.innerHTML === "Nhận") {
chest.click(); chest.click();
} }
} }
setInterval(() => { setInterval(() => {
if ((element = document.getElementsByClassName("swal2-close")[0])) { if ((element = document.getElementsByClassName("swal2-close")[0])) {
element.click(); element.click();
} }
}, 100); }, 100);
function loop() { function loop() {
receiveScore(); receiveScore();
upgradeRank(); upgradeRank();
receiveRankReward(); receiveRankReward();
setTimeout(wheel, 500); setTimeout(wheel, 500);
setTimeout(loop, 1000); setTimeout(loop, 1000);
} }
loop(); loop();
} }
setTimeout(init, 5000); setTimeout(init, 5000);

View File

@ -13,69 +13,69 @@
// ==/UserScript== // ==/UserScript==
function injectCSS(css) { function injectCSS(css) {
const style = document.createElement("style"); const style = document.createElement("style");
style.appendChild(document.createTextNode(css)); style.appendChild(document.createTextNode(css));
document.head.appendChild(style); document.head.appendChild(style);
} }
function findElement(tag, properties) { function findElement(tag, properties) {
const elements = document.querySelectorAll(tag); const elements = document.querySelectorAll(tag);
elementLoop: for (const element of elements) { elementLoop: for (const element of elements) {
for (const [key, value] of Object.entries(properties)) { for (const [key, value] of Object.entries(properties)) {
if (element.getAttribute(key) !== value) { if (element.getAttribute(key) !== value) {
continue elementLoop; continue elementLoop;
} }
} }
return element; return element;
} }
} }
function getAncestor(element, level) { function getAncestor(element, level) {
if (element == null) { if (element == null) {
return null; return null;
} }
for (let i = 0; i < level; i++) { for (let i = 0; i < level; i++) {
element = element.parentNode; element = element.parentNode;
} }
return element; return element;
} }
console.log("Scanning class for components..."); console.log("Scanning class for components...");
// Search box // Search box
let searchBox = findElement("input", { "aria-autocomplete": "list" }); let searchBox = findElement("input", { "aria-autocomplete": "list" });
if (searchBox == null) { if (searchBox == null) {
console.warn("Failed to get searchBox element."); console.warn("Failed to get searchBox element.");
throw new Error(); throw new Error();
} }
searchBox = getAncestor(searchBox, 7); searchBox = getAncestor(searchBox, 7);
// Header & Text header // Header & Text header
let textHeader = findElement("span", { let textHeader = findElement("span", {
style: style:
"line-height: var(--base-line-clamp-line-height); --base-line-clamp-line-height:28px;", "line-height: var(--base-line-clamp-line-height); --base-line-clamp-line-height:28px;",
}); });
let header; let header;
if (textHeader == null) { if (textHeader == null) {
console.warn("Failed to get textHeader element."); console.warn("Failed to get textHeader element.");
throw new Error(); throw new Error();
} }
header = getAncestor(textHeader, 7); header = getAncestor(textHeader, 7);
textHeader = textHeader.childNodes[0]; textHeader = textHeader.childNodes[0];
// Unread indicator // Unread indicator
let unreadIndicator = findElement("span", { let unreadIndicator = findElement("span", {
"data-visualcompletion": "ignore", "data-visualcompletion": "ignore",
}); });
// Action bar // Action bar
let actionBar = findElement("div", { "aria-expanded": "false" }); let actionBar = findElement("div", { "aria-expanded": "false" });
if (actionBar == null) { if (actionBar == null) {
console.warn("Failed to get actionBar element."); console.warn("Failed to get actionBar element.");
throw new Error(); throw new Error();
} }
actionBar = actionBar.parentNode; actionBar = actionBar.parentNode;
// Chats // Chats
let chats = findElement("div", { "aria-label": "Chats" }); let chats = findElement("div", { "aria-label": "Chats" });
if (chats == null) { if (chats == null) {
console.warn("Failed to get chats element."); console.warn("Failed to get chats element.");
throw new Error(); throw new Error();
} }
chats = chats.parentNode; chats = chats.parentNode;
// Print elements // Print elements

View File

@ -5,7 +5,7 @@
// @match *://www.pixiv.net/* // @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.2 // @version 1.0.3
// @author tretrauit // @author tretrauit
// @run-at document-idle // @run-at document-idle
// @homepageURL https://gitlab.com/tretrauit/scripts // @homepageURL https://gitlab.com/tretrauit/scripts
@ -14,32 +14,44 @@
// ==/UserScript== // ==/UserScript==
function checkAI() { function checkAI() {
if (!window.location.pathname.includes("/artworks/")) { if (!window.location.pathname.includes("/artworks/")) {
return; 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")) { const parentElm = elm.parentElement.parentElement;
alert("AI artwork detected :("); for (const childElm of parentElm.children) {
break; const text = childElm.innerText.trim();
} const textLowerCase = text.toLowerCase();
} if (
text.startsWith("AI") ||
text.endsWith("AI") ||
textLowerCase === "ai" ||
(textLowerCase.includes("ai") &&
(textLowerCase.includes("generated") ||
textLowerCase.includes("illustration")))
) {
alert("AI artwork detected :(");
return;
}
}
}
} }
// Stack Overflow thingy // Stack Overflow thingy
let previousUrl = ""; let previousUrl = "";
const observer = new MutationObserver(() => { const observer = new MutationObserver(() => {
if (window.location.href !== previousUrl) { if (window.location.href !== previousUrl) {
console.log(`URL changed from ${previousUrl} to ${window.location.href}`); console.log(`URL changed from ${previousUrl} to ${window.location.href}`);
previousUrl = window.location.href; previousUrl = window.location.href;
// do your thing // do your thing
setTimeout(checkAI, 1000); setTimeout(checkAI, 1000);
} }
}); });
const config = { subtree: true, childList: true }; const config = { subtree: true, childList: true };
// start observing change // start observing change
console.log("AI notifier for Pixiv is running..."); console.log("AI notifier for Pixiv is running...");
observer.observe(document, config); observer.observe(document, config);
setTimeout(checkAI, 1000); setTimeout(checkAI, 1000);

View File

@ -14,23 +14,23 @@
// Remove the "download app ads" // Remove the "download app ads"
const dlClasses = [ const dlClasses = [
"tiktok-9er52i-DivCtaGuideWrapper", "tiktok-9er52i-DivCtaGuideWrapper",
"tiktok-99ed1t-DivFooterGuide", "tiktok-99ed1t-DivFooterGuide",
"tiktok-txik7e-DivFloatButtonWrapper", "tiktok-txik7e-DivFloatButtonWrapper",
"tiktok-h0mxry-DivCtaContentWrapper", "tiktok-h0mxry-DivCtaContentWrapper",
]; ];
setInterval(() => { setInterval(() => {
for (const dlClass of dlClasses) { for (const dlClass of dlClasses) {
const element = document.getElementsByClassName(dlClass)[0]; const element = document.getElementsByClassName(dlClass)[0];
if (element === undefined) { if (element === undefined) {
continue; continue;
} }
for (const childElm of element.children) { for (const childElm of element.children) {
console.log(childElm); console.log(childElm);
setTimeout(() => element.removeChild(childElm), 1); setTimeout(() => element.removeChild(childElm), 1);
} }
element.style["height"] = "0px"; element.style["height"] = "0px";
element.style["padding"] = "0px"; element.style["padding"] = "0px";
element.style["z-index"] = "-1"; element.style["z-index"] = "-1";
} }
}, 50); }, 50);

View File

@ -18,43 +18,43 @@
const DEBUG = false; const DEBUG = false;
function logDebug(...kwargs) { function logDebug(...kwargs) {
if (!DEBUG) { if (!DEBUG) {
return; return;
} }
console.log(...kwargs); console.log(...kwargs);
} }
function getShortsId(videoPathName) { function getShortsId(videoPathName) {
const shortPath = videoPathName.split("/"); const shortPath = videoPathName.split("/");
return shortPath[shortPath.length - 1]; return shortPath[shortPath.length - 1];
} }
function redirectReplace() { function redirectReplace() {
window.location.replace( window.location.replace(
"https://www.youtube.com/watch?v=" + getShortsId(window.location.pathname), "https://www.youtube.com/watch?v=" + getShortsId(window.location.pathname),
); );
} }
function checkCurrentURL() { function checkCurrentURL() {
if (window.location.pathname.includes("/shorts/")) { if (window.location.pathname.includes("/shorts/")) {
logDebug("Shorts url detected, redirecting..."); logDebug("Shorts url detected, redirecting...");
redirectReplace(); redirectReplace();
} }
} }
// Should be run asap // Should be run asap
checkCurrentURL(); checkCurrentURL();
function replaceHrefURL(element) { function replaceHrefURL(element) {
if (element.href != null && element.href.includes("/shorts/")) { if (element.href != null && element.href.includes("/shorts/")) {
element.href = "/watch?v=" + getShortsId(element.href); element.href = "/watch?v=" + getShortsId(element.href);
} }
} }
function checkElements() { function checkElements() {
insertionQ(":is(#video-title, #thumbnail) ").every(function (element) { insertionQ(":is(#video-title, #thumbnail) ").every(function (element) {
replaceHrefURL(element); replaceHrefURL(element);
}); });
} }
window.addEventListener("yt-navigate-finish", checkCurrentURL); window.addEventListener("yt-navigate-finish", checkCurrentURL);
@ -62,55 +62,55 @@ window.addEventListener("yt-navigate-finish", checkCurrentURL);
const o_addEventListener = window.addEventListener; const o_addEventListener = window.addEventListener;
const o_shady_addEventListener = window.__shady_addEventListener; const o_shady_addEventListener = window.__shady_addEventListener;
function f_addEventListener(eventName, callback) { function f_addEventListener(eventName, callback) {
logDebug("Event listener added: ", eventName); logDebug("Event listener added: ", eventName);
function f_callback(event) { function f_callback(event) {
function cb_dbg() { function cb_dbg() {
if (event instanceof MouseEvent) { if (event instanceof MouseEvent) {
// Event flood in console // Event flood in console
return; return;
} else if (event instanceof PointerEvent) { } else if (event instanceof PointerEvent) {
// Event flood in console // Event flood in console
return; return;
} else if (event instanceof BeforeUnloadEvent) { } else if (event instanceof BeforeUnloadEvent) {
// Event flood in console // Event flood in console
return; return;
} }
logDebug("Event callback triggered: ", event, event.data); logDebug("Event callback triggered: ", event, event.data);
logDebug("Page url: ", window.location.href); logDebug("Page url: ", window.location.href);
} }
if (DEBUG) { if (DEBUG) {
cb_dbg(); cb_dbg();
} }
if (event instanceof MessageEvent) { if (event instanceof MessageEvent) {
// This event is made by SponsorBlock not Youtube so by default it will not run. // This event is made by SponsorBlock not Youtube so by default it will not run.
// But this can speed up the page navigation process so i'll just keep it. // But this can speed up the page navigation process so i'll just keep it.
const data = event.data; const data = event.data;
if (data.type == "navigation" && data.pageType == "shorts") { if (data.type == "navigation" && data.pageType == "shorts") {
if (data.videoID == undefined) { if (data.videoID == undefined) {
return; return;
} }
logDebug("Thank you SponsorBlock for this event :3"); logDebug("Thank you SponsorBlock for this event :3");
logDebug("Navigating to video..."); logDebug("Navigating to video...");
if (window.location.pathname.includes("/shorts/")) { if (window.location.pathname.includes("/shorts/")) {
window.location.replace( window.location.replace(
"https://www.youtube.com/watch?v=" + data.videoID, "https://www.youtube.com/watch?v=" + data.videoID,
); );
return; return;
} }
window.location.assign( window.location.assign(
"https://www.youtube.com/watch?v=" + data.videoID, "https://www.youtube.com/watch?v=" + data.videoID,
); );
return; return;
} }
} }
callback(event); callback(event);
} }
o_addEventListener(eventName, f_callback); o_addEventListener(eventName, f_callback);
} }
function f_sus_addEventListener(a, b, c) { function f_sus_addEventListener(a, b, c) {
logDebug("Shady addEventListener triggered."); logDebug("Shady addEventListener triggered.");
logDebug(a, b, c); logDebug(a, b, c);
o_shady_addEventListener(a, b, c); o_shady_addEventListener(a, b, c);
} }
window.addEventListener = f_addEventListener; window.addEventListener = f_addEventListener;
logDebug("Init fake addEventListener successful."); logDebug("Init fake addEventListener successful.");