-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript
More file actions
48 lines (48 loc) · 1.7 KB
/
Copy pathScript
File metadata and controls
48 lines (48 loc) · 1.7 KB
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
39
40
41
42
43
44
45
46
47
48
// ==UserScript==
// @name Workona Space Window Isolator for Orion RC
// @namespace audit.workona.isolator
// @version 1.1.0
// @description Isoler chaque espace Workona dans une fenêtre dédiée et réduire les doublons par clics répétés
// @match https://workona.com/*
// @run-at document-start
// @inject-into page
// @grant GM_openInTab
// @noframes
// ==/UserScript//
(() => {
const cfg = { debug: false }
const isSpace = u => {
try {
const url = new URL(u, location.href)
return url.origin === location.origin && /^\/0\/[a-z0-9]+(?:\/|$)/.test(url.pathname)
} catch { return false }
}
const spaceId = u => {
const url = new URL(u, location.href)
const m = url.pathname.match(/^\/0\/([a-z0-9]+)/)
return m ? m[1] : null
}
let burstAt = 0
const openNamed = href => {
const id = spaceId(href)
if (!id) return
const name = `workona_ws_${id}`
let h = null
if (typeof GM_openInTab === `function`) h = GM_openInTab(href, { active: true, insert: true, setParent: true })
else h = window.open(href, name)
try { if (h && typeof h.focus === `function`) h.focus() } catch {}
if (cfg.debug) console.debug(`[isolator] ${href} -> ${name}`)
}
const onClick = e => {
if (burstAt && performance.now() - burstAt < 150) return
const a = e.target && typeof e.target.closest === `function` ? e.target.closest(`a[href]`) : null
if (!a) return
const href = a.getAttribute(`href`)
if (!href || !isSpace(href)) return
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return
e.preventDefault()
burstAt = performance.now()
openNamed(a.href)
}
document.addEventListener(`click`, onClick, true)
})()