options.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. const autoSaveDelayInput = document.getElementById("autoSaveDelayInput");
  44. let pendingSave = Promise.resolve();
  45. document.getElementById("resetButton").addEventListener("click", async () => {
  46. await bgPage.singlefile.config.reset();
  47. await refresh();
  48. await update();
  49. }, false);
  50. maxResourceSizeEnabledInput.addEventListener("click", () => maxResourceSizeInput.disabled = !maxResourceSizeEnabledInput.checked, false);
  51. document.body.onchange = update;
  52. refresh();
  53. async function refresh() {
  54. const config = await bgPage.singlefile.config.get();
  55. removeHiddenElementsInput.checked = config.removeHiddenElements;
  56. removeUnusedCSSRulesInput.checked = config.removeUnusedCSSRules;
  57. removeFramesInput.checked = config.removeFrames;
  58. removeImportsInput.checked = config.removeImports;
  59. removeScriptsInput.checked = config.removeScripts;
  60. saveRawPageInput.checked = config.saveRawPage;
  61. compressHTMLInput.checked = config.compressHTML;
  62. compressCSSInput.checked = config.compressCSS;
  63. lazyLoadImagesInput.checked = config.lazyLoadImages;
  64. contextMenuEnabledInput.checked = config.contextMenuEnabled;
  65. appendSaveDateInput.checked = config.appendSaveDate;
  66. shadowEnabledInput.checked = config.shadowEnabled;
  67. maxResourceSizeEnabledInput.checked = config.maxResourceSizeEnabled;
  68. maxResourceSizeInput.value = config.maxResourceSize;
  69. maxResourceSizeInput.disabled = !config.maxResourceSizeEnabled;
  70. confirmFilenameInput.checked = config.confirmFilename;
  71. removeAudioSrcInput.checked = config.removeAudioSrc;
  72. removeVideoSrcInput.checked = config.removeVideoSrc;
  73. displayInfobarInput.checked = config.displayInfobar;
  74. displayStatsInput.checked = config.displayStats;
  75. backgroundSaveInput.checked = config.backgroundSave;
  76. backgroundSaveInput.disabled = config.backgroundSaveDisabled;
  77. autoSaveDelayInput.value = config.autoSaveDelay;
  78. autoSaveDelayInput.disabled = config.autoSaveDelayDisabled;
  79. }
  80. async function update() {
  81. await pendingSave;
  82. pendingSave = bgPage.singlefile.config.set({
  83. removeHiddenElements: removeHiddenElementsInput.checked,
  84. removeUnusedCSSRules: removeUnusedCSSRulesInput.checked,
  85. removeFrames: removeFramesInput.checked,
  86. removeImports: removeImportsInput.checked,
  87. removeScripts: removeScriptsInput.checked,
  88. saveRawPage: saveRawPageInput.checked,
  89. compressHTML: compressHTMLInput.checked,
  90. compressCSS: compressCSSInput.checked,
  91. lazyLoadImages: lazyLoadImagesInput.checked,
  92. contextMenuEnabled: contextMenuEnabledInput.checked,
  93. appendSaveDate: appendSaveDateInput.checked,
  94. shadowEnabled: shadowEnabledInput.checked,
  95. maxResourceSizeEnabled: maxResourceSizeEnabledInput.checked,
  96. maxResourceSize: maxResourceSizeInput.value,
  97. confirmFilename: confirmFilenameInput.checked,
  98. removeAudioSrc: removeAudioSrcInput.checked,
  99. removeVideoSrc: removeVideoSrcInput.checked,
  100. displayInfobar: displayInfobarInput.checked,
  101. displayStats: displayStatsInput.checked,
  102. backgroundSave: backgroundSaveInput.checked,
  103. autoSaveDelay: autoSaveDelayInput.value
  104. });
  105. await pendingSave;
  106. await bgPage.singlefile.ui.update();
  107. }
  108. })();