inject.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. icon: state.icon,
  11. }],
  12. func: (_args) => {
  13. document.querySelector('pre').style.visibility = 'hidden'
  14. args = _args
  15. },
  16. injectImmediately: true
  17. })
  18. chrome.scripting.insertCSS({
  19. target: {tabId: id},
  20. files: [
  21. '/content/index.css',
  22. ]
  23. })
  24. chrome.scripting.executeScript({
  25. target: {tabId: id},
  26. files: [
  27. '/vendor/mithril.min.js',
  28. state.content.syntax && '/vendor/prism.min.js',
  29. state.content.emoji && '/content/emoji.js',
  30. state.content.mermaid && ['/vendor/mermaid.min.js', '/content/mermaid.js'],
  31. state.content.mathjax && ['/content/mathjax.js', '/vendor/mathjax/tex-mml-chtml.js'],
  32. '/content/index.js',
  33. '/content/scroll.js',
  34. state.content.autoreload && '/content/autoreload.js',
  35. ].filter(Boolean).flat(),
  36. injectImmediately: true
  37. })
  38. }