Digital Clock & Date figuccio

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

As of 21.01.2020. See ბოლო ვერსია.

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

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

var use_date = true; // "true" to add date to page, "false" to not

var date_arrangement = "weekday day month  year"; // Ordina data left to right

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;bottom:0px;right:0px;padding:5px;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);

date_arrangement = date_arrangement.toLowerCase().split(" ");

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) {
		var Regexs = {
				weekday : /(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/,
				month : /(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/,
				day : /(\d+) 20\d{2}/,
				year : /20\d{2}/
			},
			date = Date();

		for(var i=0, l = date_arrangement.length; i < l; i++) {
			switch(date_arrangement[i]) {
				case "weekday":
				fulldate += date.match(Regexs["weekday"])[0] + ", "; break;
				case "month":
				fulldate += date.match(Regexs["month"])[0] + " "; break;
				case "day":
				fulldate += date.match(Regexs["day"])[1] + " "; break;
				case "year":
				fulldate += date.match(Regexs["year"])[0] + " "; break;
			}
		}
		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);

                       //sposta su e giu
 function myFunctiontu() {
  if (time_box.style.bottom === '595px') {
    time_box.style.bottom = '0px';
  } else {
    time_box.style.bottom = '595px';
  }
}
GM_registerMenuCommand("su/giu",myFunctiontu);