mini clock

simple clock for full screen mode

2015/08/03のページです。最新版はこちら

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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