mutation-observer.js 923 B

123456789101112131415161718192021222324252627282930313233343536
  1. (function () {
  2. function loadAsset(path, type) {
  3. if (path) {
  4. window.tauri.loadAsset(path, type)
  5. }
  6. }
  7. var observer = new MutationObserver(mutation => {
  8. mutation.forEach(function (mutationRecord) {
  9. var addedNodes = mutationRecord.addedNodes
  10. addedNodes.forEach(function (node) {
  11. if (node.nodeType === 1) {
  12. if (node.tagName === 'SCRIPT') {
  13. node.onload = node.onerror = null
  14. loadAsset(node.src)
  15. } else if (node.tagName === 'LINK') {
  16. if (node.type === 'text/css' || (node.href && node.href.endsWith('.css'))) {
  17. loadAsset(node.href, 'stylesheet')
  18. }
  19. }
  20. }
  21. })
  22. })
  23. })
  24. <% if (target === 'body') { %>
  25. var target = document.documentElement
  26. <% } else { %>
  27. var target = document.head
  28. <% } %>
  29. observer.observe(target, {
  30. childList: true,
  31. subtree: true
  32. })
  33. })()