Digital Clock & Date figuccio

digital clock e la data facoltativa in basso a destra sullo schermo

目前為 2020-06-11 提交的版本,檢視 最新版本

// ==UserScript==
// @name           Digital Clock & Date figuccio
// @namespace https://gf.qytechs.cn/users/237458
// @description    digital clock e la data facoltativa in basso a destra sullo schermo
// @include     *
// @version        1.2
// @noframes
// @grant          GM_getValue
// @grant          GM_registerMenuCommand
// @grant          GM_setValue
// @grant          GM_xmlhttpRequest
// ==/UserScript==

var AM_PM = false; // "true"  TIME AM/PM 12am-12pm.
                  // "false"  TIME 00:00-24:00

var use_date = true; // "true" si date , "false" no data

if(document.getElementById("digital_clock") !== null) throw "";

var time_box = document.createElement("div");
time_box.setAttribute("id", "digital_clock");
time_box.setAttribute("style","position:fixed;padding:5px;cursor:move;color:lime;background:black;border:1px solid red;border-radius:6px;font-size:14px;font-family:sans-serif, arial, verdana; z-index:99999999;");
document.body.insertBefore(time_box, document.body.firstChild);

function setTime() {
	var period = "",
		DateArr = new Array(),
		fulldate = "",
		date = new Date();

		DateArr["hours"] = date.getHours(),
		DateArr["minutes"] = date.getMinutes().toString(),
		DateArr["seconds"] = date.getSeconds().toString();

	// Renderlo am / pm se l'impostazione è attiva
	if(AM_PM) {
		if(DateArr["hours"]>12) {DateArr["hours"]-=12; period=" pm";} else period=" am";
		if(DateArr["hours"]==0) DateArr["hours"]=12;
	}
	DateArr["hours"] = DateArr["hours"].toString();

	if(DateArr["hours"].length==1 && !AM_PM) DateArr["hours"]="0"+DateArr["hours"]; // Correct the 1 digit glitch
	if(DateArr["minutes"].length==1) DateArr["minutes"]="0"+DateArr["minutes"]; // Correct the 1 digit glitch
	if(DateArr["seconds"].length==1) DateArr["seconds"]="0"+DateArr["seconds"]; // Correct the 1 digit glitch

	// Gestire la disposizione della data
	if(use_date === true) {
let options = {'day':'2-digit','year':'numeric','month':'long','weekday':'long'};
let date = new Date().toLocaleDateString('it-IT', options);
		if(fulldate === "") fulldate = date;
	}

	time_box.textContent = DateArr["hours"]+":"+DateArr["minutes"]+":"+DateArr["seconds"]+period+
		(use_date?("  "+fulldate):""); // Aggiungi data se abilitato
	window.setTimeout(setTime, 1000);
}

window.setTimeout(setTime, 0);
                 //mostra nascondi orologio
                function myFunctiont() {
  if (time_box.style.display === 'none') {
    time_box.style.display = 'block';
  } else {
    time_box.style.display = 'none';
  }
}
GM_registerMenuCommand("nascondi/mostra",myFunctiont);

////////////
//Make the DIV element draggagle:
dragElement(document.getElementById("digital_clock"));

function dragElement(elmnt) {
  var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
  if (document.getElementById(elmnt.id + "header")) {
    /* if present, the header is where you move the DIV from:*/
    document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
  } else {
    /* otherwise, move the DIV from anywhere inside the DIV:*/
    elmnt.onmousedown = dragMouseDown;
  }

  function dragMouseDown(e) {
    e = e || window.event;
    e.preventDefault();
    // get the mouse cursor position at startup:
    pos3 = e.clientX;
    pos4 = e.clientY;
    document.onmouseup = closeDragElement;
    // call a function whenever the cursor moves:
    document.onmousemove = elementDrag;
  }

  function elementDrag(e) {
    e = e || window.event;
    e.preventDefault();
    // calculate the new cursor position:
    pos1 = pos3 - e.clientX;
    pos2 = pos4 - e.clientY;
    pos3 = e.clientX;
    pos4 = e.clientY;
    // set the element's new position:
    elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
    elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
  }

  function closeDragElement() {
    /* stop moving when mouse button is released:*/
    document.onmouseup = null;
    document.onmousemove = null;
  }
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址