Clock2

Show time drag

目前為 2025-03-29 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Clock2
  3. // @description Show time drag
  4. // @author figuccio
  5. // @version 0.6
  6. // @namespace https://greasyfork.org/users/237458
  7. // @match *://*/*
  8. // @noframes
  9. // @grant GM_addStyle
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM_registerMenuCommand
  13. // @require https://code.jquery.com/jquery-3.6.0.min.js
  14. // @require https://code.jquery.com/ui/1.12.1/jquery-ui.js
  15. // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
  16. // @license MIT
  17. // ==/UserScript==
  18. (function() {
  19. 'use strict';
  20. const $ = window.jQuery.noConflict();
  21. const body=document.body;
  22.  
  23. var todVisible = true; // Variabile per monitorare se l'orologio è visibile o meno
  24. // Funzione per salvare la posizione dell'orologio nella memoria locale
  25. function saveClockPosition(x, y) {
  26. GM_setValue('clockPosition', JSON.stringify({ x: x, y: y }));
  27. }
  28.  
  29. // Funzione per caricare la posizione dell'orologio dalla memoria locale
  30. function loadClockPosition() {
  31. const savedPosition = GM_getValue('clockPosition');
  32. if (savedPosition) {
  33. const position = JSON.parse(savedPosition);
  34. tod.style.left = position.x + 'px';
  35. tod.style.top = position.y + 'px';
  36. }
  37. }
  38.  
  39. // Aggiungi comandi di menu per mostrare e nascondere l'orologio
  40. GM_registerMenuCommand("Mostra/Nascondi orologio", function() {
  41. if (todVisible) {
  42. $(tod).hide();
  43. todVisible = false;
  44. } else {
  45. $(tod).show();
  46. todVisible = true;
  47. }
  48. });
  49.  
  50. ////////////////////////
  51.  
  52. if( top.location != location ) return;
  53.  
  54. Number.prototype.pad = function(size) {
  55. if( typeof(size) !== "number" ) {
  56. size = 2;
  57. }
  58. var s = String(this);
  59. while (s.length < size) {
  60. s = "0" + s;
  61. }
  62. return s;
  63. }
  64.  
  65. var tod = document.createElement("div");
  66. tod.id = "todClock";
  67.  
  68. tod.setAttribute("style", `
  69. top: 0;
  70. color: black;
  71. font-family: "Droid Sans Mono";
  72. font-size: 16pt;
  73. line-height: 20px;
  74. position: fixed;
  75. text-align: center;
  76. z-index: 99999999999;
  77. background-color: green;
  78. -moz-user-select: none;
  79. cursor: move;
  80. `);
  81.  
  82.  
  83. function tick() {
  84. var d = new Date();
  85. var Y = d.getFullYear();
  86. var M = (d.getMonth()+1).pad();
  87. var D = d.getDate().pad();
  88. var h = d.getHours().pad();
  89. var m = d.getMinutes().pad();
  90. var s = d.getSeconds().pad();
  91. var ms = d.getMilliseconds();
  92. tod.innerHTML=h + ":" + m + ":" + s + ":" + ms + "-" + D + "/" + M + "/" + Y;
  93. }
  94.  
  95. $(tod).draggable({
  96. containment: "window", // Assicura che l'elemento draggable sia confinato alla finestra del browser
  97. stop: function(event, ui) {
  98. saveClockPosition(ui.position.left, ui.position.top);
  99. }
  100. });
  101.  
  102. body.append(tod);
  103.  
  104. loadClockPosition(); // Carica la posizione dell'orologio dalla memoria locale
  105. tick();
  106. setInterval(tick, 70);
  107.  
  108. })();