lukasbloom83 / Autoscore for Pornbay torrents

// ==UserScript==
// @name         Autoscore for Pornbay torrents
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Gives a score for every Pornbay torrent based on its tags, title and some user given preferences
// @author       lukasbloom83
// @include     /https?://pornbay\.org/bookmarks\.php.*/
// @include     /https?://pornbay\.org/torrents\.php.*/
// @include     /https?://pornbay\.org/collages\.php.*/
// @grant        none
// @license MIT
// @require http://code.jquery.com/jquery-3.3.1.min.js
// ==/UserScript==

this.jQuery = jQuery.noConflict(true);

(function() {
    'use strict';

    //***********************************************************************************
    // CONFIG START
    //***********************************************************************************

    // Do you want to reorder results by score (descending order)?
    let reorderResults = true;

    // Give a personal score for any tag you like
    let tagsScoreGood = {
        "double.blowjob": 2,
        "eye.rolling": 3,
        "oil": 3,
        "orgy": 2,
        "teen": 1,
        "tiny.teen": 2,
        "uncensored": 1,
        "pale.skin": 2,
        "shaved.pussy": 1,
        "cum.in.mouth": 1,
        "skinny": 2,
        "slim": 1,
        "redhead": 2,
        "petite": 1,
        "threesome": 1
    };

    // Give a personal score for any tag you don't like
    let tagsScoreBad = {
        "trimmed.pussy": -1,
        "hairy.pussy": -3,
        "solo": -4,
        "anal": -2,
        "camera.movement": -1,
        "milf": -2,
        "mature": -2,
        "interracial": -3,
        "big.areolas": -1
    };

    // Give a personal score for every porn studio you want
    let sitesScore = {
        "18vr.com": 3,
        "sexbabesvr.com": 2,
        "milfvr.com": -1
    };

    // Give a personal score for every pornstar you want
    let starsScore = {
        "alexis.crystal": 4,
        "alicia.williams": 1,
        "alina.lopez": 3,
        "anastasia.brokelyn": 6,
        "anna.claire.clouds": 2,
        "arietta.young": 6,
        "belle.claire": 4,
        "chloe.scott": 4,
        "cindy.shine": 8,
        "diana.grace": 2,
        "elle.rose": 4,
        "emily.willis": 4,
        "eva.elfie": 5,
        "evelyn.claire": 1,
        "frederica.fierce": 3,
        "haley.reed": 6,
        "jenny.wild": 4,
        "kali.roses": 3,
        "kenzie.reeves": 2,
        "kiara.cole": 1,
        "kyler.quinn": 1,
        "lily.adams": 6,
        "lily.larimar": 2,
        "linda.sweet": 1,
        "lovita.fate": 3,
        "megan.rain": 4,
        "nikki.hill": 3,
        "pamela.morrison": 4,
        "polina.maxim": 1,
        "rebecca.volpetti": 5,
        "sia.siberia": 2,
        "sweetie.plum": 1,
        "sybil.a": 2,
        "tera.link": 8,
        "uma.jolie": 7
    };

    // If the torrent has any of these tags, it will be hidden
    let hideTorrentsWith = ["censored", "gay", "transsexual", "shemale"];

    // You can add/substract points if any word appears in th title
    let titleWords = {
        "siterip": -10,
        "pack": -10,
        "compilation": -10
    }

    //***********************************************************************************
    // CONFIG ENDS
    //***********************************************************************************

    let scores = {...tagsScoreGood, ...tagsScoreBad, ...sitesScore, ...starsScore};
    let pageTorrents = [];
    jQuery('tr.torrent').each(function () {
        let torrentScore = 0;
        let torrentTags = [];
        let hiddenTorrent = false;
        jQuery('.tags a', this).each(function () {
            let tag = jQuery(this).text();
            if (hideTorrentsWith.includes(tag)) {
                hiddenTorrent = true;
                return false;
            } else {
                if (scores.hasOwnProperty(tag)) {
                    torrentScore = torrentScore + scores[tag];
                    torrentTags.push([tag, scores[tag]]);
                }
            }
        });
        if (!hiddenTorrent) {
            let scoreContent = jQuery('<div></div>');
            let scoreItem = jQuery('<div></div>').css('white-space', 'nowrap');
            // words in title
            let title = jQuery('td:nth-of-type(2) > a', this).html().toLowerCase();
            for(let word in titleWords) {
                if (title.indexOf(word) >= 0) {
                    torrentScore = torrentScore + titleWords[word];
                    torrentTags.push([word, titleWords[word]]);
                };
            }
            // total score
            let scoreTotal = scoreItem.clone().text('Total: ' + (torrentScore > 0 ? '+' : '') + torrentScore);
            if (torrentScore != 0)
                scoreTotal.css('color', torrentScore > 0 ? '#44aa44' : '#e52121');
            scoreContent.append(scoreTotal);
            // detailed score
            torrentTags.sort(function(a, b) {
                return b[1] - a[1];
            });
            for(let idx in torrentTags) {
                let scoreTag = scoreItem.clone().text(torrentTags[idx][0] + ': ' + (torrentTags[idx][1] > 0 ? '+' : '') + torrentTags[idx][1]);
                scoreTag.css('font-weight', 'normal');
                scoreTag.css('font-style', 'italic');
                scoreTag.css('color', torrentTags[idx][1] > 0 ? '#719e71' : '#bb7575');
                scoreTag.css('font-size', 'smaller');
                scoreContent.append(scoreTag);
            }
            jQuery('td:nth-of-type(3)', this).removeClass('center').html(scoreContent)
            pageTorrents.push([this, torrentScore]);
        }
    });

    jQuery('table.torrent_table tbody tr.torrent').remove();
    jQuery('table.torrent_table tbody tr.colhead td:nth-of-type(3)').text('Autoscore');
    if (reorderResults) {
        pageTorrents.sort(function(a, b) {
            return b[1] - a[1];
        });
    }
    for (let idx in pageTorrents) {
        jQuery('table.torrent_table tbody').append(pageTorrents[idx][0]);
    }
})();