Clock2

Show time right.

目前为 2019-04-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Clock2
  3. // @description Show time right.
  4. // @author figuccio
  5. // @version 0.1
  6. // @namespace https://greasyfork.org/users/237458
  7. // @include *
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js
  9. // ==/UserScript==
  10.  
  11. if( top.location != location ) return;
  12.  
  13. Number.prototype.pad = function(size) {
  14. if( typeof(size) !== "number" ) {
  15. size = 2;
  16. }
  17. var s = String(this);
  18. while (s.length < size) {
  19. s = "0" + s;
  20. }
  21. return s;
  22. }
  23.  
  24. var tod = document.createElement("div");
  25. tod.id = "todClock";
  26.  
  27. tod.setAttribute(
  28. "style",
  29.  
  30. "bottom:50px;" +
  31. "color:black;" +
  32. "font-family:droid sans mono;" +
  33. "font-size:16pt;" +
  34. "line-height:20px;" +
  35. "position:fixed;" +
  36. "right:4px;" +
  37. "text-align:center;" +
  38. "z-index:9999;" +
  39. " background-color:White;"+
  40. "-moz-user-select:none;"
  41.  
  42. );
  43.  
  44. var clicker = document.createAttribute( "onClick" );
  45. clicker.nodeValue = "document.getElementById('todClock').style.display = 'none';";
  46. tod.setAttributeNode(clicker)
  47.  
  48. function tick() {
  49. var d = new Date();
  50. var Y = d.getFullYear();
  51. var M = (d.getMonth()+1).pad();
  52. var D = d.getDate().pad();
  53. var h = d.getHours().pad();
  54. var m = d.getMinutes().pad();
  55. var s = d.getSeconds().pad();
  56. tod.innerHTML =D + "-" + M + "-" + Y + " " + h + ":" + m + ":" + s;
  57. }
  58.  
  59. tick();
  60. setInterval(tick, 500);
  61.  
  62. $('html body').append(tod);
  63.