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) {
let target: HTMLElement | null = e.target as HTMLElement
while (target) {
if (target.matches('a')) {
const t = target as HTMLAnchorElement
if ( if (
t.href !== '' && evt.defaultPrevented ||
['http://', 'https://', 'mailto:', 'tel:'].some((v) => evt.button !== 0 ||
t.href.startsWith(v) evt.metaKey ||
) && evt.altKey ||
t.target === '_blank' evt.ctrlKey ||
) { evt.shiftKey
void invoke('plugin:opener|open', { )
path: t.href return
})
e.preventDefault() const a = evt
} .composedPath()
break .find((el) => el instanceof Node && el.nodeName.toUpperCase() === 'A') as
} | HTMLAnchorElement
target = target.parentElement | undefined
}
// only open if supposed to be open in a new tab
if (!a || !a.href || a.target !== '_blank') return
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