// ==UserScript==
// @name Empornium Deluxe Mode
// @namespace http://tampermonkey.net/
// @version 1.04
// @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==
var $ = function (inpt) {
switch (inpt) {
case "location.href":
return window.location.href;
break;
default:
return document.querySelectorAll(inpt);
break;
}
};
GM_config.init({
'id': 'EmporniumEnhancementsConfig',
'title': 'Empornium Deluxe Mode Configuration',
'fields': {
'AlwaysHeader' : {
'label': 'Always keep header in view',
'type': 'checkbox',
'default': false
},
'AutoDismiss': {
'label': 'Auto-dismiss login timeout notification',
'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
},
'CopyClearBottomNotifs': {
'label': 'Notifications - Move "clear" and "clear selected" links onto bottom of matched groups',
'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';
if (GM_config.get('AutoDismiss')) {
if (document.querySelectorAll("#flashClose").length > 0) {
document.querySelector("#flashClose").click()
}
}
var loc = $("location.href");
var page = loc.substring(loc.lastIndexOf("/") + 1, loc.indexOf(".php") + 4);
var i;
var strHtml;
console.log("#location#: " + loc + ", page: " + page);
if (loc === "https://www.empornium.me/") {
$("a").forEach(function (link) {
if (link.innerText === "Login") {
window.location.href += "login";
}
});
} else if (loc === "https://www.empornium.me/login") {
$("input").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;\"> " + myRound(currRatio, 3) + " </td><td style=\"text-align:center;\"> " + myRound(currAmount, 3) + " " + displayUnits + " </td></tr>";
currAmount += diff;
}
strHtml += "</tbody></table>";
var content = document.querySelector("#content");
content.innerHTML = strHtml + content.innerHTML;
}
break; // end bonus.php
case "torrents.php":
if (GM_config.get("CopyClearBottomNotifs") && loc.indexOf("torrents.php?action=notify") >= 0) {
console.log("action=notify");
$(".torrent_table").forEach(t => {
var ps = t.previousSibling.previousSibling;
var c = ps.cloneNode(true);
t.parentNode.insertBefore(c, t.nextSibling);
ps.innerHTML = ps.innerHTML.toString().match(/(\w+\s){4}/gm);
});
}
case "top10.php":
case "user.php":
if (page !== "user.php" && loc.indexOf("id=") > 0) {
break;
}
/* hide content */
var rows = $(".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.querySelector(".tags").innerText.split(" ");
filters.forEach(filter => {
if (tags.indexOf(filter) >= 0) {
curr.style = "display:none";
}
});
});
console.log("Completed filter tags");
}
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";
}
});
console.log("Completed hide torrents");
}
/* end hide content */
/* display images inline */
if (GM_config.get('ShowImages')) {
console.log("display images inline");
rows.forEach(curr => {
if (curr.querySelectorAll("script").length > 0) {
strHtml = curr.querySelector("script").innerHTML.replace(/[\[\]\{\}\(\)\\\|]/g, "");
var start = strHtml.indexOf("\"")+1;
var end = strHtml.lastIndexOf("\"");
strHtml = strHtml.substring(start, end);
var div = document.createElement("div");
if (curr.querySelectorAll(".cats_col").length > 0) {
Array.from(curr.querySelector(".cats_col").childNodes).forEach(n => {
if (n.title !== undefined) {
n.style.display = "none";
}
});
div.innerHTML = strHtml;
curr.querySelector(".cats_col").appendChild(div);
} else if (curr.querySelectorAll(".cats_cols").length > 0) {
Array.from(curr.querySelector(".cats_cols").childNodes).forEach(n => {
if (n.title !== undefined) {
n.style.display = "none";
}
});
div.innerHTML = strHtml;
curr.querySelector(".cats_cols").appendChild(div);
}
}
});
console.log("Completed display images inline");
}
/* end display images inline */
break; // end torrents.php
} // end page switch
if (GM_config.get('StripAnonym') || GM_config.get('PreventNewWindow')) {
var needles = [ "http://anonym.to/?", "http://anon.now.im/?" ];
$("a").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')) {
var jumpDiv = document.createElement("div");
var anchor = document.createElement("a");
Object.assign(jumpDiv.style, {
position: "fixed",
bottom: "5px",
right: "5px",
textAlign: "right"
});
anchor.innerText = "Jump to Top";
anchor.href = "javascript:window.scrollTo(0, 0)";
jumpDiv.appendChild(anchor);
document.body.appendChild(jumpDiv);
}
// always keep header in view
if ($("#header").length > 0 && GM_config.get('AlwaysHeader')) {
$("#header")[0].style.cssText = "position: fixed !important; top: 0px; left: 0px;";
$("#content")[0].style.cssText = "margin-top:120px;";
}
// auto open spoilers
if (GM_config.get('AutoOpenSpoilers')) {
// find all BBCode spoiler links
$("a[onclick='BBCode.spoiler(this);']").forEach(curr => {
// if the element is hidden
if (curr.innerText === "Show") {
// click to unhide
curr.click();
}
});
}
})();