Empornium Deluxe Mode

Enhances the empornium.me porn torrent website

目前為 2019-02-09 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Empornium Deluxe Mode
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.04
  5. // @description Enhances the empornium.me porn torrent website
  6. // @author codingjoe
  7. // @match https://*.empornium.me/*
  8. // @require https://openuserjs.org/src/libs/sizzle/GM_config.js
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @grant GM_addStyle
  12. // @grant GM_registerMenuCommand
  13. // ==/UserScript==
  14.  
  15. var $ = function (inpt) {
  16. switch (inpt) {
  17. case "location.href":
  18. return window.location.href;
  19. break;
  20.  
  21. default:
  22. return document.querySelectorAll(inpt);
  23. break;
  24. }
  25. };
  26.  
  27. GM_config.init({
  28. 'id': 'EmporniumEnhancementsConfig',
  29. 'title': 'Empornium Deluxe Mode Configuration',
  30. 'fields': {
  31. 'AlwaysHeader' : {
  32. 'label': 'Always keep header in view',
  33. 'type': 'checkbox',
  34. 'default': false
  35. },
  36. 'AutoDismiss': {
  37. 'label': 'Auto-dismiss login timeout notification',
  38. 'type': 'checkbox',
  39. 'default': false
  40. },
  41. 'AutoOpenSpoilers': {
  42. 'label': 'Auto-open hidden text / spoilers',
  43. 'type': 'checkbox',
  44. 'default': false
  45. },
  46. 'ShowImages': {
  47. 'label': 'Display hover images inline',
  48. 'type': 'checkbox',
  49. 'default': false
  50. },
  51. 'ShowRatioGoals': {
  52. 'label': 'Display ratio goals table on the Bonus Shop page (experimental)',
  53. 'type': 'checkbox',
  54. 'default': false
  55. },
  56. 'JumpToTop': {
  57. 'label': "Insert 'Jump to Top' link onto bottom-right corner of all pages",
  58. 'type': 'checkbox',
  59. 'default': false
  60. },
  61. 'StripAnonym': {
  62. 'label': 'Strip url anonymizers from links',
  63. 'type': 'checkbox',
  64. 'default': false
  65. },
  66. 'CopyClearBottomNotifs': {
  67. 'label': 'Notifications - Move "clear" and "clear selected" links onto bottom of matched groups',
  68. 'type': 'checkbox',
  69. 'default': false
  70. },
  71. 'PreventNewWindow': {
  72. 'label': 'Prevent single-click links from opening a new window',
  73. 'type': 'checkbox',
  74. 'default': false
  75. },
  76. 'HideSeeded': {
  77. 'label': 'Hide currently seeding torrents',
  78. 'type': 'checkbox',
  79. 'default': false
  80. },
  81. 'HideLeeching': {
  82. 'label': 'Hide currently leeching torrents',
  83. 'type': 'checkbox',
  84. 'default': false
  85. },
  86. 'HideGrabbed': {
  87. 'label': 'Hide previously grabbed torrents [incomplete download]',
  88. 'type': 'checkbox',
  89. 'default': false
  90. },
  91. 'HideSnatched': {
  92. 'label': 'Hide previously snatched torrents [finished]',
  93. 'type': 'checkbox',
  94. 'default': false
  95. },
  96. 'FilterTags': {
  97. 'label': 'Hide torrents that contain any of the following tags:',
  98. 'type': 'checkbox',
  99. 'default': false
  100. },
  101. 'TagListing': {
  102. 'label': '(comma-separated list)',
  103. 'type': 'textarea',
  104. 'default': 'bbc, big.black.cock, bbw, fat, obese, hairy, gay, trans, tranny, transsexual, scat, feces, poop, puke, vomit, censored'
  105. }
  106. },
  107. 'css': '#EmporniumEnhancementsConfig { background-color:#222222 !important; color:silver !important; } ' +
  108. '#EmporniumEnhancementsConfig_field_TagListing { width: 700px; height: 175px; background-color:grey; } ' +
  109. '#EmporniumEnhancementsConfig_ShowRatioGoals_var, #EmporniumEnhancementsConfig_PreventNewWindow_var, #EmporniumEnhancementsConfig_HideSnatched_var { border-bottom: 3px solid black !important; } ',
  110. 'events': {
  111. 'init': function() {
  112. // Set the value of the dummy field to the saved value
  113. //GM_config.set('customCSS', GM_config.get('validCSS'));
  114. },
  115. 'open': function(doc) {
  116. // Use a listener to update the hidden field when the dummy field passes validation
  117. /*GM_config.fields['customCSS'].node.addEventListener('change', function () {
  118. // get the current value of the visible field
  119. var customCSS = GM_config.get('customCSS', true);
  120.  
  121. // Only save valid CSS
  122. if (/\w+\s*\{\s*\w+\s*:\s*\w+[\s|\S]*\}/.test(customCSS)) {
  123. GM_config.set('validCSS', customCSS);
  124. }
  125. }, false);*/
  126. },
  127. 'save': function(forgotten) {
  128. // reload on save
  129. location.reload();
  130. }
  131. }
  132. });
  133.  
  134. GM_registerMenuCommand('Empornium Deluxe Mode Configuration', function () {
  135. GM_config.open();
  136. });
  137.  
  138. function myRound(x, places) {
  139. var trunc = Math.pow(10, places);
  140. return Math.round(x * trunc) / trunc;
  141. }
  142.  
  143. // wait until html document completely loaded to invoke script
  144. (function() {
  145. 'use strict';
  146.  
  147. if (GM_config.get('AutoDismiss')) {
  148. if (document.querySelectorAll("#flashClose").length > 0) {
  149. document.querySelector("#flashClose").click()
  150. }
  151. }
  152.  
  153. var loc = $("location.href");
  154. var page = loc.substring(loc.lastIndexOf("/") + 1, loc.indexOf(".php") + 4);
  155. var i;
  156. var strHtml;
  157.  
  158. console.log("#location#: " + loc + ", page: " + page);
  159.  
  160. if (loc === "https://www.empornium.me/") {
  161. $("a").forEach(function (link) {
  162. if (link.innerText === "Login") {
  163. window.location.href += "login";
  164. }
  165. });
  166. } else if (loc === "https://www.empornium.me/login") {
  167. $("input").forEach(function (input) {
  168. if (input.name === "username") {
  169. input.focus();
  170. }
  171. });
  172. }
  173.  
  174. switch (page) {
  175. case "bonus.php":
  176. if (GM_config.get('ShowRatioGoals')) {
  177. var stats = document.getElementsByClassName("stat");
  178. var units = [ "KiB", "MiB", "GiB", "TiB" ];
  179.  
  180. var ratio = parseFloat(stats[5].innerText);
  181. var down = stats[3].innerText;
  182. var up = stats[1].innerText;
  183.  
  184. var upUnitsIdx = units.indexOf(up.substring(1 + up.indexOf(" ")));
  185. var downUnitsIdx = units.indexOf(down.substring(1 + down.indexOf(" ")));
  186.  
  187. var unitsDiff = parseInt(Math.round(upUnitsIdx - downUnitsIdx));
  188. var displayUnits = units[downUnitsIdx];
  189.  
  190. up = up.replace(/,/g, "");
  191. up = parseFloat(up.substring(0, up.indexOf(" ")));
  192. down = down.replace(/,/g, "");
  193. down = parseFloat(down.substring(0, down.indexOf(" ")));
  194.  
  195. // convert totals to same units
  196. if (unitsDiff < 0) {
  197. down *= Math.pow(1024, -unitsDiff);
  198. displayUnits = units[upUnitsIdx];
  199. } else if (unitsDiff > 0) {
  200. up *= Math.pow(1024, unitsDiff);
  201. }
  202.  
  203. var diff = down / 100.0;
  204. var currAmount = Math.abs((ratio + 0.01) * down - up);
  205.  
  206. 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>";
  207.  
  208. for (i = 1; i <= 10; i++) {
  209. var currRatio = i/100.0 + ratio;
  210.  
  211. // alternate background color
  212. var style = "";
  213. if (i % 2 != 0) {
  214. style = " style=\"background-color:#222222 !important;\"";
  215. }
  216.  
  217. 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>";
  218.  
  219. currAmount += diff;
  220. }
  221.  
  222. strHtml += "</tbody></table>";
  223.  
  224. var content = document.querySelector("#content");
  225. content.innerHTML = strHtml + content.innerHTML;
  226. }
  227.  
  228.  
  229. break; // end bonus.php
  230.  
  231. case "torrents.php":
  232. if (GM_config.get("CopyClearBottomNotifs") && loc.indexOf("torrents.php?action=notify") >= 0) {
  233. console.log("action=notify");
  234. $(".torrent_table").forEach(t => {
  235. var ps = t.previousSibling.previousSibling;
  236. var c = ps.cloneNode(true);
  237. t.parentNode.insertBefore(c, t.nextSibling);
  238. ps.innerHTML = ps.innerHTML.toString().match(/(\w+\s){4}/gm);
  239. });
  240. }
  241.  
  242. case "top10.php":
  243. case "user.php":
  244. if (page !== "user.php" && loc.indexOf("id=") > 0) {
  245. break;
  246. }
  247.  
  248. /* hide content */
  249. var rows = $(".torrent");
  250.  
  251. if (GM_config.get('FilterTags')) {
  252. var filters = GM_config.get('TagListing').trim().replace(/[\n\r]/g, '').replace(/ /g,"").split(',');
  253. rows.forEach(curr => {
  254. var tags = curr.querySelector(".tags").innerText.split(" ");
  255. filters.forEach(filter => {
  256. if (tags.indexOf(filter) >= 0) {
  257. curr.style = "display:none";
  258. }
  259. });
  260. });
  261. console.log("Completed filter tags");
  262. }
  263.  
  264. if (GM_config.get('HideSeeded') || GM_config.get('HideGrabbed') || GM_config.get('HideSnatched') || GM_config.get('HideLeeching')) {
  265. rows.forEach(curr => {
  266. if (GM_config.get('HideSeeded') && curr.innerHTML.indexOf("icon_disk_seed") >= 0) {
  267. curr.style = "display:none";
  268. } else if (GM_config.get('HideGrabbed') && curr.innerHTML.indexOf("icon_disk_grabbed") >= 0) {
  269. curr.style = "display:none";
  270. } else if (GM_config.get('HideSnatched') && curr.innerHTML.indexOf("icon_disk_snatched") >= 0) {
  271. curr.style = "display:none";
  272. } else if (GM_config.get('HideLeeching') && curr.innerHTML.indexOf("icon_disk_leech") >= 0) {
  273. curr.style = "display:none";
  274. }
  275. });
  276. console.log("Completed hide torrents");
  277. }
  278. /* end hide content */
  279.  
  280. /* display images inline */
  281. if (GM_config.get('ShowImages')) {
  282. console.log("display images inline");
  283. rows.forEach(curr => {
  284. if (curr.querySelectorAll("script").length > 0) {
  285. strHtml = curr.querySelector("script").innerHTML.replace(/[\[\]\{\}\(\)\\\|]/g, "");
  286. var start = strHtml.indexOf("\"")+1;
  287. var end = strHtml.lastIndexOf("\"");
  288. strHtml = strHtml.substring(start, end);
  289.  
  290. var div = document.createElement("div");
  291. if (curr.querySelectorAll(".cats_col").length > 0) {
  292. Array.from(curr.querySelector(".cats_col").childNodes).forEach(n => {
  293. if (n.title !== undefined) {
  294. n.style.display = "none";
  295. }
  296. });
  297. div.innerHTML = strHtml;
  298. curr.querySelector(".cats_col").appendChild(div);
  299. } else if (curr.querySelectorAll(".cats_cols").length > 0) {
  300. Array.from(curr.querySelector(".cats_cols").childNodes).forEach(n => {
  301. if (n.title !== undefined) {
  302. n.style.display = "none";
  303. }
  304. });
  305. div.innerHTML = strHtml;
  306. curr.querySelector(".cats_cols").appendChild(div);
  307. }
  308. }
  309. });
  310. console.log("Completed display images inline");
  311. }
  312. /* end display images inline */
  313.  
  314.  
  315. break; // end torrents.php
  316. } // end page switch
  317.  
  318. if (GM_config.get('StripAnonym') || GM_config.get('PreventNewWindow')) {
  319. var needles = [ "http://anonym.to/?", "http://anon.now.im/?" ];
  320.  
  321. $("a").forEach(link => {
  322. // strip anonymizer from link
  323. if (GM_config.get('StripAnonym')) {
  324. needles.forEach(needle => {
  325. if (link.href.indexOf(needle) >= 0) {
  326. link.href = link.href.substring(needle.length, link.href.length);
  327. }
  328. });
  329. }
  330.  
  331. // prevent link from opening new window
  332. if (GM_config.get('PreventNewWindow')) {
  333. if (link.target.length > 0) {
  334. link.target = '';
  335. }
  336. }
  337. });
  338. }
  339.  
  340. // Jump to Top link in bottom-right corner
  341. if (GM_config.get('JumpToTop')) {
  342. var jumpDiv = document.createElement("div");
  343. var anchor = document.createElement("a");
  344. Object.assign(jumpDiv.style, {
  345. position: "fixed",
  346. bottom: "5px",
  347. right: "5px",
  348. textAlign: "right"
  349. });
  350. anchor.innerText = "Jump to Top";
  351. anchor.href = "javascript:window.scrollTo(0, 0)";
  352. jumpDiv.appendChild(anchor);
  353. document.body.appendChild(jumpDiv);
  354. }
  355.  
  356. // always keep header in view
  357. if ($("#header").length > 0 && GM_config.get('AlwaysHeader')) {
  358. $("#header")[0].style.cssText = "position: fixed !important; top: 0px; left: 0px;";
  359. $("#content")[0].style.cssText = "margin-top:120px;";
  360. }
  361.  
  362. // auto open spoilers
  363. if (GM_config.get('AutoOpenSpoilers')) {
  364. // find all BBCode spoiler links
  365. $("a[onclick='BBCode.spoiler(this);']").forEach(curr => {
  366. // if the element is hidden
  367. if (curr.innerText === "Show") {
  368. // click to unhide
  369. curr.click();
  370. }
  371. });
  372. }
  373. })();