Empornium Deluxe Mode

Enhances the empornium.me porn torrent website

As of 2018-04-22. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Empornium Deluxe Mode
// @namespace    http://tampermonkey.net/
// @version      1.02
// @description  Enhances the empornium.me porn torrent website
// @author       codingjoe
// @match        https://*.empornium.me/*
// @require      https://openuserjs.org/src/libs/sizzle/GM_config.js
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_addStyle
// @grant        GM_registerMenuCommand
// ==/UserScript==

GM_config.init({
  'id': 'EmporniumEnhancementsConfig',
  'title': 'Empornium Deluxe Mode Configuration',
  'fields': {
    'AlwaysHeader' : {
        'label': 'Always keep header in view',
        'type': 'checkbox',
        'default': false
    },
    'AutoOpenSpoilers': {
        'label': 'Auto-open hidden text / spoilers',
        'type': 'checkbox',
        'default': false
    },
    'ShowImages': {
        'label': 'Display hover images inline',
        'type': 'checkbox',
        'default': false
    },
    'ShowRatioGoals': {
        'label': 'Display ratio goals table on the Bonus Shop page (experimental)',
        'type': 'checkbox',
        'default': false
    },
    'JumpToTop': {
        'label': "Insert 'Jump to Top' link onto bottom-right corner of all pages",
        'type': 'checkbox',
        'default': false
    },
    'StripAnonym': {
        'label': 'Strip url anonymizers from links',
        'type': 'checkbox',
        'default': false
    },
    'PreventNewWindow': {
        'label': 'Prevent single-click links from opening a new window',
        'type': 'checkbox',
        'default': false
    },
    'HideSeeded': {
        'label': 'Hide currently seeding torrents',
        'type': 'checkbox',
        'default': false
    },
    'HideLeeching': {
        'label': 'Hide currently leeching torrents',
        'type': 'checkbox',
        'default': false
    },
    'HideGrabbed': {
        'label': 'Hide previously grabbed torrents [incomplete download]',
        'type': 'checkbox',
        'default': false
    },
    'HideSnatched': {
        'label': 'Hide previously snatched torrents [finished]',
        'type': 'checkbox',
        'default': false
    },
    'FilterTags': {
        'label': 'Hide torrents that contain any of the following tags:',
        'type': 'checkbox',
        'default': false
    },
    'TagListing': {
        'label': '(comma-separated list)',
        'type': 'textarea',
        'default': 'bbc, big.black.cock, bbw, fat, obese, hairy, gay, trans, tranny, transsexual, scat, feces, poop, puke, vomit, censored'
    }
  },
  'css': '#EmporniumEnhancementsConfig { background-color:#222222 !important; color:silver !important; } ' +
         '#EmporniumEnhancementsConfig_field_TagListing { width: 700px; height: 175px; background-color:grey; } ' +
         '#EmporniumEnhancementsConfig_ShowRatioGoals_var, #EmporniumEnhancementsConfig_PreventNewWindow_var, #EmporniumEnhancementsConfig_HideSnatched_var { border-bottom: 3px solid black !important; } ',
  'events': {
    'init': function() {
      // Set the value of the dummy field to the saved value
      //GM_config.set('customCSS', GM_config.get('validCSS'));
    },
    'open': function(doc) {
      // Use a listener to update the hidden field when the dummy field passes validation
      /*GM_config.fields['customCSS'].node.addEventListener('change', function () {
        // get the current value of the visible field
        var customCSS = GM_config.get('customCSS', true);

        // Only save valid CSS
        if (/\w+\s*\{\s*\w+\s*:\s*\w+[\s|\S]*\}/.test(customCSS)) {
          GM_config.set('validCSS', customCSS);
        }
      }, false);*/
    },
    'save': function(forgotten) {
      // reload on save
      location.reload();
    }
  }
});

GM_registerMenuCommand('Empornium Deluxe Mode Configuration', function () {
    GM_config.open();
});

function myRound(x, places) {
    var trunc = Math.pow(10, places);
	return Math.round(x * trunc) / trunc;
}

// wait until html document completely loaded to invoke script
(function() {
    'use strict';

    var loc = window.location.href;
    var page = loc.substring(loc.lastIndexOf("/") + 1, loc.indexOf(".php") + 4);
    var i;
    var strHtml;

    console.log("location: " + loc);

    if (loc === "https://www.empornium.me/") {
        var links = Array.from(document.getElementsByTagName("a"));

        links.forEach(function (link) {
            if (link.innerText === "Login") {
                window.location.href += "login";
            }
        });
    } else if (loc === "https://www.empornium.me/login") {
        var inputs = Array.from(document.getElementsByTagName("input"));

        inputs.forEach(function (input) {
            if (input.name === "username") {
                input.focus();
            }
        });
    }

    switch (page) {
        case "bonus.php":
            if (GM_config.get('ShowRatioGoals')) {
                var stats = document.getElementsByClassName("stat");
                var units = [ "KiB", "MiB", "GiB", "TiB" ];

                var ratio = parseFloat(stats[5].innerText);
                var down = stats[3].innerText;
                var up = stats[1].innerText;

                var upUnitsIdx = units.indexOf(up.substring(1 + up.indexOf(" ")));
                var downUnitsIdx = units.indexOf(down.substring(1 + down.indexOf(" ")));

                var unitsDiff = parseInt(Math.round(upUnitsIdx - downUnitsIdx));
                var displayUnits = units[downUnitsIdx];

                up = up.replace(/,/g, "");
                up = parseFloat(up.substring(0, up.indexOf(" ")));
                down = down.replace(/,/g, "");
                down = parseFloat(down.substring(0, down.indexOf(" ")));

                // convert totals to same units
                if (unitsDiff < 0) {
                    down *= Math.pow(1024, -unitsDiff);
                    displayUnits = units[upUnitsIdx];
                } else if (unitsDiff > 0) {
                    up *= Math.pow(1024, unitsDiff);
                }

                var diff = down / 100.0;
                var currAmount = Math.abs((ratio + 0.01) * down - up);

                strHtml = "<table style=\"text-align:center !important;margin: 0px auto; width:50%;\"><tbody><tr><td style=\"width:90px;text-align:center;\">U/L differential</td><td style=\"width:90px;text-align:center;\"> for ratio </td><td style=\"width:90px;text-align:center;\"> Amount to U/L </td></tr>";

                for (i = 1; i <= 10; i++) {
                    var currRatio = i/100.0 + ratio;

                    // alternate background color
                    var style = "";
                    if (i % 2 != 0) {
                        style = " style=\"background-color:#222222 !important;\"";
                    }

                    strHtml += "<tr" + style + "><td style=\"text-align:center;\"> +" + (i == 1 ? myRound(currAmount, 3) : myRound(diff, 3)) + " " + displayUnits + " </td><td style=\"text-align:center;\"> " + currRatio + " </td><td style=\"text-align:center;\"> " + myRound(currAmount, 3) + " " + displayUnits + " </td></tr>";

                    currAmount += diff;
                }

                strHtml += "</tbody></table>";

                var content = document.getElementById("content");
                content.innerHTML = strHtml + content.innerHTML;
            }


            break; // end bonus.php

        case "torrents.php":
        case "top10.php":
        case "user.php":
            if (page !== "user.php" && loc.indexOf("id=") > 0) {
                break;
            }

            /* hide content */
            var rows = Array.from(document.getElementsByClassName('torrent'));

            if (GM_config.get('FilterTags')) {
                var filters = GM_config.get('TagListing').trim().replace(/[\n\r]/g, '').replace(/ /g,"").split(',');
                rows.forEach(curr => {
                    var tags = curr.getElementsByClassName("tags")[0].innerText.split(" ");
                    filters.forEach(filter => {
                        if (tags.indexOf(filter) >= 0) {
                            curr.style = "display:none";
                        }
                    });
                });
            }

            if (GM_config.get('HideSeeded') || GM_config.get('HideGrabbed') || GM_config.get('HideSnatched') || GM_config.get('HideLeeching')) {
                rows.forEach(curr => {
                    if (GM_config.get('HideSeeded') && curr.innerHTML.indexOf("icon_disk_seed") >= 0) {
                        curr.style = "display:none";
                    } else if (GM_config.get('HideGrabbed') && curr.innerHTML.indexOf("icon_disk_grabbed") >= 0) {
                        curr.style = "display:none";
                    } else if (GM_config.get('HideSnatched') && curr.innerHTML.indexOf("icon_disk_snatched") >= 0) {
                        curr.style = "display:none";
                    } else if (GM_config.get('HideLeeching') && curr.innerHTML.indexOf("icon_disk_leech") >= 0) {
                        curr.style = "display:none";
                    }
                });
            }
            /* end hide content */

            /* display images inline */
            if (GM_config.get('ShowImages')) {
                rows.forEach(curr => {
                    strHtml = curr.getElementsByTagName("script")[0].innerHTML.replace(/[\[\]\{\}\(\)\\\|]/g, "");
                    var start = strHtml.indexOf("\"")+1;
                    var end = strHtml.lastIndexOf("\"");
                    strHtml = strHtml.substring(start, end);

                    curr.getElementsByClassName("cats_col")[0].innerHTML = strHtml;
                });
            }
            /* end display images inline */


            break; // end torrents.php
    } // end page switch

    if (GM_config.get('StripAnonym') || GM_config.get('PreventNewWindow')) {
        var links = Array.from(document.getElementsByTagName("a"));
        var needles = [ "http://anonym.to/?", "http://anon.now.im/?" ];

        links.forEach(link => {
            // strip anonymizer from link
            if (GM_config.get('StripAnonym')) {
                 needles.forEach(needle => {
                    if (link.href.indexOf(needle) >= 0) {
                        link.href = link.href.substring(needle.length, link.href.length);
                    }
                });
            }

            // prevent link from opening new window
            if (GM_config.get('PreventNewWindow')) {
                if (link.target.length > 0) {
                    link.target = '';
                }
            }
        });
    }

    // Jump to Top link in bottom-right corner
    if (GM_config.get('JumpToTop')) {
        document.getElementsByTagName("body")[0].innerHTML += "<div style=\"position: fixed; bottom: 5px; right: 5px; text-align: right;\"><a href=\"javascript:window.scrollTo(0, 0)\">Jump to Top</a></div>";
    }

    // always keep header in view
    if (document.getElementById("header") && GM_config.get('AlwaysHeader')) {
        document.getElementById("header").style.cssText = "position: fixed !important; top: 0px; left: 0px;";
        document.getElementById("content").style.cssText = "margin-top:120px;";
    }

    if (GM_config.get('AutoOpenSpoilers')) {
        document.querySelectorAll("a").forEach(function (curr) {
            if (curr.innerText === "Show") {
                curr.click();
            }
        });
    }
})();