Block New Player

No more s-tier post in General Discussion

  1. // ==UserScript==
  2. // @name Block New Player
  3. // @namespace microbes.torn.blocknewplayer
  4. // @version 0.1
  5. // @description No more s-tier post in General Discussion
  6. // @author Microbes
  7. // @match https://www.torn.com/forums.php*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=torn.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. let UID_LIMIT = parseInt(localStorage.getItem(`block_new_user_uid_limit`) || 3100000);
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Start mutation observsor
  19. let currentUrl = window.location.href;
  20.  
  21. function onUrlChange() {
  22. if (window.location.href == 'https://www.torn.com/forums.php' || window.location.href == 'https://www.torn.com/forums.php#/p=main') {
  23. waitForElementToExist('#updates').then((elm) => {
  24. $('#updates .update-wrap').prepend(`
  25. <div class="dashboard w3" role="heading" aria-level="6">
  26. <div class="title-black title-toggle active" role="button" aria-expanded="false">
  27. <i class="arrow"></i>
  28. Block New User Topic
  29. </div>
  30. <ul class="panel fm-list cont-gray bottom-round">
  31. <li class="rating w3">
  32. <label class='bold' for='block_uid_limit'>Starting From:</label> <input id="block_uid_limit" class="input-text" type="number" data-lpignore="true" value="${UID_LIMIT}">
  33. </li>
  34. </ul>
  35. </div>
  36.  
  37. <hr class="delimiter-999 m-top10 m-bottom10">
  38. `);
  39.  
  40. $('#block_uid_limit').change(() => {
  41. UID_LIMIT = $('#block_uid_limit').val()
  42. localStorage.setItem(`block_new_user_uid_limit`, UID_LIMIT);
  43. });
  44. });
  45. }
  46. else {
  47. waitForElementToExist('.forums-committee-wrap .pagination').then((elm) => {
  48. $('.starter .user').each((i, element) => {
  49. var uid = $(element).prop('href').split('=')[1]
  50.  
  51. if (uid >= UID_LIMIT) {
  52. $(element).parent().parent().parent().parent().remove();
  53. }
  54. });
  55. });
  56. }
  57. }
  58.  
  59. const observer = new MutationObserver(function(mutations) {
  60. if (currentUrl !== window.location.href) {
  61. currentUrl = window.location.href;
  62. onUrlChange();
  63. }
  64. });
  65.  
  66. observer.observe(document.body, { childList: true, subtree: true });
  67.  
  68. // Initial call
  69. onUrlChange();
  70. })();
  71.  
  72. function waitForElementToExist(selector) {
  73. return new Promise(resolve => {
  74. if (document.querySelector(selector)) {
  75. return resolve(document.querySelector(selector));
  76. }
  77.  
  78. const observer = new MutationObserver(() => {
  79. if (document.querySelector(selector)) {
  80. resolve(document.querySelector(selector));
  81. observer.disconnect();
  82. }
  83. });
  84.  
  85. observer.observe(document.body, {
  86. subtree: true,
  87. childList: true,
  88. });
  89. });
  90. }