options.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright 2018 Gildas Lormeau
  3. * contact : gildas.lormeau <at> gmail.com
  4. *
  5. * This file is part of SingleFile.
  6. *
  7. * SingleFile is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * SingleFile is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with SingleFile. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /* global browser, document */
  21. (async () => {
  22. const bgPage = await browser.runtime.getBackgroundPage();
  23. const removeHiddenElementsInput = document.getElementById("removeHiddenElementsInput");
  24. const removeUnusedCSSRulesInput = document.getElementById("removeUnusedCSSRulesInput");
  25. const removeFramesInput = document.getElementById("removeFramesInput");
  26. const removeImportsInput = document.getElementById("removeImportsInput");
  27. const removeScriptsInput = document.getElementById("removeScriptsInput");
  28. const saveRawPageInput = document.getElementById("saveRawPageInput");
  29. const compressHTMLInput = document.getElementById("compressHTMLInput");
  30. const compressCSSInput = document.getElementById("compressCSSInput");
  31. const lazyLoadImagesInput = document.getElementById("lazyLoadImagesInput");
  32. const contextMenuEnabledInput = document.getElementById("contextMenuEnabledInput");
  33. const appendSaveDateInput = document.getElementById("appendSaveDateInput");
  34. const shadowEnabledInput = document.getElementById("shadowEnabledInput");
  35. const maxResourceSizeInput = document.getElementById("maxResourceSizeInput");
  36. const maxResourceSizeEnabledInput = document.getElementById("maxResourceSizeEnabledInput");
  37. const confirmFilenameInput = document.getElementById("confirmFilenameInput");
  38. const removeAudioSrcInput = document.getElementById("removeAudioSrcInput");
  39. const removeVideoSrcInput = document.getElementById("removeVideoSrcInput");
  40. const displayInfobarInput = document.getElementById("displayInfobarInput");
  41. const displayStatsInput = document.getElementById("displayStatsInput");
  42. const backgroundSaveInput = document.getElementById("backgroundSaveInput");
  43. let pendingSave = Promise.resolve();
  44. document.getElementById("resetButton").addEventListener("click", async () => {
  45. await bgPage.singlefile.config.reset();
  46. await refresh();
  47. await update();
  48. }, false);
  49. maxResourceSizeEnabledInput.addEventListener("click", () => maxResourceSizeInput.disabled = !maxResourceSizeEnabledInput.checked, false);
  50. document.body.onchange = update;
  51. refresh();
  52. async function refresh() {
  53. const config = await bgPage.singlefile.config.get();
  54. removeHiddenElementsInput.checked = config.removeHiddenElements;
  55. removeUnusedCSSRulesInput.checked = config.removeUnusedCSSRules;
  56. removeFramesInput.checked = config.removeFrames;
  57. removeImportsInput.checked = config.removeImports;
  58. removeScriptsInput.checked = config.removeScripts;
  59. saveRawPageInput.checked = config.saveRawPage;
  60. compressHTMLInput.checked = config.compressHTML;
  61. compressCSSInput.checked = config.compressCSS;
  62. lazyLoadImagesInput.checked = config.lazyLoadImages;
  63. contextMenuEnabledInput.checked = config.contextMenuEnabled;
  64. appendSaveDateInput.checked = config.appendSaveDate;
  65. shadowEnabledInput.checked = config.shadowEnabled;
  66. maxResourceSizeEnabledInput.checked = config.maxResourceSizeEnabled;
  67. maxResourceSizeInput.value = config.maxResourceSize;
  68. maxResourceSizeInput.disabled = !config.maxResourceSizeEnabled;
  69. confirmFilenameInput.checked = config.confirmFilename;
  70. removeAudioSrcInput.checked = config.removeAudioSrc;
  71. removeVideoSrcInput.checked = config.removeVideoSrc;
  72. displayInfobarInput.checked = config.displayInfobar;
  73. displayStatsInput.checked = config.displayStats;
  74. backgroundSaveInput.checked = config.backgroundSave;
  75. }
  76. async function update() {
  77. await pendingSave;
  78. pendingSave = bgPage.singlefile.config.set({
  79. removeHiddenElements: removeHiddenElementsInput.checked,
  80. removeUnusedCSSRules: removeUnusedCSSRulesInput.checked,
  81. removeFrames: removeFramesInput.checked,
  82. removeImports: removeImportsInput.checked,
  83. removeScripts: removeScriptsInput.checked,
  84. saveRawPage: saveRawPageInput.checked,
  85. compressHTML: compressHTMLInput.checked,
  86. compressCSS: compressCSSInput.checked,
  87. lazyLoadImages: lazyLoadImagesInput.checked,
  88. contextMenuEnabled: contextMenuEnabledInput.checked,
  89. appendSaveDate: appendSaveDateInput.checked,
  90. shadowEnabled: shadowEnabledInput.checked,
  91. maxResourceSizeEnabled: maxResourceSizeEnabledInput.checked,
  92. maxResourceSize: maxResourceSizeInput.value,
  93. confirmFilename: confirmFilenameInput.checked,
  94. removeAudioSrc: removeAudioSrcInput.checked,
  95. removeVideoSrc: removeVideoSrcInput.checked,
  96. displayInfobar: displayInfobarInput.checked,
  97. displayStats: displayStatsInput.checked,
  98. backgroundSave: backgroundSaveInput.checked
  99. });
  100. await pendingSave;
  101. await bgPage.singlefile.ui.update();
  102. }
  103. })();