Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mouseover event for page titles to show day name #82

Merged
merged 10 commits into from
Jun 17, 2020
3 changes: 2 additions & 1 deletion src/ts/contentScripts/entry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
import '../../core/features'
import '../../core/settings/dispatcher'
import '../../core/settings/shortcuts'
import '../../core/features/fuzzy_date'
import '../../core/features/fuzzy_date'
import '../../core/features/day-title'
39 changes: 39 additions & 0 deletions src/ts/core/features/day-title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {RoamDate} from '../roam/date'

const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']

function getDayFromDate(name: string) {
let re = /(.*) (\d+).{2}, (\d{4})/i
var matches = name.match(re)
if (matches && matches.length === 4) {
const d = RoamDate.parse(name)
return days[d.getDay()]
}
return null
}

function isPageViewTitle(element: HTMLElement) {
return (
element.parentNode &&
element.parentNode.parentNode &&
(element.parentNode.parentNode as Element).classList.contains('rm-ref-page-view-title')
)
}

document.querySelector('body')?.addEventListener('mouseover', ev => {
let day = null
const target = ev.target as HTMLElement

if (target === null) {
return
}

if (target.classList.contains('rm-page-ref') || isPageViewTitle(target)) {
day = getDayFromDate(target.innerText)
}

if (day == null) {
return
}
target.setAttribute('title', day)
})