r18dev_remove_duplicates.user.js: add mutation observer
This commit is contained in:
@@ -3,21 +3,26 @@
|
|||||||
// @namespace Violentmonkey Scripts
|
// @namespace Violentmonkey Scripts
|
||||||
// @match https://r18.dev/videos/vod/movies/list/*
|
// @match https://r18.dev/videos/vod/movies/list/*
|
||||||
// @grant none
|
// @grant none
|
||||||
// @version 1.11
|
// @version 1.12
|
||||||
// @author Lukáš Kucharczyk
|
// @author Lukáš Kucharczyk
|
||||||
// @description Removes duplicate entries in the list of movies on r18.dev.
|
// @description Removes duplicate entries in the list of movies on r18.dev.
|
||||||
// @downloadURL https://git.kucharczyk.xyz/lukas/userscripts/raw/branch/main/r18dev_remove_duplicates.user.js
|
// @downloadURL https://git.kucharczyk.xyz/lukas/userscripts/raw/branch/main/r18dev_remove_duplicates.user.js
|
||||||
// @supportURL https://git.kucharczyk.xyz/lukas/userscripts
|
// @supportURL https://git.kucharczyk.xyz/lukas/userscripts
|
||||||
|
// @run-at document-idle
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
function filterVideos() {
|
function filterVideos() {
|
||||||
// Select all .video containers
|
// Select all .video containers
|
||||||
const videos = document.querySelectorAll('.video');
|
const videos = document.querySelectorAll('.video');
|
||||||
console.log(`Found videos: ${videos.length}`)
|
|
||||||
|
// Only log if we find videos to avoid spamming console during observation
|
||||||
|
if (videos.length > 0) {
|
||||||
|
console.log(`Found videos: ${videos.length}`);
|
||||||
|
}
|
||||||
|
|
||||||
// Regex to match "Letters-Numbers" (e.g., AAA-111)
|
// Regex to match "Letters-Numbers" (e.g., AAA-111)
|
||||||
const regex = /[a-zA-Z]+-[0-9]+/;
|
const regex = /[a-zA-Z]+-[0-9]+/;
|
||||||
const removedCount = 0;
|
let removedCount = 0; // Changed to 'let' so it can be incremented
|
||||||
|
|
||||||
videos.forEach(video => {
|
videos.forEach(video => {
|
||||||
const label = video.querySelector('.video-label');
|
const label = video.querySelector('.video-label');
|
||||||
@@ -30,12 +35,37 @@ function filterVideos() {
|
|||||||
// Remove if text doesn't match pattern OR label has more than 1 link
|
// Remove if text doesn't match pattern OR label has more than 1 link
|
||||||
if (!regex.test(text) || linkCount > 1) {
|
if (!regex.test(text) || linkCount > 1) {
|
||||||
video.remove();
|
video.remove();
|
||||||
removedCount++
|
removedCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(`Removed videos: ${removedCount}`)
|
|
||||||
|
if (removedCount > 0) {
|
||||||
|
console.log(`Removed videos: ${removedCount}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the function
|
// 1. Run immediately in case elements are already there
|
||||||
filterVideos();
|
filterVideos();
|
||||||
|
|
||||||
|
// 2. Set up a MutationObserver to handle dynamic content (AJAX/Infinite Scroll)
|
||||||
|
const observer = new MutationObserver((mutations) => {
|
||||||
|
let shouldRun = false;
|
||||||
|
// Check if nodes were actually added
|
||||||
|
for (const mutation of mutations) {
|
||||||
|
if (mutation.addedNodes.length) {
|
||||||
|
shouldRun = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldRun) {
|
||||||
|
filterVideos();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start observing the body for changes
|
||||||
|
observer.observe(document.body, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user