Merge pull request #3442 from DhruvaSambrani/master

Implement mouse_mode to revert no_mouse_mode, and pied_piper_mouse_mode
This commit is contained in:
Oliver Blanthorn 2021-03-10 08:47:46 +00:00 committed by GitHub
commit 03eb321bb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 22 deletions

View file

@ -9,34 +9,54 @@
*/
export function jack_in() {
// chinese characters - taken from the unicode charset
const chinese = "田由甲申甴电甶男甸甹町画甼甽甾甿畀畁畂畃畄畅畆畇畈畉畊畋界畍畎畏畐畑".split(
"",
)
const chinese = "田由甲申甴电甶男甸甹町画甼甽甾甿畀畁畂畃畄畅畆畇畈畉畊畋界畍畎畏畐畑".split("")
const colour = "#0F0" // green text
rain(chinese, colour)
rain(makeBlock(), chinese, colour)
}
export function music() {
// music characters - taken from the unicode charset
const music = "𝄞𝄟𝄰𝅘𝅥𝅮𝅘𝅥𝅯𝅘𝅥𝅰𝄽".split("")
const colour = "#ead115"
rain(makeBlock(), music, colour)
}
export function no_mouse() {
rain([" "], "#FFF", 0) // No characters, unused colour code, no darkening
makeBlock()
}
export const snow = () => rain(["❄"], "#FFF", 0.15)
function makeBlock() {
const overlaydiv = document.createElement("div")
overlaydiv.className = "_tridactyl_no_mouse_"
overlaydiv.style.position = "fixed"
overlaydiv.style.display = "block"
overlaydiv.style.width = String(window.innerWidth)
overlaydiv.style.height = String(window.innerHeight)
overlaydiv.style.top = "0"
overlaydiv.style.left = "0"
overlaydiv.style.right = "0"
overlaydiv.style.bottom = "0"
overlaydiv.style.zIndex = "1000"
overlaydiv.style.opacity = "0.5"
document.body.appendChild(overlaydiv)
return overlaydiv
}
export function rain(characters: string[], colour, darkening = 0.05) {
const d = document.createElement("div")
d.style.position = "fixed"
d.style.display = "block"
d.style.width = "100%"
d.style.height = "100%"
d.style.top = "0"
d.style.left = "0"
d.style.right = "0"
d.style.bottom = "0"
d.style.zIndex = "1000"
d.style.opacity = "0.5"
export function removeBlock() {
Array.from(document.getElementsByClassName("_tridactyl_no_mouse_")).map((el: Element & { intid?: number | null}) => {
if(typeof el.intid === "number") {
clearInterval(el.intid)
}
el.remove()
})
}
export const snow = () => rain(makeBlock(), ["❄"], "#FFF", 0.15)
function rain(overlaydiv, characters: string[], colour, darkening = 0.05) {
const c = document.createElement("canvas")
d.appendChild(c)
document.body.appendChild(d)
overlaydiv.appendChild(c)
const ctx = c.getContext("2d")
// making the canvas full screen
@ -79,6 +99,5 @@ export function rain(characters: string[], colour, darkening = 0.05) {
drops[i]++
}
}
setInterval(draw, 33)
overlaydiv.intid = setInterval(draw, 33)
}

View file

@ -1563,6 +1563,8 @@ export async function credits() {
/**
* Cover the current page in an overlay to prevent clicking on links with the mouse to force yourself to use hint mode. Get rid of it by reloading the page.
*
* To bring back mouse control, use [[mouse_mode]] or refresh the page.
*
* Suggested usage: `autocmd DocLoad .* no_mouse_mode`
*
* "There is no mouse".
@ -1592,6 +1594,24 @@ export function snow_mouse_mode() {
toys.snow()
}
/**
* Music variant of [[no_mouse_mode]].
*/
//#content
export function pied_piper_mouse_mode() {
toys.music()
}
/**
* Revert any variant of the [[no_mouse_mode]]
*
* Suggested usage: `bind <C-\> mouse_mode` with the autocmd mentioned in [[no_mouse_mode]].
*/
//#content
export function mouse_mode() {
toys.removeBlock()
}
/** @hidden */
// Find clickable next-page/previous-page links whose text matches the supplied pattern,
// and return the last such link.