Skip to content

Instantly share code, notes, and snippets.

@kyoh86
Created June 28, 2017 02:02
Show Gist options
  • Save kyoh86/93222f3cfab84107dbf82588f905b07d to your computer and use it in GitHub Desktop.
Save kyoh86/93222f3cfab84107dbf82588f905b07d to your computer and use it in GitHub Desktop.
(() => {
const escapeAttribute = "data-datetime-default-value";
const phenotypeAttribute = "title";
const interval = 2000;
const format = item => {
return item.getAttribute(escapeAttribute) +
" (" + item.getAttribute(phenotypeAttribute) + ")"
};
const process = () => {
document.querySelectorAll(".js-timeago[" + phenotypeAttribute + "]").forEach(item => {
if (!item.hasAttribute(escapeAttribute) ||
(
item.getAttribute(escapeAttribute) != item.innerHTML &&
format(item) != item.innerHTML
)
) {
item.setAttribute(escapeAttribute, item.innerHTML);
}
item.innerHTML = format(item);
});
window.setTimeout(process, interval);
};
process();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment