Soundcloud Precise Date

A script to replace relative dates with exact dates (e.g track upload date, comment publication date).

  1. // ==UserScript==
  2. // @name Soundcloud Precise Date
  3. // @namespace Violentmonkey Scripts
  4. // @match https://soundcloud.com/*
  5. // @grant none
  6. // @version 2.0
  7. // @author bye-csavier (https://github.com/bye-csavier)
  8. // @run-at document-end
  9. // @description A script to replace relative dates with exact dates (e.g track upload date, comment publication date).
  10. // @license GNU GPLv3
  11. // ==/UserScript==
  12.  
  13. function setRealDate(relDate){
  14. if(relDate.dataset.xjsPreciseSoundCloudDate) return;
  15. let realDate = relDate.getAttribute("title")
  16. relDate.children[1].innerText = realDate; //may changed based on soundcloud comoponents strcture
  17. relDate.dataset.xjsPreciseSoundCloudDate = true;
  18. }
  19.  
  20. function handleAllRelativeTimes(){
  21. let trackDates = document.querySelectorAll("time.relativeTime");
  22. for (let i = 0, len = trackDates.length; i < len; ++i) {
  23. setRealDate(trackDates[i])
  24. }
  25. }
  26.  
  27. handleAllRelativeTimes(); //If the content is already loaded, somehow
  28.  
  29.  
  30. let idleDone = false;
  31. /*
  32. I guess soundcloud loads everything after the DOMContentLoaded event, trough scripts. Therefore I need to observe for every mutation on the body :(
  33. Still, the mutation is used to replace the new content the user loads so +1 for mutation observer.
  34.  
  35. It may be possible to stop it after a while it gets not called and trigger the mec
  36. */
  37. new MutationObserver((mutations, observer)=>{
  38. handleAllRelativeTimes();
  39. if(!idleDone){
  40. idleDone = true;
  41. observer.disconnect();
  42. observer.observe(document.getElementById("content"), {subtree:true, childList:true})
  43. }
  44. }).observe(document.body, {subtree:true, childList:true})