showClock figuccio

Mostra un orologio in un angolo di ogni pagina web.

目前為 2024-02-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name           showClock figuccio
// @namespace      https://greasyfork.org/users/237458
// @description    Mostra un orologio in un angolo di ogni pagina web.
// @match          *://*/*
// @license        MIT
// @author         figuccio
// @version        0.7
// @grant          GM_setValue
// @grant          GM_getValue
// @grant          GM_registerMenuCommand
// @grant          GM_addStyle
// @noframes
// ==/UserScript==
makeMenuToggle("rightleft", true, "Orologio sul lato destro►", "Orologio sul lato sinistro◄", );
makeMenuToggle("bottomtop", true, "Orologio in fondo alla pagina↕", "Orologio all'inizio della pagina↕", );
makeMenuToggle("displayhide", true, "Mostra orologio", "Nascondi l'orologio", );

if (rightleft) horizontal = "right";
else horizontal = "left";
if (bottomtop) vertical = "bottom";
else vertical = "top";
if (displayhide) displayClock = "block";
else displayClock = "none";

// menuGM functions
// ---------------------------------------------------------------------
function makeMenuToggle(key, defaultValue, toggleOn, toggleOff, prefix) {
  // Carica il valore corrente in variabile
  window[key] = GM_getValue(key, defaultValue);
  //Attiva / disattiva menu
  GM_registerMenuCommand((prefix ? prefix+": " : "") + (window[key] ? toggleOff : toggleOn), function() {
  GM_setValue(key, !window[key]);
  location.reload();
  });
}

// mostra l'orologio iniziale e prepara la data
setInterval(showClock,70);
function showClock() {
var d = new Date();
var t = d.toLocaleTimeString();
var mm = d.getMilliseconds();//millisecondi settembre 2023
    ////////////////short  long
var date = new Date().toLocaleString('it', {'weekday': 'short', 'month': '2-digit', 'day': '2-digit','year':'numeric'});

if (document.getElementById("clockDiv")) document.getElementById("clockDiv").innerHTML = date +" "+ t +":"+ mm;
}

  // creare un elemento orologio
  var clock = document.createElement('div');
  clock.id = "clockDiv";
  clock.title = 'Time';
  clock.setAttribute("style", "position: fixed;"+horizontal+": 0px; "+vertical+": 0px; font-family:arial; font-size: 18px; z-index:99999999!important; background-color:red; color:white; border: 2px solid blue; width:auto; padding-left:2px; padding-right:2px;");
  document.body.appendChild(clock);
 ////////////////////////////
// aggiungi stile per la stampa(mostra nasconde clock)
  var head, style;
  head = document.getElementsByTagName('head')[0];
  if (!head) { return; }
  style = document.createElement('style');
  style.type = 'text/css';
  style.innerHTML = "@media print {div#clockDiv {display:none;}} @media screen {div#clockDiv {display:"+displayClock+";}}";
  head.appendChild(style);

showClock();