time

ora-data

当前为 2020-06-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name time
  3. // @namespace https://greasyfork.org/users/237458
  4. // @version 0.2
  5. // @description ora-data
  6. // @author figuccio
  7. // @include *
  8. // @noframes
  9. // @run-at document-start
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM_registerMenuCommand
  13. // @require https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js
  14. // ==/UserScript==
  15. jQuery.noConflict();
  16. (function($) {
  17. $(document).ready(function() {
  18. addGlobalStyle(`
  19. .timebox {
  20. position: fixed;
  21. top:0px;
  22. right:0px;
  23. z-index:999999;
  24. width: 150px;
  25. height: 60px;
  26. margin: 0;
  27. text-align: center;
  28. background-color: rgba(246, 246, 246,.5);
  29. border-radius: 10px;
  30. border:2px solid red;
  31. }
  32. .day,
  33. .time {
  34. width: 100%;
  35. height: 30px;
  36. font-size: 25px;
  37. color:green;
  38. line-height:30px;
  39. }
  40. `);
  41. //Aggiungi casella
  42. var box = $("<div class='timebox' id=testtimebox><div class='day' id='day'></div><div class='time' id='time'>");
  43. $("body").append(box);
  44. var date = new Date();
  45.  
  46. var year = date.getFullYear();
  47. var month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1);
  48. var day2 = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
  49. var day1 = day2 + '-' + month + '-' +year ;
  50. ////////////////////////////////////////////
  51. var hour = date.getHours();
  52. var minu = date.getMinutes();
  53. var sec = date.getSeconds();
  54.  
  55. var time1 = hour + ':' + minu + ':' + sec;
  56. $("#day").text(day1);
  57. $("#time").text(time1);
  58. var flag=0;//Segno dell'anno bisestile
  59. var d=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  60. window.setInterval(add, 1000);
  61.  
  62. function add() {
  63. sec++;
  64. if (sec >= 60) {
  65. sec = 0;
  66. minu++;
  67. }
  68. if (minu >= 60) {
  69. minu = 0;
  70. hour++;
  71. }
  72. if (hour >= 24) {
  73. hour = 0;
  74. day2++;
  75. }
  76.  
  77. //anno bisestile
  78. if(year%400==0||(year%4==0&&year%100!=0))
  79. flag=1;
  80. //Aumento del mese
  81. if(month==2){
  82. if(flag==1){
  83. if(day2>d[month]+1){
  84. month++;
  85. day2=1;
  86. }
  87. }else{
  88. if(day2>d[month]){
  89. month++;
  90. day2=1;
  91. }
  92. }
  93. }else{
  94. if(day2>d[month]){
  95. month++;
  96. day2=1;
  97. }
  98. }
  99. if(month>12){
  100. month=1;
  101. year++;
  102. }
  103. // alert(minu);
  104. sec = parseInt(sec);
  105. minu = parseInt(minu);
  106. hour = parseInt(hour);
  107. day2 = parseInt(day2);
  108. month = parseInt(month);
  109. year = parseInt(year);
  110. sec = sec < 10 ? '0' + sec : sec;
  111. minu = minu < 10 ? '0' + minu : minu;
  112. hour = hour < 10 ? '0' + hour : hour;
  113. time1 = hour + ':' + minu + ':' + sec;
  114. day2 = day2 < 10 ? '0' + day2 : day2;
  115. month = month < 10 ? '0' + month : month;
  116. year = year < 10 ? '0' + year : year;
  117. day1 = day2 + '-' + month + '-' + year;
  118. $("#day").text(day1);
  119. $("#time").text(time1);
  120. }
  121.  
  122. });
  123. function addGlobalStyle(css) {
  124. var head, style;
  125. head = document.getElementsByTagName('head')[0];
  126. if (!head) { return; }
  127. style = document.createElement('style');
  128. style.type = 'text/css';
  129. style.innerHTML = css;
  130. head.appendChild(style);
  131. }
  132. })(jQuery);
  133. //mostra nascondi data
  134. function myFunctiondate() {
  135. var box= document.getElementById('day');
  136. box.style.display = ((box.style.display!='none') ? 'none' : 'block');
  137. }
  138. GM_registerMenuCommand("mostra data/nascondi data",myFunctiondate);
  139. /////////////////////////////
  140. function myFunctiontime() {
  141. var box= document.getElementById('time');
  142. box.style.display = ((box.style.display!='none') ? 'none' : 'block');
  143. }
  144. GM_registerMenuCommand("mostra time/nascondi time",myFunctiontime);
  145. //////////////////
  146. function Functionnasconditutto() {
  147. var box= document.getElementById('testtimebox');
  148. box.style.display = ((box.style.display!='none') ? 'none' : 'block');
  149. }
  150. GM_registerMenuCommand("mostra box/nascondi box",Functionnasconditutto);
  151. ////////////////////////////////////