mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-18 16:11:38 +03:00
2681ad361b
Co-authored-by: Quentin Goinaud <armaldio@gmail.com> Co-authored-by: Lucas Fernandes Nogueira <lucasfernandesnog@gmail.com> Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
37 lines
927 B
JavaScript
37 lines
927 B
JavaScript
(function () {
|
|
function loadAsset(path, type) {
|
|
if (path) {
|
|
window.__TAURI__.loadAsset(path, type)
|
|
}
|
|
}
|
|
|
|
var observer = new MutationObserver(mutation => {
|
|
mutation.forEach(function (mutationRecord) {
|
|
var addedNodes = mutationRecord.addedNodes
|
|
addedNodes.forEach(function (node) {
|
|
if (node.nodeType === 1) {
|
|
if (node.tagName === 'SCRIPT') {
|
|
node.onload = node.onerror = null
|
|
loadAsset(node.src)
|
|
} else if (node.tagName === 'LINK') {
|
|
if (node.type === 'text/css' || (node.href && node.href.endsWith('.css'))) {
|
|
loadAsset(node.href, 'stylesheet')
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
})
|
|
|
|
<% if (target === 'body') { %>
|
|
var target = document.documentElement
|
|
<% } else { %>
|
|
var target = document.head
|
|
<% } %>
|
|
|
|
observer.observe(target, {
|
|
childList: true,
|
|
subtree: true
|
|
})
|
|
})()
|