Clock figuccio

clock ore minuti secondi

当前为 2019-01-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Clock figuccio
  3. // @description clock ore minuti secondi
  4. // @version 1.0.0
  5. // @include *
  6. // @author figuccio
  7. // @grant GM_setValue
  8. // @grant GM_getValue
  9. // @grant GM_registerMenuCommand
  10. // @icon data:image/gif;base64,R0lGODlhEAAQAKECABEREe7u7v///////yH5BAEKAAIALAAAAAAQABAAAAIplI+py30Bo5wB2IvzrXDvaoFcCIBeeXaeSY4tibqxSWt2RuWRw/e+UQAAOw==
  11.  
  12. // @namespace https://greasyfork.org/users/237458
  13. // ==/UserScript==
  14.  
  15. /*==================================================================================*/
  16. const clockSettings = {
  17. opacity: '', // Controls CSS Opacity and needs a value from 0 to 1
  18. fontSize: '20px', // Sets the size of the clock.
  19. is12hour: false, // Toggles between 24 hour or 12 hour clock.
  20. font: 'Arial', // Allow a custom font
  21. }
  22. /*==================================================================================*/
  23.  
  24. function setStyles(styles) {
  25. styles.forEach(style => node.style.setProperty(style.name, style.value));
  26. }
  27.  
  28. function changeOpacity(newOpacity){
  29. node.style.setProperty('opacity', newOpacity);
  30. }
  31.  
  32. function updateClock() {
  33. let date = new Date();
  34. let time = date.toLocaleString('ita', {
  35. hour: 'numeric',
  36. minute: 'numeric',
  37. second: 'numeric',
  38. day :'numeric',
  39. month :'numeric',
  40. year:'numeric',
  41. weekday:'long',
  42. hour12: clockSettings.is12hour
  43. });
  44. node.innerHTML = time;
  45. }
  46.  
  47. function isFullscreen() {
  48. return (window.fullScreen ||
  49. (window.innerWidth == screen.width && window.innerHeight == screen.height) ||
  50. (window.innerWidth >= screen.width && window.innerHeight >= screen.height) || /* Fix for chrome when zoom is < 100% */
  51. (!window.screenTop && !window.screenY))
  52. }
  53.  
  54. let node = document.createElement('div');
  55. let textnode = document.createTextNode('');
  56. node.appendChild(textnode);
  57. setStyles([
  58. { name: 'position', value: 'fixed'},
  59. { name: 'bottom', value: '0' },
  60. { name: '', value: '0' },
  61. { name: 'background-color', value: 'red' },
  62. { name: 'color', value: 'white' },
  63. { name: 'z-index', value: '99999' },
  64. { name: 'font-size', value: clockSettings.fontSize },
  65. { name: 'padding', value: '17px 4px' },
  66. { name: 'border-radius', value: '4px' },
  67. { name: 'border', value: '1px solid rgba(250, 250, 250, 0.3)' },
  68. { name: 'margin', value: '2px' },
  69. { name: 'font-family', value: '"' + clockSettings.font + '", sans-serif' },
  70. ]);
  71. document.body.appendChild(node);
  72.  
  73. setInterval(() => updateClock(), 1000);
  74. window.addEventListener('resize', () => changeOpacity((isFullscreen())? clockSettings.opacity : '0'));
  75. node.addEventListener('mouseout', () => changeOpacity(clockSettings.opacity));
  76.