Skip to content

Instantly share code, notes, and snippets.

@bduggan
Created February 25, 2021 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bduggan/0f7c75aa52a06818057e49efb4cf2b78 to your computer and use it in GitHub Desktop.
Save bduggan/0f7c75aa52a06818057e49efb4cf2b78 to your computer and use it in GitHub Desktop.
let as = document.getElementsByTagName('a')
let now = Date.now();
for (let item of as) {
let href = item.getAttribute('href');
let last = localStorage.getItem(href);
let days_ago = (now - last)/1000/60/60/24;
let h = 190;
// if (days_ago > 20) { h = 90; }
let s = days_ago > 1 ? 20 : 20 + 60 * (1 - days_ago);
let l = days_ago > 1 ? 20 : 20 + 60 * (1 - days_ago);
item.style.backgroundColor = `hsl(${h},${s}%,${l}%)`
if (days_ago < 1) {
item.style.color = `black`
}
item.addEventListener("click", function() {
localStorage.setItem(href,Date.now());
} );
console.log(` added ${href} (${days_ago})`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment