Dragonrip Server Time

Server time display for Dragonrip.com

  1. // ==UserScript==
  2. // @name Dragonrip Server Time
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.0
  5. // @description Server time display for Dragonrip.com
  6. // @author Kronos1
  7. // @match *://*.dragonrip.com/*
  8. // @icon https://i.imgur.com/Vn0ku7D.png
  9. // @grant none
  10. // @license GPLv3
  11. // ==/UserScript==
  12.  
  13.  
  14. (() => {
  15. 'use strict';
  16.  
  17. const settings = {
  18. runningClock: true, // Keep updating clock time (updates every second)
  19. enableSeconds: false, // Include seconds in the time
  20. use24HourClock: true, // Toggle between 12h/24h time format
  21. fancyBox: false, // Additional styling for the time box element
  22. }
  23. const mainCss = `
  24. .dragonrip-server-time-cont > * {
  25. -webkit-box-sizing: border-box;
  26. -moz-box-sizing: border-box;
  27. box-sizing: border-box;
  28. user-select:none;
  29. }
  30.  
  31. .dragonrip-server-time-cont {
  32. border-radius:3px;
  33. float:right;
  34. display:flex;
  35. flex-direction:row;
  36. align-items:center;
  37. justify-content:space-between;
  38. background-repeat:repeat;
  39. background-size:contain;
  40. padding:3px 5px 3px 5px;
  41. font-size:0.8em;
  42. font-family:consolas,monospace;
  43. color:grey;
  44. text-shadow:
  45. 0px 0px 3px black,
  46. 0px 0px 3px black,
  47. 0px 0px 3px black,
  48. 0px 0px 3px black,
  49. 0px 0px 3px black,
  50. 0px 0px 3px black,
  51. 0px 0px 3px black
  52. ;
  53. position:absolute;
  54. bottom:0;
  55. right:0;
  56. }
  57.  
  58. .dragonrip-server-time-cont > .label {
  59. margin-right:10px;
  60. }
  61.  
  62. .dragonrip-server-time-cont > .time {
  63. color:#de6c09;
  64. }
  65.  
  66. body > .logo {
  67. position:relative;
  68. }
  69. `;
  70.  
  71. const fancyBoxCss = `
  72. .dragonrip-server-time-cont {
  73. border:2px solid rgba(255,255,255,0.15);
  74. background-image: url('https://i.imgur.com/vjJ8ugC.jpeg');
  75. box-shadow:0px 0px 5px 0px rgba(0,0,0,0.5);
  76. }
  77. `;
  78.  
  79. const getTime = () => {
  80. let options = {
  81. timeZone: 'UTC',
  82. hour: 'numeric',
  83. minute: 'numeric',
  84. hour12: true,
  85. }
  86.  
  87. if (settings.enableSeconds) { options.second = 'numeric'; }
  88. if (settings.use24HourClock) { options.hour12 = false; }
  89. const currentLocalDate = new Date (Date.now());
  90. const time = new Intl.DateTimeFormat([], options).format(currentLocalDate);
  91. return time;
  92. }
  93.  
  94.  
  95. const createClock = () => {
  96. const target = document.querySelector('body > div.logo');
  97.  
  98. const elem = document.createElement('div');
  99. elem.classList.add('dragonrip-server-time-cont');
  100. // Create text label
  101. const label = document.createElement('div');
  102. label.classList.add('label');
  103. label.innerHTML = 'Server time';
  104.  
  105. // Create time
  106. const time = document.createElement('div');
  107. time.classList.add('time');
  108. elem.append(label);
  109. elem.append(time);
  110. target.append(elem);
  111.  
  112. updateClock();
  113. if (settings.runningClock) {
  114. setInterval( () => {
  115. updateClock();
  116. }, 1000);
  117. }
  118. }
  119.  
  120. const updateClock = () => {
  121. const elem = document.querySelector('body > .logo > .dragonrip-server-time-cont > .time');
  122. elem.innerText = getTime();
  123. }
  124.  
  125.  
  126. // Wait for game UI to load, then insert custom element
  127. const waitForElem = () => {
  128. const checkElem = setInterval( () => {
  129. if (document.querySelector('ul.navbar') !== null) {
  130. clearInterval(checkElem);
  131. createClock();
  132. }
  133. }, 5);
  134. }
  135.  
  136.  
  137. const setCustomCss = str => {
  138. const styleElem = document.createElement("style");
  139. styleElem.textContent = str;
  140. document.body.appendChild(styleElem);
  141. }
  142.  
  143.  
  144. setCustomCss(mainCss);
  145. if (settings.fancyBox) { setCustomCss(fancyBoxCss); }
  146.  
  147. waitForElem();
  148. })();