options.js 4.2 KB

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