FA Rating Filter

On furaffinity.net, hides thumbnails according to desired rating(s) and/or art medium.

Versione datata 03/05/2017. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         FA Rating Filter
// @namespace    FurAffinity
// @version      1.01
// @description  On furaffinity.net, hides thumbnails according to desired rating(s) and/or art medium.
// @author       Toboe
// @grant        none
// @run-at       document-end
// @match        *://*.furaffinity.net/*
// @require      https://code.jquery.com/jquery-latest.js
// ==/UserScript==

(function() {
        'use strict';

        console.log("FA Rating Filter");

        const $ = jQuery;

        const artRatings = {
            general: { key: 'general', classId: 'r-general', on: true},
            mature: { key: 'mature', classId: 'r-mature', on: true},
            adult: { key: 'adult', classId: 'r-adult', on: true}
        };

        const artTypes = {
            img: { key: 'image', classId: 't-image', on: true},
            txt: { key: 'text', classId: 't-text', on: true},
            audio: { key: 'audio', classId: 't-audio', on: true}
        };

        const updateFilteredView = function() {
            for(let rating in artRatings) {
                for(let type in artTypes) {
                    let selector = 'figure.' + artRatings[rating].classId + '.' + artTypes[type].classId;
                    let figure = $(selector);
                    figure.each(function(){
                            $(this).toggle(artRatings[rating].on && artTypes[type].on);
                       }
                    );
                }
            }
        };

        const attachPoint = $("body");
        if (attachPoint.length) {
            attachPoint.prepend(`
<input type="checkbox" id="generalControl" checked /> <strong>General</strong>
<input type="checkbox" id="matureControl" checked /> <strong>Mature</strong>
<input type="checkbox" id="adultControl" checked /> <strong>Adult</strong>
<input type="checkbox" id="imageControl" checked /> <strong>Images</strong>
<input type="checkbox" id="textControl" checked /> <strong>Writing</strong>
<input type="checkbox" id="audioControl" checked /> <strong>Music</strong>
            `);
        }

        const checkboxChanged = function(key) {
            let isOn = $('#' + key + 'Control').prop('checked');
            for(let rating in artRatings) {
                if(artRatings[rating].key === key) {
                    artRatings[rating].on = isOn;
                }
            }
            for(let type in artTypes) {
                if(artTypes[type].key === key) {
                    artTypes[type].on = isOn;
                }
            }
            updateFilteredView();
        };

        for(let rating in artRatings) {
            $('#' + artRatings[rating].key + 'Control').click(function() { checkboxChanged(artRatings[rating].key); } );
        }
        for(let type in artTypes) {
            $('#' + artTypes[type].key + 'Control').click(function() { checkboxChanged(artTypes[type].key); } );
        }

        updateFilteredView();
    }
)();