util

TL;DR

当前为 2024-11-04 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/515720/1477820/util.js

  1. // ==UserScript==
  2. // @name util
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @license MIT
  6. // @description TL;DR
  7. // @author https://greasyfork.org/ja/users/705684
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. /**
  15. * format to HH:MM:SS
  16. * @param {Date} date JavaScript Date object
  17. * @return {string} HH:MM:SS
  18. */
  19. window.formatTime = date => {
  20. let d = date && date !== 0 ? new Date(date) : Date.now();
  21. d -= new Date().getTimezoneOffset() * 60 * 1000;
  22. d /= 1000;
  23. const s = (d | 0) % 60;
  24. d /= 60;
  25. const m = (d | 0) % 60;
  26. d /= 60;
  27. const h = (d | 0) % 24;
  28. return [h, m, s].map(v => v.toString().padStart(2, '0')).join(':');
  29. };
  30.  
  31. /**
  32. * calc PseudoRandom from seed
  33. * @param {string} seed
  34. * @return {number} 0 <= x < 1
  35. */
  36. window.pseudoRandomBy = async seed => {
  37. const [a, b] = new Uint8Array(await window.crypto.subtle.digest('SHA-1', (new TextEncoder()).encode(seed)));
  38. const unique = (a << 8) + b;
  39. return unique / 0x10000;
  40. };
  41. })();