Precise Time Converter on Google

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

当前为 2021-03-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Precise Time Converter on Google
  3. // @namespace PreciseTimeConverterGoogle
  4. // @version 0.9
  5. // @description See the precise time convertion results on google when searching for Hours to Days, Minutes to Hours Minutes to Milliseconds or X Hours From Now.
  6. // @author hacker09
  7. // @include *://www.google.*
  8. // @icon https://api.faviconkit.com/www.google.com/57
  9. // @grant none
  10. // @run-at document-end
  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 === 'Minute') //If the convertion 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 === 'Hour') //If the convertion box value is equal Hour
  24. { //Starts the if condition
  25. var 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 === 'Hour' && document.querySelector("#NotFQb > select").value === 'Day') || (document.querySelector("#ssSucf").value === 'Minute' && document.querySelector("#NotFQb > select").value === 'Hour') || (document.querySelector("#ssSucf").value === 'Minute' && document.querySelector("#NotFQb > select").value === 'Millisecond')) //If the convertion 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 === 'Minute' && document.querySelector("#NotFQb > select").value === 'Millisecond') ? 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/i) !== null) //If the search box contains the text hours from now
  42. { //Starts the if condition
  43.  
  44. //Start the function to correctly format the date and time from now https://pastebin.com/uMAEYbdf
  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 = document.querySelector("input.gLFyf.gsfi").value.match(/\d+/)[0]; //Get the written number of hours from now that the user wrote
  78. var MinutesFromNow = 0; //The total precise amount of minutes
  79. var SecondsFromNow = 0; //Creates a new variable
  80.  
  81. var date = new Date(); //Creates a new date
  82.  
  83. var secondsToAdd = DaysFromNow * 60 * 60 * 24 + HoursFromNow * 60 * 60 + MinutesFromNow * 60 + SecondsFromNow; //Convert the actual days,hours and minutes to seconds
  84. date.setSeconds(date.getSeconds() + secondsToAdd);
  85.  
  86.  
  87. document.querySelector("input.gLFyf.gsfi").value = document.querySelector("input.gLFyf.gsfi").value + ' = ' + formatDateTime(date); //Display a message showing the days and hours from now
  88. } //Finishes the if condition
  89. })();