inject.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. md.inject = ({storage: {state}}) => (id) => {
  2. chrome.scripting.executeScript({
  3. target: {tabId: id},
  4. args: [{
  5. theme: state.theme,
  6. raw: state.raw,
  7. themes: state.themes,
  8. content: state.content,
  9. compiler: state.compiler,
  10. custom: state.custom,
  11. icon: state.settings.icon,
  12. }],
  13. func: (_args) => {
  14. document.querySelector('pre').style.visibility = 'hidden'
  15. args = _args
  16. },
  17. injectImmediately: true
  18. })
  19. chrome.scripting.insertCSS({
  20. target: {tabId: id},
  21. files: [
  22. '/content/index.css',
  23. '/content/themes.css',
  24. ]
  25. })
  26. chrome.scripting.executeScript({
  27. target: {tabId: id},
  28. files: [
  29. '/vendor/mithril.min.js',
  30. state.content.syntax && ['/vendor/prism.js', '/content/prism-autoloader.js', '/content/prism.js'],
  31. state.content.emoji && '/content/emoji.js',
  32. state.content.mermaid && ['/vendor/mermaid.min.js', '/vendor/panzoom.min.js', '/content/mermaid.js'],
  33. state.content.mathjax && ['/content/mathjax.js', '/vendor/mathjax/tex-mml-chtml.js'],
  34. '/content/index.js',
  35. '/content/scroll.js',
  36. state.content.autoreload && '/content/autoreload.js',
  37. ].filter(Boolean).flat(),
  38. injectImmediately: true
  39. })
  40. }