-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from braydie/master
Added mouseover event for page titles to show day name
- Loading branch information
Showing
4 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {browser} from 'webextension-polyfill-ts' | ||
import {RoamDate} from '../roam/date' | ||
import {getDayName} from '../common/date' | ||
import {Feature, Settings} from '../settings' | ||
|
||
export const config: Feature = { | ||
id: 'day-title', | ||
name: 'Daily Notes Day Titles', | ||
} | ||
|
||
Settings.isActive(config.id).then(active => { | ||
if (active) { | ||
registerEventListener() | ||
} | ||
}) | ||
|
||
browser.runtime.onMessage.addListener(async message => { | ||
if (message?.featureId === config.id) { | ||
registerEventListener() | ||
} | ||
}) | ||
|
||
const getDayFromDate = (name: string) => { | ||
let re = /(.*) (\d+).{2}, (\d{4})/i | ||
const matches = name.match(re) | ||
if (matches && matches.length === 4) { | ||
const date = RoamDate.parse(name) | ||
return getDayName(date) | ||
} | ||
return null | ||
} | ||
|
||
const isElementPageViewTitle = (element: HTMLElement) => | ||
(element.parentNode?.parentNode as HTMLElement)?.classList?.contains('rm-ref-page-view-title') | ||
|
||
const registerEventListener = () => { | ||
document.querySelector('body')?.addEventListener('mouseover', ev => { | ||
const target = ev.target as HTMLElement | ||
if (target === null) { | ||
return | ||
} | ||
|
||
let day = null | ||
if ( | ||
target.classList.contains('rm-page-ref') || | ||
target.classList.contains(`rm-title-display`) || | ||
isElementPageViewTitle(target) | ||
) { | ||
day = getDayFromDate(target.innerText) | ||
} | ||
|
||
if (day === null) { | ||
return | ||
} | ||
target.setAttribute('title', day) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters