Greasy Fork is available in English.
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.
当前为
// ==UserScript==
// @name Precise Time Converter on Google
// @namespace PreciseTimeConverterGoogle
// @version 1.0.1
// @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.
// @author hacker09
// @include *://www.google.*
// @icon https://api.faviconkit.com/www.google.com/57
// @grant none
// @run-at document-end
// @noframes
// ==/UserScript==
(function() {
'use strict';
if (document.querySelector("#ssSucf") !== null) //If the user searched for something that google returned the conversion boxes
{ //Starts the if condition
if (document.querySelector("#ssSucf").value === 'Minute') //If the convertion box value is equal Minute
{ //Starts the if condition
var Input = document.querySelector("#HG5Seb > input").defaultValue; //Get the Minute number value
} //Finishes the if condition
if (document.querySelector("#ssSucf").value === 'Hour') //If the convertion box value is equal Hour
{ //Starts the if condition
var Input = document.querySelector("input.vXQmIe.gsrt").defaultValue * 60; //Get the Hour number value
} //Finishes the if condition
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
{ //Starts the if condition
var Value; //Create a new global variable
var days = Math.floor(Input / 1440); //Sum the total precise amount of days
var hours = Math.floor((Input % 1440) / 60); //Sum the total precise amount of hours
var minutes = (Input % 1440) % 60; //Sum the total precise amount of minutes
(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
document.querySelector("#NotFQb > input").style.width = '370px'; //Expand the converted results box
document.querySelector("#NotFQb > input").defaultValue = Value; //Display the converted results
} //Finishes the if condition
} //Finishes the if condition
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
{ //Starts the if condition
//Start the function to correctly format the date and time from now https://pastebin.com/uMAEYbdf
function formatDateTime(date) { //Starts the function
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hh = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
var dd = "AM";
var h = hh;
if (h >= 12) {
h = hh - 12;
dd = "PM";
}
if (h == 0) {
h = 12;
}
month = month < 10 ? "0" + month : month;
day = day < 10 ? "0" + day : day;
m = m < 10 ? "0" + m : m;
s = s < 10 ? "0" + s : s;
h = h < 10 ? "0" + h : h;
var display = month + "/" + day + "/" + year + " " + h + ":" + m;
display += ":" + s;
display += " " + dd;
return display;
} //Finishes the function
var DaysFromNow = 0; //The total precise amount of days
var HoursFromNow = document.querySelector("input.gLFyf.gsfi").value.match(/\d+/)[0]; //Get the written number of hours from now that the user wrote
var MinutesFromNow = 0; //The total precise amount of minutes
var SecondsFromNow = 0; //Creates a new variable
var date = new Date(); //Creates a new date
var secondsToAdd = DaysFromNow * 60 * 60 * 24 + HoursFromNow * 60 * 60 + MinutesFromNow * 60 + SecondsFromNow; //Convert the actual days,hours and minutes to seconds
date.setSeconds(date.getSeconds() + secondsToAdd);
document.querySelector("input.gLFyf.gsfi").value = document.querySelector("input.gLFyf.gsfi").value + ' = ' + formatDateTime(date); //Display a message showing the days and hours from now
} //Finishes the if condition
})();