-
Notifications
You must be signed in to change notification settings - Fork 1
/
ctx.js
executable file
·38 lines (35 loc) · 1.07 KB
/
ctx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
if(!("hmm" in window)){
window.hmm = window.parent.hmm
}
document.addEventListener('contextmenu', ev => {
hmm.ctx(ev,eval("window.ctxs"))
ev.preventDefault()
})
document.addEventListener('click',ev=>{
if (ev.target != document.getElementById("ctx")) {
document.getElementById("ctx").style.display = "none"
}
})
document.addEventListener('touchstart', ev => {
setTimeout(()=>{
if (ev.touches.length == 2) {
hmm.ctx(ev.touches[0], eval("window.ctxs"))
}else
if (ev.touches[0].target != document.getElementById("ctx")) {
document.getElementById("ctx").style.display = "none"
}
},500)
})
hmm.ctx = function(event, ctxs) {
if(event.target.getAttribute('ctx')===null)return
const { pageX, pageY } = event
document.getElementById("ctx").style.display = "block"
document.getElementById("ctx").style.top = pageY + "px"
document.getElementById("ctx").style.left = pageX + "px"
document.getElementById("ctx").innerHTML = (ctxs || hmm.ctxs)[event.target.getAttribute('ctx')] //?? hmm.ctxs.default
}
{
let e=document.createElement("div")
e.id="ctx"
document.body.appendChild(e)
}