Created
December 12, 2019 23:38
-
-
Save mceachen/8179498f0943400a1eeff48abb74bc6d to your computer and use it in GitHub Desktop.
Add title with URL for browsers that hide the URL on hover
This file contains hidden or 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
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