Clock millisecondi
当前为
// ==UserScript==
// @name millesimisec Clock figuccio
// @description Clock millisecondi
// @include *
// @version 9
// @author figuccio
// @noframes
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_registerMenuCommand
// @namespace https://greasyfork.org/users/237458
// ==/UserScript==
var box = document.createElement("div");
box.id = "milli";
box.title = 'trascina time';
box.setAttribute("style", "background:blue;color:red;cursor:move; font-family:sans-serif; font-size:13pt; top:0px; line-height:21px; position:fixed; text-align:center; z-index:999999;");
document.body.appendChild(box);
function tick()
{
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
var ms = today.getMilliseconds();
m = checkTime(m);
s = checkTime(s);
function checkTime(i) {
if (i < 10) {i = "0" + i}; // aggiungi zero davanti ai numeri < 10
return i;
}
var options = {'weekday': 'long', 'month': 'long', 'day': '2-digit','year':'numeric'};
var date = new Date().toLocaleString('it-IT', options);
box.innerHTML = h + ":" + m + ":" + s+ ":" + ms + " "+date;
}
tick();
setInterval(tick, 70);
//mostra nascondi time
function myFunction2() {
box.style.display = ((box.style.display!='none') ? 'none' : 'block');
}
GM_registerMenuCommand("mostra/nascondi",myFunction2);
///////////////
//Make the DIV element draggagle:
dragElement(document.getElementById("milli"));
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;
}
}