options.js 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 compressInput = document.getElementById("compressInput");
  30. const lazyLoadImagesInput = document.getElementById("lazyLoadImagesInput");
  31. const contextMenuEnabledInput = document.getElementById("contextMenuEnabledInput");
  32. const appendSaveDateInput = document.getElementById("appendSaveDateInput");
  33. const shadowEnabledInput = document.getElementById("shadowEnabledInput");
  34. const maxResourceSizeInput = document.getElementById("maxResourceSizeInput");
  35. const maxResourceSizeEnabledInput = document.getElementById("maxResourceSizeEnabledInput");
  36. const confirmFilenameInput = document.getElementById("confirmFilenameInput");
  37. let pendingSave = Promise.resolve();
  38. document.getElementById("resetButton").addEventListener("click", async () => {
  39. await bgPage.singlefile.config.reset();
  40. await refresh();
  41. await update();
  42. }, false);
  43. maxResourceSizeEnabledInput.addEventListener("click", () => maxResourceSizeInput.disabled = !maxResourceSizeEnabledInput.checked, false);
  44. document.getElementById("popupContent").onchange = update;
  45. refresh();
  46. async function refresh() {
  47. const config = await bgPage.singlefile.config.get();
  48. removeHiddenElementsInput.checked = config.removeHiddenElements;
  49. removeUnusedCSSRulesInput.checked = config.removeUnusedCSSRules;
  50. removeFramesInput.checked = config.removeFrames;
  51. removeImportsInput.checked = config.removeImports;
  52. removeScriptsInput.checked = config.removeScripts;
  53. saveRawPageInput.checked = config.saveRawPage;
  54. compressInput.checked = config.compress;
  55. lazyLoadImagesInput.checked = config.lazyLoadImages;
  56. contextMenuEnabledInput.checked = config.contextMenuEnabled;
  57. appendSaveDateInput.checked = config.appendSaveDate;
  58. shadowEnabledInput.checked = config.shadowEnabled;
  59. maxResourceSizeEnabledInput.checked = config.maxResourceSizeEnabled;
  60. maxResourceSizeInput.value = config.maxResourceSize;
  61. maxResourceSizeInput.disabled = !config.maxResourceSizeEnabled;
  62. confirmFilenameInput.checked = config.confirmFilename;
  63. }
  64. async function update() {
  65. await pendingSave;
  66. pendingSave = bgPage.singlefile.config.set({
  67. removeHiddenElements: removeHiddenElementsInput.checked,
  68. removeUnusedCSSRules: removeUnusedCSSRulesInput.checked,
  69. removeFrames: removeFramesInput.checked,
  70. removeImports: removeImportsInput.checked,
  71. removeScripts: removeScriptsInput.checked,
  72. saveRawPage: saveRawPageInput.checked,
  73. compress: compressInput.checked,
  74. lazyLoadImages: lazyLoadImagesInput.checked,
  75. contextMenuEnabled: contextMenuEnabledInput.checked,
  76. appendSaveDate: appendSaveDateInput.checked,
  77. shadowEnabled: shadowEnabledInput.checked,
  78. maxResourceSizeEnabled: maxResourceSizeEnabledInput.checked,
  79. maxResourceSize: maxResourceSizeInput.value,
  80. confirmFilename: confirmFilenameInput.checked
  81. });
  82. await pendingSave;
  83. await bgPage.singlefile.ui.update();
  84. }
  85. })();