hackmd-styles.ts 1017 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * GROWI styles loader for HackMD
  3. *
  4. * This file will be transpiled as a single JS
  5. * and should be load from HackMD head via 'routes/hackmd.js' route
  6. *
  7. * USAGE:
  8. * <script src="${hostname of GROWI}/_hackmd/load-styles"></script>
  9. *
  10. * @author Yuki Takei <yuki@weseek.co.jp>
  11. */
  12. /* eslint-disable no-console */
  13. const styles = '<%= styles %>'; // will be replaced by ejs
  14. /**
  15. * Insert link tag to load style file
  16. */
  17. function insertStyle() {
  18. const element = document.createElement('style');
  19. element.appendChild(document.createTextNode(unescape(styles)));
  20. document.getElementsByTagName('head')[0].appendChild(element);
  21. }
  22. /**
  23. * main
  24. */
  25. (function() {
  26. // check HackMD is in iframe
  27. if (window === window.parent) {
  28. console.log('[GROWI] Loading styles for HackMD is not processed because currently not in iframe');
  29. return;
  30. }
  31. console.log('[HackMD] Loading GROWI styles for HackMD...');
  32. insertStyle();
  33. console.log('[HackMD] GROWI styles for HackMD has successfully loaded.');
  34. }());