Skip to content

Instantly share code, notes, and snippets.

@kyoh86
Created June 28, 2017 02:03
Show Gist options
  • Save kyoh86/1f8e4a16a4ab0a1befc35cd7ec13082e to your computer and use it in GitHub Desktop.
Save kyoh86/1f8e4a16a4ab0a1befc35cd7ec13082e to your computer and use it in GitHub Desktop.
(()=>{
const escapeAttribute = "data-datetime-default-value";
const interval = 4000;
const format = item=>{
return item.getAttribute(escapeAttribute) +
"<br>(" + item.getAttribute("data") + ")";
};
const process = ()=>{
document.querySelectorAll("*[data^='20']").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