Coomer Video Filter

Filters posts without videos on Coomer

20.09.2024 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Coomer Video Filter
// @namespace    http://coomer.su
// @version      1.4
// @description  Filters posts without videos on Coomer
// @match        https://*.coomer.party/*/user/*
// @match        https://*.kemono.party/*/user/*
// @match        https://*.coomer.su/*/user/*
// @match        https://*.kemono.su/*/user/*
// @grant        none
// ==/UserScript==

(async function() {
    'use strict';

    // Helper function to wait for elements that may load dynamically
    async function querySelectorAsync(selector) {
        return await new Promise(resolve => {
            let elm = document.querySelector(selector);
            if (elm) return resolve(elm);

            const observer = new MutationObserver(mutations => {
                elm = document.querySelector(selector);
                if (elm) {
                    resolve(elm);
                    observer.disconnect();
                }
            });
            observer.observe(document.body, { childList: true, subtree: true });
        });
    }

    // Function to check if a post contains a video
    async function hasVideo(postUrl) {
        return new Promise(resolve => {
            fetch(postUrl)
                .then(response => response.text())
                .then(html => {
                    const parser = new DOMParser();
                    const doc = parser.parseFromString(html, "text/html");
                    const videoExists = doc.querySelector("video") !== null;
                    resolve(videoExists);
                })
                .catch(err => {
                    console.error("Error fetching post:", postUrl, err);
                    resolve(false); // Assume no video if error occurs
                });
        });
    }

    // Function to filter out posts without videos
    async function filterVideos() {
        const posts = [...(await querySelectorAsync(".card-list__items")).children];
        for (let post of posts) {
            const postLink = post.querySelector("a")?.href;
            if (postLink) {
                const videoPresent = await hasVideo(postLink);
                if (!videoPresent) {
                    post.remove(); // Remove post if it doesn't have a video
                }
            }
        }
    }

    // Add a filter button to the page to trigger the video filtering
    async function addFilterButton() {
        const filterBtn = document.createElement("button");
        filterBtn.textContent = "Filter Videos";
        filterBtn.style = "position: fixed; top: 10px; right: 10px; z-index: 9999;";
        filterBtn.onclick = function() {
            filterBtn.remove(); // Remove button after it's clicked
            filterVideos(); // Start filtering videos
        };

        const form = await querySelectorAsync("form"); // Wait for a form element to append the button to
        form.appendChild(filterBtn);
    }

    // Add the filter button when the page loads
    addFilterButton();

})();