refactor init script

pull/2019/head
amrbashir 9 months ago
parent bcc6c092f2
commit e0264cca3c
No known key found for this signature in database
GPG Key ID: BBD7A47A2003FF33

@ -5,36 +5,39 @@
import { invoke } from '@tauri-apps/api/core' import { invoke } from '@tauri-apps/api/core'
// open <a href="..."> links with the API // open <a href="..."> links with the API
function openLinks(): void { window.addEventListener('click', function (evt) {
document.querySelector('body')?.addEventListener('click', function (e) { if (
let target: HTMLElement | null = e.target as HTMLElement evt.defaultPrevented ||
while (target) { evt.button !== 0 ||
if (target.matches('a')) { evt.metaKey ||
const t = target as HTMLAnchorElement evt.altKey ||
if ( evt.ctrlKey ||
t.href !== '' && evt.shiftKey
['http://', 'https://', 'mailto:', 'tel:'].some((v) => )
t.href.startsWith(v) return
) &&
t.target === '_blank' const a = evt
) { .composedPath()
void invoke('plugin:opener|open', { .find((el) => el instanceof Node && el.nodeName.toUpperCase() === 'A') as
path: t.href | HTMLAnchorElement
}) | undefined
e.preventDefault()
} // only open if supposed to be open in a new tab
break if (!a || !a.href || a.target !== '_blank') return
}
target = target.parentElement const url = new URL(a.href)
}
if (
// only open if not same origin
url.origin === window.location.origin ||
// only open default protocols
['http:', 'https:', 'mailto:', 'tel:'].every((p) => url.protocol !== p)
)
return
evt.preventDefault()
void invoke('plugin:opener|open_url', {
path: url
}) })
} })
if (
document.readyState === 'complete' ||
document.readyState === 'interactive'
) {
openLinks()
} else {
window.addEventListener('DOMContentLoaded', openLinks, true)
}

@ -1 +1 @@
!function(){"use strict";async function e(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}function t(){document.querySelector("body")?.addEventListener("click",(function(t){let n=t.target;for(;n;){if(n.matches("a")){const r=n;""!==r.href&&["http://","https://","mailto:","tel:"].some((e=>r.href.startsWith(e)))&&"_blank"===r.target&&(e("plugin:opener|open",{path:r.href}),t.preventDefault());break}n=n.parentElement}}))}"function"==typeof SuppressedError&&SuppressedError,"complete"===document.readyState||"interactive"===document.readyState?t():window.addEventListener("DOMContentLoaded",t,!0)}(); !function(){"use strict";"function"==typeof SuppressedError&&SuppressedError,window.addEventListener("click",(function(e){if(e.defaultPrevented||0!==e.button||e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)return;const t=e.composedPath().find((e=>e instanceof Node&&"A"===e.nodeName.toUpperCase()));if(!t||!t.href||"_blank"!==t.target)return;const n=new URL(t.href);n.origin===window.location.origin||["http:","https:","mailto:","tel:"].every((e=>n.protocol!==e))||(e.preventDefault(),async function(e,t={},n){window.__TAURI_INTERNALS__.invoke(e,t,n)}("plugin:opener|open_url",{path:n}))}))}();

Loading…
Cancel
Save