millesimisec Clock figuccio

Clock millisecondi con salvataggio posizione

  1. // ==UserScript==
  2. // @name millesimisec Clock figuccio
  3. // @description Clock millisecondi con salvataggio posizione
  4. // @match *://*/*
  5. // @version 9.6
  6. // @author figuccio
  7. // @noframes
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @grant GM_registerMenuCommand
  11. // @namespace https://greasyfork.org/users/237458
  12. // @require http://code.jquery.com/jquery-latest.js
  13. // @require https://code.jquery.com/ui/1.13.2/jquery-ui.js
  14. // @icon data:image/gif;base64,R0lGODlhEAAQAKECABEREe7u7v///////yH5BAEKAAIALAAAAAAQABAAAAIplI+py30Bo5wB2IvzrXDvaoFcCIBeeXaeSY4tibqxSWt2RuWRw/e+UQAAOw==
  15. // @license MIT
  16. // ==/UserScript==
  17. (function() {
  18. 'use strict';
  19. var $ = window.jQuery.noConflict();
  20. const body = document.body;
  21. var box = document.createElement("div");
  22. box.id = "milli";
  23. box.title = 'trascina time';
  24. box.setAttribute("style", "background:blue;color:red;cursor:move;font-family:sans-serif;width:290px;font-size:16px;top:0px;line-height:21px;position:fixed;text-align:center;z-index:999999;");
  25.  
  26. // Recupera le coordinate salvate
  27. var savedPosition = GM_getValue("widget_position");
  28. if (savedPosition) {
  29. var [left, top] = savedPosition.split(",");
  30. box.style.left = left + "px";
  31. box.style.top = top + "px";
  32. }
  33.  
  34. document.body.appendChild(box);
  35. $(box).draggable({
  36. containment: "window", // Assicura che l'elemento draggable sia confinato alla finestra del browser
  37. stop: function() {
  38. // Salva le nuove coordinate quando si smette di trascinare il widget
  39. var position = $(this).position();
  40. GM_setValue("widget_position", position.left + "," + position.top);
  41. }
  42. });
  43. let use12HourFormat = GM_getValue('use12HourFormat', false); // Default è il formato 24 ore
  44. let language = GM_getValue('language') || 'it'; // Recupera la lingua dal localStorage o usa 'it' come predefinita
  45.  
  46. const languages = {
  47. en: { weekday: 'short', month: 'short', day: '2-digit', year: 'numeric' },
  48. it: { weekday: 'short', month: '2-digit', day: '2-digit', year: 'numeric' }
  49. };
  50. function tick() {
  51. const now = new Date();
  52. let hours = now.getHours();
  53. const minutes = String(now.getMinutes()).padStart(2, "0");
  54. const seconds = String(now.getSeconds()).padStart(2, "0");
  55. const milliseconds = String(now.getMilliseconds()).padStart(3, "0");
  56. const date = now.toLocaleString(language, languages[language]); // Usa la lingua selezionata per la data
  57.  
  58. let period = "";
  59.  
  60. if (!use12HourFormat) {
  61. period = hours >= 12 ? " PM" : " AM";
  62. hours = hours % 12 || 12; // Converte in formato 12 ore
  63. }
  64.  
  65. hours = String(hours).padStart(2, "0");
  66. document.getElementById("milli").textContent = `${hours}:${minutes}:${seconds}:${milliseconds}${period} ${date}`;
  67. }
  68.  
  69. tick();
  70. setInterval(tick, 70);
  71. function changeLanguage() {
  72. language = (language === 'it') ? 'en' : 'it';
  73. GM_setValue('language', language); // Salva la lingua scelta nel localStorage
  74. }
  75. function toggleFormat() {
  76. //Cambia il formato orario
  77. use12HourFormat = !use12HourFormat;
  78. GM_setValue('use12HourFormat', use12HourFormat); // Salva lo stato del formato
  79. }
  80. GM_registerMenuCommand("Cambia formato orario 12/24", toggleFormat);
  81. GM_registerMenuCommand("Cambia lingua datario", changeLanguage);
  82. //mostra nascondi time
  83. function myFunction2() {
  84. box.style.display = ((box.style.display!='none') ? 'none' : 'block');
  85. }
  86. GM_registerMenuCommand("mostra/nascondi", myFunction2);
  87. })();