Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TfTHacker/689270044dcf74257956a289131738c9 to your computer and use it in GitHub Desktop.
Save TfTHacker/689270044dcf74257956a289131738c9 to your computer and use it in GitHub Desktop.
// Roam42 is a prerequisite for this code, as it uses Roam42 libraries
// Install & Config:
// Add the code from this gist to a roam/js block in your roam graph and enable it
// If you prefer foreign day names, modify the english in the Javascript below
// CSS can be customized using #roam-title-day-banner CSS selector. Example:
// .roam-title-day-banner {
// color:silver;
// }
// to exclude sidebars, change 'var includeSidebars = true;' in the code o
// var includeSidebars = false;
;(()=>{
if( typeof window.roamhacker_daytitle != 'undefined') return;
window.roamhacker_daytitle = ()=> {
var includeSidebars = true;
var querystring = includeSidebars ? '.rm-title-display, .sidebar-content .level2 a' : '.rm-title-display';
const addDateToRoamTitleBanners = ()=> {
setTimeout(()=>{
document.querySelectorAll(querystring).forEach(title=>{
try {
if(title.nextElementSibling.classList.contains('roam-title-day-banner')) {
return;
}
} catch(e) {}
let pageDate = chrono.parseDate( title.innerText );
if( pageDate!=null ) {
var weekdays = new Array( "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday" );
var day = pageDate.getDay();
var div = document.createElement('DIV');
div.className = 'roam-title-day-banner';
div.innerText = weekdays[day];
div.style.fontSize="10pt";
div.style.top = -(Number(getComputedStyle(title).marginBottom.replace('px','')) + 6) + 'px';
div.style.position="relative";
div.style.fontStyle="oblique";
title.insertAdjacentElement('afterend', div);
}
});
},300)
};
setTimeout(()=>{
addDateToRoamTitleBanners();
const observerHeadings = new MutationObserver(addDateToRoamTitleBanners);
observerHeadings.observe(document.querySelector('.roam-body'), {
childList: true,
subtree: true
});
},10000);
}
window.roamhacker_daytitle();
})();
@louisw00
Copy link

Thank you! better add week number next to the day of the week,

@jirkapalacky
Copy link

Hi, how do I please install Roam42 into Roam research to make this extension work? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment