Chaturbate Advanced Filters

Adds more features to the chaturbate website filters such as age and keyword searching filtering. Look for these features under the normal options gear.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Chaturbate Advanced Filters
// @namespace    http://tampermonkey.net/
// @version      1.03
// @description  Adds more features to the chaturbate website filters such as age and keyword searching filtering. Look for these features under the normal options gear.
// @author       [email protected]
// @match        *chaturbate.com/*
// @icon         https://static-assets.highwebmedia.com/favicons/favicon.ico
// @grant        none
// @license      MIT
// ==/UserScript==

const defaultHomepage = "https://chaturbate.com/tag/milf/female/"; //homepage redirect
const minAgeDefault = '30'; //default min age
const maxAgeDefault = ''; //default max age
const keywordDefaults = '-squirt'; //list of keywords (or negative keywords) separated by commas

// Keep track of changes to the DOM and update as needed
let timer;
let targetNode = document.getElementsByClassName("roomlist_container")[0];
let config = { attributes: true, childList: true, subtree: true };
let callback = (mutationList, observer) => {
    if (timer) clearTimeout(timer);
    timer = setTimeout(() => { initialize(); }, 1000);
};
let observer = new MutationObserver(callback);
observer.observe(targetNode, config);

homepageRedirect();
addFilters();

function initialize(){
    showHideRoomCards();
}

function addFilters(){
    const searchMenu = document.getElementsByClassName("advance-search-element")[0];

    // Age filter
    // **************************************************

    const ageFilter = document.createElement("div");
    const ageLabel = document.createElement("label");
    const ageMin = document.createElement("input");
    const ageMax = document.createElement("input");
    const ageSeparator = document.createElement("span");

    ageFilter.id = "age-filter";
    ageLabel.innerHTML = "Age:   ";

    ageMin.type = "text";
    ageMin.id = "age-min";
    ageMin.value = minAgeDefault;

    ageSeparator.innerHTML = "  -  ";

    ageMax.type = "text";
    ageMax.id = "age-max";
    ageMax.value = maxAgeDefault;

    ageFilter.appendChild(ageLabel);
    ageFilter.appendChild(ageMin);
    ageFilter.appendChild(ageSeparator);
    ageFilter.appendChild(ageMax);

    searchMenu.appendChild(ageFilter);
    searchMenu.insertBefore(addStyleBlock(), ageFilter);

    ageMin.addEventListener("change", (event) => {
        showHideRoomCards();
    });

    ageMax.addEventListener("change", (event) => {
        showHideRoomCards();
    });


    // Keyword filter
    // **************************************************

    const keywordFilter = document.createElement("div");
    const keywordLabel = document.createElement("label");
    const keywordList = document.createElement("input");

    keywordFilter.id = "keyword-filter";
    keywordLabel.innerHTML = "keywords:   ";

    keywordList.type = "text";
    keywordList.id = "keyword-list";
    keywordList.value = keywordDefaults;

    keywordFilter.appendChild(keywordLabel);
    keywordFilter.appendChild(keywordList);

    searchMenu.appendChild(keywordFilter);
    searchMenu.insertBefore(addStyleBlock(), keywordFilter);

    keywordList.addEventListener("change", (event) => {
        showHideRoomCards();
    });

    keywordList.addEventListener("change", (event) => {
        showHideRoomCards();
    });
}

function showHideRoomCards(){
    var minAge = document.getElementById("age-min").value;
    var maxAge = document.getElementById("age-max").value;
    var keywordList = document.getElementById("keyword-list").value;

    var rooms = document.getElementsByClassName("roomCard");
    for (let i = 0; i < rooms.length; ++i) {
        // Age check
        var ages = rooms[i].getElementsByClassName("age");
        var age = (ages[0] !== undefined) ? ages[0].innerHTML : '';
        var showAge = false;
        if ((age >= minAge || minAge == "") && (age <= maxAge || maxAge == "")){ showAge = true; }

        // Keyword check
        var subjects = rooms[i].getElementsByClassName("subject");
        var subject = (subjects[0] !== undefined) ? subjects[0].innerHTML : "";

        var keywords = keywordList.split(",");
        var showKeyword = true;

        if(subject != "" && keywords != ""){
            for (let k = 0; k < keywords.length; ++k) {
                if(keywords[k].startsWith("-") == true && subject.includes(keywords[k].substring(1).toLowerCase())){
                    showKeyword = false;
                }
                if(keywords[k].startsWith("-") == false && !subject.includes(keywords[k].toLowerCase() in subject)){
                    showKeyword = false;
                }
            }}

        if(showAge == true && showKeyword == true){
            rooms[i].dataset.hide = false;
            rooms[i].style.display = "list-item";
        } else {
            rooms[i].dataset.hide = true;
            rooms[i].style.display = "none !important";
        }
    }
}

function homepageRedirect(){
    if(window.location.href == "https://chaturbate.com/"){
        window.location.replace(defaultHomepage);
        return false;
    } else { return true; }
}

function addStyleBlock(){
    var cssBlock = document.createElement("style");
    cssBlock.innerHTML = "" +
        "#improvedSearch { height: 50px; }" +
        "" +
        "#age-min,#age-max { width:20px; }" +
        "body li[data-hide='true'] {display:none !important; }" +
        "";
    return cssBlock;
}

function insertAfter(referenceNode, newNode) {
    referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}