inject.js 883 B

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