您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

download.js 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * WHITEBOPHIR
  3. *********************************************************
  4. * @licstart The following is the entire license notice for the
  5. * JavaScript code in this page.
  6. *
  7. * Copyright (C) 2020 Ophir LOJKINE
  8. *
  9. *
  10. * The JavaScript code in this page is free software: you can
  11. * redistribute it and/or modify it under the terms of the GNU
  12. * General Public License (GNU GPL) as published by the Free Software
  13. * Foundation, either version 3 of the License, or (at your option)
  14. * any later version. The code is distributed WITHOUT ANY WARRANTY;
  15. * without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  17. *
  18. * As additional permission under GNU GPL version 3 section 7, you
  19. * may distribute non-source (e.g., minimized or compacted) forms of
  20. * that code without the copy of the GNU GPL normally required by
  21. * section 4, provided you include this license notice and a URL
  22. * through which recipients can access the Corresponding Source.
  23. *
  24. * @licend
  25. */
  26. (function download() { //Code isolation
  27. function downloadSVGFile(evt) {
  28. var canvasCopy = Tools.svg.cloneNode(true);
  29. var styleNode = document.createElement("style");
  30. // Copy the stylesheets from the whiteboard to the exported SVG
  31. styleNode.innerHTML = Array.from(document.styleSheets).map(
  32. function (stylesheet) {
  33. return Array.from(stylesheet.cssRules).map(
  34. function (rule) {
  35. return rule.cssText
  36. }
  37. )}
  38. ).join("\n")
  39. canvasCopy.appendChild(styleNode);
  40. downloadContent('data:image/svg+xml;charset=utf-8,' + encodeURIComponent(canvasCopy.outerHTML), "svg")
  41. }
  42. function downloadContent(href, type){
  43. var element = document.createElement('a');
  44. element.setAttribute('href', href);
  45. element.setAttribute('download', Tools.boardName + "." + type);
  46. element.style.display = 'none';
  47. document.body.appendChild(element);
  48. element.click();
  49. document.body.removeChild(element);
  50. }
  51. Tools.add({ //The new tool
  52. "name": "Download",
  53. "shortcut": "d",
  54. "listeners": {},
  55. "icon": "tools/download/download.svg",
  56. "oneTouch": true,
  57. "onstart": downloadSVGFile,
  58. "mouseCursor": "crosshair",
  59. });
  60. })(); //End of code isolation