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=";
for (const element of document.getElementsByTagName("a")) {
try {
if (element.getAttribute("href").startsWith(REDIRECT_PAGE)) {
element.setAttribute(
"href",
decodeURIComponent(
element.getAttribute("href").substring(REDIRECT_PAGE.length),
),
);
}
} catch (_) {}
try {
if (element.getAttribute("href").startsWith(REDIRECT_PAGE)) {
element.setAttribute(
"href",
decodeURIComponent(
element.getAttribute("href").substring(REDIRECT_PAGE.length),
),
);
}
} catch (_) {}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@
// @match *://www.pixiv.net/*
// @icon https://upload.wikimedia.org/wikipedia/commons/7/7e/Pixiv_Icon.svg
// @grant none
// @version 1.0.2
// @version 1.0.3
// @author tretrauit
// @run-at document-idle
// @homepageURL https://gitlab.com/tretrauit/scripts
@ -14,32 +14,44 @@
// ==/UserScript==
function checkAI() {
if (!window.location.pathname.includes("/artworks/")) {
return;
}
const tagElms = document.querySelectorAll(".gtm-new-work-tag-event-click");
for (const elm of tagElms) {
if (elm.parentElement.parentElement.textContent.toLowerCase().includes("ai")) {
alert("AI artwork detected :(");
break;
}
}
if (!window.location.pathname.includes("/artworks/")) {
return;
}
const tagElms = document.querySelectorAll(".gtm-new-work-tag-event-click");
for (const elm of tagElms) {
const parentElm = elm.parentElement.parentElement;
for (const childElm of parentElm.children) {
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
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);
}
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);
setTimeout(checkAI, 1000);

View File

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

View File

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