Skip to content

Instantly share code, notes, and snippets.

@mceachen
Created December 12, 2019 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mceachen/8179498f0943400a1eeff48abb74bc6d to your computer and use it in GitHub Desktop.
Save mceachen/8179498f0943400a1eeff48abb74bc6d to your computer and use it in GitHub Desktop.
Add title with URL for browsers that hide the URL on hover
export function $$<T extends HTMLElement = HTMLElement>(selector: string) {
return document.querySelectorAll<T>(selector)
}
export function blank(o: any): o is undefined {
if (o == null) return true
const s = String(o)
return s.length === 0 || s.trim().length === 0
}
export type Maybe<T> = T | undefined
export type MaybeNull<T> = Maybe<T> | null | void
export function map<T, U>(obj: MaybeNull<T>, f: (t: T) => U): Maybe<U> {
return obj == null ? undefined : f(obj)
}
for (const ea of $$("a[target]")) {
map(ea.getAttribute("href"), href => {
if (blank(ea.getAttribute("title"))) {
ea.setAttribute("title", `Click to open ${href} in a new window`)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment