Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Chain Watch
  3. // @namespace LordBusiness.CW
  4. // @version 1.9
  5. // @description Makes the chain watch a whole lot bigger.
  6. // @author LordBusiness [2052465]
  7. // @match https://www.torn.com/*
  8. // @exclude https://www.torn.com/loader.php?sid=attack*
  9. // @grant GM_addStyle
  10. // ==/UserScript==
  11.  
  12. GM_addStyle(`
  13. .lbschainoverlay {
  14. opacity: 0.8;
  15. position: fixed;
  16. height: 100px;
  17. width: 230px;
  18. top: 10px;
  19. right: 10px;
  20. left: calc(100% - 240px);
  21. border-radius: 10px;
  22. background-color: white;
  23. z-index: 6666;
  24. display: flex;
  25. justify-content: center;
  26. align-items: center;
  27. font-size: 5rem;
  28. font-Weight: bold;
  29. color: #2f2f2f;
  30. transition: all 1s;
  31. pointer-events: none;
  32. }
  33. .lbsvbig {
  34. height: 250px;
  35. width: 750px;
  36. top: 60px;
  37. right: center;
  38. bottom: 0;
  39. left: 0;
  40. font-Weight: bold;
  41. font-size: 16rem;
  42. }
  43. .lbschainlabel {
  44. display: none;
  45. }
  46. .lbsvbig .lbschainlabel {
  47. display: initial !important;
  48. }
  49. `);
  50.  
  51. document.getElementsByTagName("body")[0].insertAdjacentHTML("beforeend", `<div class="lbschainoverlay"></span><span class="lbschaintime"></span></div>`);
  52. const chainOverlay = document.querySelector(".lbschainoverlay");
  53.  
  54. var popupTimer;
  55. const displayOverlay = () => {
  56. chainOverlay.classList.add("lbsvbig");
  57. }
  58.  
  59. const barChainTime = "#barChain [class^=bar-stats] [class^=bar-timeleft]";
  60. const Chainregex = /(\d{2}):\d{2}/igm;
  61. const observerChainTime = new MutationObserver((mutations) => {
  62. let CTime = document.querySelector(barChainTime).innerText;
  63. chainOverlay.querySelector(".lbschaintime").innerHTML = CTime;
  64. let ChainTimeregAr = Chainregex.exec(CTime);
  65. if(ChainTimeregAr !== null && parseInt(ChainTimeregAr[1]) <= 2) {
  66. chainOverlay.classList.add("t-red");
  67. } else {
  68. chainOverlay.classList.remove("t-red");
  69. }
  70. })
  71.  
  72. const observeObserverCT = () => {
  73. observerChainTime.observe(document.querySelector(barChainTime).childNodes[0], { characterData: true })
  74. }
  75.  
  76. const observerSidebar = new MutationObserver((mutations) => {
  77. for (const mutation of mutations) {
  78. if (document.querySelector(barChainTime) !== null) {
  79. console.log("This is also working!!");
  80. observeObserverCT();
  81. observerSidebar.disconnect();
  82. }
  83. }
  84. })
  85.  
  86. const notInactive = () => {
  87. clearTimeout(popupTimer);
  88. chainOverlay.classList.remove("lbsvbig");
  89. popupTimer = setTimeout(displayOverlay, 15000);
  90. }
  91.  
  92. const pageVisibility = () => {
  93. var hidden = "hidden", hid;
  94.  
  95. if (hidden in document) {
  96. document.addEventListener("visibilitychange", onchange);
  97. } else if ((hidden = "mozHidden") in document) {
  98. document.addEventListener("mozvisibilitychange", onchange);
  99. } else if ((hidden = "webkitHidden") in document) {
  100. document.addEventListener("webkitvisibilitychange", onchange);
  101. } else if ((hidden = "msHidden") in document) {
  102. document.addEventListener("msvisibilitychange", onchange);
  103. } else if ('onfocusin' in document) {
  104. document.onfocusin = document.onfocusout = onchange;
  105. } else {
  106. window.onpageshow = window.onpagehide = window.onfocus = window.onblur = onchange;
  107. }
  108.  
  109. function onchange (evt) {
  110. var v = 'visible', h = 'hidden',
  111. evtMap = {
  112. focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h
  113. };
  114.  
  115. evt = evt || window.event;
  116. if (evt.type in evtMap) {
  117. hid = evtMap[evt.type];
  118. } else {
  119. hid = this[hidden] ? "hidden" : "visible";
  120. }
  121.  
  122. if(hid != "visible") {
  123. clearTimeout(popupTimer)
  124. }
  125. }
  126. };
  127. document.addEventListener('click', notInactive);
  128. document.addEventListener('keypress', notInactive);
  129. document.addEventListener('mousemove', notInactive);
  130.  
  131. if (document.querySelector(barChainTime) === null) {
  132. observerSidebar.observe(document.getElementById('sidebarroot'), { subtree: true, childList: true })
  133. } else {
  134. observeObserverCT();
  135. }
  136. pageVisibility();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement