Absolute Time on GreasyFork

Make Absolute Time on GreasyFork

Version au 07/07/2023. Voir la dernière version.

// ==UserScript==
// @name        Absolute Time on GreasyFork
// @namespace   UserScript
// @match       https://greatest.deepsurf.us/*
// @grant       none
// @version     1.0.0
// @license MIT
// @author      CY Fung
// @description Make Absolute Time on GreasyFork
// @unwrap
// ==/UserScript==



function pad(s, d){

  s= `000000${s}`
return s.substring(s.length-d)

}
let did = 0;
let cid = setInterval(()=>{



  for(const s of document.querySelectorAll("relative-time[datetime]:not(.absolute)")){
    s.classList.add("absolute")
    s.format = 'datetime';
    did ? (cancelAnimationFrame(did), (did=0)) :0;
    Promise.resolve(s).then(()=>{

    did ? (cancelAnimationFrame(did), (did=0)) :0;
    requestAnimationFrame(()=>{

    did ? (cancelAnimationFrame(did), (did=0)) :0;
      let d = s.getAttribute('datetime');
      let dt = d ? new Date(d) : null;

      if(dt && s.shadowRoot && s.shadowRoot.firstChild){
        s.shadowRoot.firstChild.textContent =`${dt.getFullYear()}.${pad(dt.getMonth()+1,2)}.${pad(dt.getDate(),2)} ${pad(dt.getHours(),2)}:${pad(dt.getMinutes(),2)}`

      }
    })

    })

  }


    did = did || (document.body ? requestAnimationFrame(()=>{
      cid && clearInterval(cid);
      cid = 0;
    }) : 0);




},1)