TPlacella

Accurate Dates

Jul 13th, 2025
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. // ==UserScript==
  2. // @name accurate dates
  3. // @namespace http://tampermonkey.net/
  4. // @version 2025-07-13
  5. // @description try to take over the world!
  6. // @author Protvod (thanks to last played script for reference)
  7. // @match https://www.freeriderhd.com/**
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=freeriderhd.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14. let url;
  15. setInterval(() => {
  16. if (
  17. window.location.href !== url &&
  18. window.location.href.startsWith('https://www.freeriderhd.com/t/')
  19. ) {
  20. main();
  21. }
  22. url = window.location.href;
  23. }, 500);
  24.  
  25. const getTrackDate = async (url, format = 'ddmmyyyy') => {
  26. const resp = await fetch(`${url}?ajax=true`);
  27. if (resp.ok) {
  28. const json = await resp.json();
  29. const trackDate = json['track']['date'];
  30. if (format === 'ddmmyyyy') {
  31. return trackDate.replace(/^([^/]*)\/([^/]*)\/([^/]*)$/, `$2/$1/20$3`);
  32. } else if (format === 'mmddyyyy') {
  33. return trackDate.replace(/^([^/]*)\/([^/]*)\/([^/]*)$/, `$1/$2/20$3`);
  34. }
  35. return trackDate;
  36. }
  37. };
  38.  
  39. const main = async () => {
  40. let timer = setInterval(async () => {
  41. const elem = document.querySelector('.published_date');
  42. if (elem) {
  43. clearInterval(timer);
  44. const trackDate = await getTrackDate(new URL(document.URL), 'ddmmyyyy'); // options are 'ddmmyyyy' (default), 'mmddyyyy' and 'mmddyy'
  45. if (trackDate) {
  46. elem.textContent = elem.textContent.replace(/^(Published).*ago (.*)$/, `$1 on ${trackDate} $2`);
  47. }
  48. }
  49. });
  50. };
  51. })();
Advertisement
Add Comment
Please, Sign In to add comment