Skip to content

Instantly share code, notes, and snippets.

@myfonj
Last active October 13, 2023 12:33
Show Gist options
  • Save myfonj/7c551e381e3a03362b7e4c92d4c8120d to your computer and use it in GitHub Desktop.
Save myfonj/7c551e381e3a03362b7e4c92d4c8120d to your computer and use it in GitHub Desktop.
(() => {
let nowTS = Date.now();
const archiveDate = document.location.href.match(/web.archive.org\/web\/([0-9]+)/);
if (archiveDate) {
const c = archiveDate[1].match(/(....)(..)(..)(..)(..)(..)/);
const d = new Date(`${c[1]}-${c[2]}-${c[3]}T${c[4]}:${c[6]}:${c[6]}Z`);
nowTS = d.getTime();
}
const ageSpans = document.querySelectorAll('.age[title]');
const data = Array.from(ageSpans).map(
el => {
const titleDate = el.title;
const text = el.textContent;
const date = new Date(titleDate + 'Z');
const ageTS = nowTS - date.getTime();
const hoursSinceTitleDate = msToHours(ageTS).toFixed(4);
const diffDiff = ageTS - textAgeToMS(text);
const id = el.closest('tr').previousElementSibling.id;
const hoursBetweenTitleDateAndText = msToHours(diffDiff).toFixed(4);
const postTitle = el.closest('tr').previousElementSibling.querySelector('.titleline a')?.textContent;
return {
titleDate,
hoursSinceTitleDate,
text,
hoursBetweenTitleDateAndText,
id,
postTitle,
el
}
}
)
function textAgeToMS(text) {
const rx = /^([0-9]+)\s+(\S+)/;
const match = text.match(rx);
return 1000 * Number(match[1]) * {
minute: 60, minutes: 60,
hour: 60 * 60, hours: 60 * 60,
day: 24 * 60 * 60, days: 24 * 60 * 60,
} [match[2]]
}
function msToHours(ms) {
return ms / 1000 / 60 / 60;
}
console.table(data.sort((a,b)=>b.hoursBetweenTitleDateAndText-a.hoursBetweenTitleDateAndText));
console.log(data.map(e=>Math.round(Number(e.hoursBetweenTitleDateAndText))));
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment