Precise Time Converter on Google

See the precise time conversion results on google when searching for Hours to Days, Minutes to Hours, Minutes to Milliseconds or X Hours/Minutes From Now.

目前为 2021-12-22 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Precise Time Converter on Google
  3. // @namespace PreciseTimeConverterGoogle
  4. // @version 1.0.7
  5. // @description See the precise time conversion results on google when searching for Hours to Days, Minutes to Hours, Minutes to Milliseconds or X Hours/Minutes From Now.
  6. // @author hacker09
  7. // @include *://www.google.*
  8. // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://www.google.com&size=64
  9. // @run-at document-end
  10. // @grant none
  11. // @noframes
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. if (document.querySelector("#ssSucf") !== null) //If the user searched for something that google returned the conversion boxes
  17. { //Starts the if condition
  18. if (document.querySelector("#ssSucf").value.match('Min') != null) //If the conversion box value is equal Minute
  19. { //Starts the if condition
  20. var Input = document.querySelector("#HG5Seb > input").defaultValue; //Get the Minute number value
  21. } //Finishes the if condition
  22.  
  23. if (document.querySelector("#ssSucf").value.match('Ho') != null) //If the conversion box value is equal Hour
  24. { //Starts the if condition
  25. Input = document.querySelector("input.vXQmIe.gsrt").defaultValue * 60; //Get the Hour number value
  26. } //Finishes the if condition
  27.  
  28. if ((document.querySelector("#ssSucf").value.match('Ho') != null && document.querySelector("#NotFQb > select").value.match(/Day|Dia/) != null) || (document.querySelector("#ssSucf").value.match('Min') != null && document.querySelector("#NotFQb > select").value.match('Ho') != null) || (document.querySelector("#ssSucf").value.match('Min') != null && document.querySelector("#NotFQb > select").value.match('Mil') != null)) //If the conversion box value is equal Hour, Minute or Day
  29. { //Starts the if condition
  30. var Value; //Create a new global variable
  31. var days = Math.floor(Input / 1440); //Sum the total precise amount of days
  32. var hours = Math.floor((Input % 1440) / 60); //Sum the total precise amount of hours
  33. var minutes = (Input % 1440) % 60; //Sum the total precise amount of minutes
  34.  
  35. (document.querySelector("#ssSucf").value.match('Min') != null && document.querySelector("#NotFQb > select").value.match('Mil') != null) ? Value = Input * 60000: Value = days + ' day(s) ' + hours + ' hr(s) ' + minutes + ' min(s)'; //If the conversion if from Minutes to Milliseconds do the first math, otherwise do the second matn
  36. document.querySelector("#NotFQb > input").style.width = '370px'; //Expand the converted results box
  37. document.querySelector("#NotFQb > input").defaultValue = Value; //Display the converted results
  38. } //Finishes the if condition
  39. } //Finishes the if condition
  40.  
  41. if (document.querySelector("input.gLFyf.gsfi").value.match(/hours? from now|hrs? from now|minutes? from now|mins? from now/i) !== null) //If the search box contains the text hours/mins from now
  42. { //Starts the if condition
  43.  
  44. //Start the function to correctly format the date and time from now
  45. function formatDateTime(date) { //Starts the function
  46. var year = date.getFullYear();
  47. var month = date.getMonth() + 1;
  48. var day = date.getDate();
  49. var hh = date.getHours();
  50. var m = date.getMinutes();
  51. var s = date.getSeconds();
  52. var dd = "AM";
  53. var h = hh;
  54.  
  55. if (h >= 12) {
  56. h = hh - 12;
  57. dd = "PM";
  58. }
  59. if (h == 0) {
  60. h = 12;
  61. }
  62.  
  63. month = month < 10 ? "0" + month : month;
  64. day = day < 10 ? "0" + day : day;
  65. m = m < 10 ? "0" + m : m;
  66. s = s < 10 ? "0" + s : s;
  67. h = h < 10 ? "0" + h : h;
  68.  
  69. var display = month + "/" + day + "/" + year + " " + h + ":" + m;
  70. display += ":" + s;
  71. display += " " + dd;
  72.  
  73. return display;
  74. } //Finishes the function
  75.  
  76. var DaysFromNow = 0; //The total precise amount of days
  77. var HoursFromNow = 0; //The total precise amount of hours
  78. var MinutesFromNow = 0; //The total precise amount of minutes
  79. var SecondsFromNow = 0; //Creates a new variable
  80. var date = new Date(); //Creates a new date
  81.  
  82. if (document.querySelector("input.gLFyf.gsfi").value.match(/hours? from now|hrs? from now/i) !== null) //If the search box contains the text hours from now
  83. { //Starts the if condition
  84. HoursFromNow = document.querySelector("input.gLFyf.gsfi").value.match(/\d+/)[0]; //Get the written number of hours from now that the user wrote
  85. } //Finishes the if condition
  86.  
  87. if (document.querySelector("input.gLFyf.gsfi").value.match(/minutes? from now|mins? from now/i) !== null) //If the search box contains the text mins from now
  88. { //Starts the if condition
  89. MinutesFromNow = document.querySelector("input.gLFyf.gsfi").value.match(/\d+/)[0]; //Get the written number of Minutes from now that the user wrote
  90. } //Finishes the if condition
  91.  
  92. if (document.querySelector("input.gLFyf.gsfi").value.match(/and \d+ minutes? from now|and \d+ mins? from now/i) !== null) //If the search box contains the text "and minutes/mins from now"
  93. { //Starts the if condition
  94. HoursFromNow = document.querySelector("input.gLFyf.gsfi").value.match(/\d+/)[0]; //Get the written number of hours from now that the user wrote
  95. MinutesFromNow = document.querySelector("input.gLFyf.gsfi").value.match(/(?:and (\d+))/)[1]; //Get the written number of Minutes from now that the user wrote
  96. } //Finishes the if condition
  97.  
  98. var secondsToAdd = DaysFromNow * 60 * 60 * 24 + HoursFromNow * 60 * 60 + MinutesFromNow * 60 + SecondsFromNow; //Convert the actual days,hours and minutes to seconds
  99. date.setSeconds(date.getSeconds() + secondsToAdd);
  100. document.querySelector("input.gLFyf.gsfi").value = document.querySelector("input.gLFyf.gsfi").value + ' = ' + formatDateTime(date); //Display a message showing the days, hours and mins from now
  101. } //Finishes the if condition
  102. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址