mini clock

simple clock for full screen mode

Verze ze dne 03. 08. 2015. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        mini clock
// @namespace   gnblizz
// @description simple clock for full screen mode
// @version     1.02
// @include     *
// @noframes
// @grant       GM_setValue
// @grant       GM_getValue
// @grant       GM_registerMenuCommand
// @icon        data:image/gif;base64,R0lGODlhEAAQAKECABEREe7u7v///////yH5BAEKAAIALAAAAAAQABAAAAIplI+py30Bo5wB2IvzrXDvaoFcCIBeeXaeSY4tibqxSWt2RuWRw/e+UQAAOw==
// ==/UserScript==

/* This user script inserts the system time in the upper right corner of the browser window. This is especially useful 
 * in full screen mode, where the task bar clock is hidden.
 * If something is obscured by the time display, select "hide mini clock" from the context menu of the time display.
 * To set the minimum width for the clock to appear, resize the browser window to that width and select "mini clock set min width" from the "user script commands" sub menu of the greasemonkey menu.
 */

function miniClockSetWidth() {
  if(GM_setValue) {
    GM_setValue('miniClockMinWidth', window.outerWidth);
    alert('New treshold width is '+window.outerWidth+' pixel.');
  }
}

if(GM_registerMenuCommand && GM_setValue) {
  GM_registerMenuCommand('mini clock set min width', miniClockSetWidth, 'w');
}

var miniClockData = [];
{
  miniClockData["hTimer"] = null;
  miniClockData["div"] = document.createElement('div');
  miniClockData["datePattern"] = (function(){
    switch(navigator.language.slice(0,2)){
    case 'de': return '%A, %e. %B %Y'; // e.g: 'Donnerstag, 16. Juli 2015'
    case 'en': return /-US/i.test(navigator.language) ? '%A%n%B %e, %Y' : '%A%n%e %B %Y';
    }
    return '%A, %x';
  }());
  miniClockData.div.setAttribute('id', 'GMMiniClock');
  addStyle('#GMMiniClock{display:none;position:fixed!important;top:0px;right:0px;width:auto;color:#E8E8E8;background-color:#181818;border:1px solid gray;padding:1px 7px;font:18pt normal sans-serif;z-index:2147483647;}');
  document.body.appendChild(miniClockData.div);
/*
 I've decideded to not use toLocaleTimeString anymore. Some countries add an AM/PM there, but I intended to strip the seconds with ".slice(0,-3)" witch will not work properly then.
 Howewer, nobody bothered to report to me!
 Now, I just compose the time string by hours and minutes separaded by colon. That should give the cheap wrist watch look I wanted.
 Most people can tell by feel, if it's morning or afternoon anyway.
 */
  miniClockData["OnTimer"] = function() {
    var dt = new Date(), t = niceTime(dt); // t = dt.toLocaleTimeString().slice(0,-3);
    if(miniClockData.div.innerHTML != t) {
      miniClockData.div.innerHTML = t;
      if(!miniClockData.div.title || (!dt.getHours() && !dt.getMinutes()))
	miniClockData.div.title = niceDate(dt);
    }
  }
  miniClockData["OnReSize"] = function() {
    var minWidth = 0;
    if(GM_getValue) minWidth = GM_getValue('miniClockMinWidth');
    if(!minWidth || minWidth >= window.screen.availWidth) minWidth = window.screen.availWidth;
    if(window.outerWidth >= minWidth) {
      miniClockData.div.style.display = "block";
      if(!miniClockData.hTimer) {
        miniClockData.OnTimer();
        miniClockData.hTimer = setInterval(miniClockData.OnTimer, 1900);
      }
    } else {
      miniClockData.div.style.display = "none";
      if(miniClockData.hTimer) {
        clearInterval(miniClockData.hTimer);
        miniClockData.hTimer = null;
      }
    }
  }
  miniClockData.OnReSize();/*init*/
  if(miniClockData.div.offsetTop) {  /*check for unsupported file (such as .css) */
    if(miniClockData.hTimer)
      clearInterval(miniClockData.hTimer);
    miniClockData.div.parentNode.removeChild(miniClockData.div);
    miniClockData.div = null;
  } else {
    window.onresize = miniClockData.OnReSize;
    var menu=document.createElement('menu');
    menu.setAttribute('type','context');
    menu.setAttribute('id','miniClockMenu');
    menu.innerHTML='<menuitem label="hide mini clock" onclick="document.getElementById(\'GMMiniClock\').style.visibility=\'hidden\';"></menuitem>';
    document.body.appendChild(menu);
    miniClockData.div.setAttribute('contextmenu','miniClockMenu');
    if(document.domain == 'monkeyguts.com')
      miniClockData.div.style.top = '32px';
  }
}
function niceTime(d) {
  //return ("0"+d.getHours()).slice(-2) + ':' + ("0"+d.getMinutes()).slice(-2);
  return d.toLocaleFormat('%R');
}
function niceDate(d) { // I'd need some help here!
  return d.toLocaleFormat(miniClockData.datePattern);
  // toLocaleDateString() uses an outdated short format at my system for 'de-DE'.
}
function addStyle(style) {
  var o = document.createElement("STYLE");
  o.innerHTML = style;
  document.getElementsByTagName('HEAD')[0].appendChild(o);
}

//public domain by gnblizz