DH3 Tick Pulse

Pulses each tick to aid in counting various things (e.g. shark bite).

目前为 2020-10-08 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name DH3 Tick Pulse
  3. // @namespace com.anwinity.dh3
  4. // @version 1.0.1
  5. // @description Pulses each tick to aid in counting various things (e.g. shark bite).
  6. // @author Anwinity
  7. // @match dh3.diamondhunt.co
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. const PULSE_DURATION = 1000;
  15. const KEY_TOP = "dh3-tick-pulse-top";
  16. const KEY_LEFT = "dh3-tick-pulse-left";
  17.  
  18. function init() {
  19. if(!window.var_username) {
  20. setTimeout(init, 1000);
  21. return;
  22. }
  23.  
  24. let fontAwesome = document.createElement("script");
  25. fontAwesome.src = "https://kit.fontawesome.com/044e12ee28.js"
  26. fontAwesome.crossorigin = "anonymous";
  27. fontAwesome.type = "text/javascript";
  28. $("head").append(fontAwesome);
  29.  
  30. let top = localStorage.getItem(KEY_TOP);
  31. let left = localStorage.getItem(KEY_LEFT);
  32.  
  33. const styles = document.createElement("style");
  34. styles.textContent = `
  35. #dh3-tick-pulse {
  36. width: 100px;
  37. height: 100px;
  38. position: absolute;
  39. left: ${left}px;
  40. top: ${top}px;
  41. z-index: 9999;
  42. padding: 0.25em;
  43. border: 1px solid rgb(64, 64, 64);
  44. border-radius: 2px;
  45. background-color: rgb(26, 26, 26);
  46. padding: 0px;
  47. margin: 0px;
  48. }
  49. #dh3-tick-pulse.collapsed {
  50. width: 32px !important;
  51. height: 32px !important;
  52. }
  53. #dh3-tick-pulse-circle-container {
  54. width: 80px;
  55. height: 80px;
  56. }
  57. #dh3-tick-pulse.collapsed > #dh3-tick-pulse-circle-container {
  58. display: none;
  59. }
  60. #dh3-tick-pulse-circle-container > .circle {
  61. width: 0px;
  62. height: 0px;
  63. margin-top: 0px;
  64. margin-left: 0px;
  65. -webkit-border-radius: 40px;
  66. -moz-border-radius: 40px;
  67. border-radius: 40px;
  68. background: rgb(42, 200, 200);
  69. opacity: 1;
  70. position: absolute;
  71. top: 50%;
  72. left: 50%;
  73. }
  74. .dh3-tick-pulse-button {
  75. color: rgb(196, 196, 196);
  76. position: absolute;
  77. left: 0px;
  78. top: 0px;
  79. cursor: pointer;
  80. opacity: 0.75;
  81. }
  82. .dh3-tick-pulse-button:hover {
  83. color: rgb(255, 255, 255);
  84. background-color: rgb(39, 39, 39);
  85. opacity: 1.0;
  86. }
  87. #dh3-tick-pulse-drag-message {
  88. display: none;
  89. position: absolute;
  90. width: 100%;
  91. text-align: center;
  92. bottom: 0px;
  93. opacity: 1;
  94. }
  95.  
  96. `;
  97. $("head").append(styles);
  98.  
  99. $("body").prepend(`
  100. <div id="dh3-tick-pulse">
  101. <div id="dh3-tick-plus" class="dh3-tick-pulse-button" style="display: none">
  102. <i class="far fa-plus-square"></i>
  103. </div>
  104. <div id="dh3-tick-minus" class="dh3-tick-pulse-button">
  105. <i class="far fa-minus-square"></i>
  106. </div>
  107. <div id="dh3-tick-pulse-drag-message">DRAG ME</div>
  108. <div id="dh3-tick-pulse-circle-container"></div>
  109. </div>
  110. `);
  111.  
  112. $("#dh3-tick-plus").click(function() {
  113. $("#dh3-tick-pulse").removeClass("collapsed");
  114. $("#dh3-tick-plus").hide();
  115. $("#dh3-tick-minus").show();
  116. });
  117. $("#dh3-tick-minus").click(function() {
  118. $("#dh3-tick-pulse").addClass("collapsed");
  119. $("#dh3-tick-minus").hide();
  120. $("#dh3-tick-plus").show();
  121. });
  122.  
  123. let el = $("#dh3-tick-pulse");
  124. el.draggable({
  125. appendTo: "body",
  126. containment: "document",
  127. cursor: "pointer"
  128. });
  129. el.on("dragstop", function(event, ui) {
  130. localStorage.setItem(KEY_TOP, ui.position.top);
  131. localStorage.setItem(KEY_LEFT, ui.position.left);
  132. });
  133.  
  134. function pulse() {
  135. let container = $("#dh3-tick-pulse-circle-container");
  136. let circle = $('<div class="circle"></div>');
  137. circle.animate({
  138. "width": "80px",
  139. "height": "80px",
  140. "margin-top": "-40px",
  141. "margin-left": "-40px",
  142. "opacity": 0
  143. }, PULSE_DURATION, "swing");
  144. container.append(circle);
  145. setTimeout(function() {
  146. circle.remove();
  147. }, PULSE_DURATION);
  148. };
  149.  
  150. const originalSetItems = window.setItems;
  151. window.setItems = function(data) {
  152. originalSetItems.apply(this, arguments);
  153. if(data.includes("playtime~")) {
  154. pulse();
  155. }
  156. let el = $("#dh3-tick-pulse");
  157. if(el.is(":hidden") && (!var_monsterName || var_monsterName != "none")) {
  158. let dragMessage = $("#dh3-tick-pulse-drag-message");
  159. dragMessage.show();
  160. dragMessage.css("opacity", 1);
  161. dragMessage.animate({
  162. opacity: 0
  163. }, 2000);
  164. setTimeout(function() {
  165. dragMessage.hide();
  166. }, 2000);
  167. el.show();
  168. }
  169. else if(el.is(":visible") && (var_monsterName && var_monsterName == "none")) {
  170. el.hide();
  171. }
  172. }
  173. }
  174.  
  175. $(init);
  176. })();