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 compressHTMLInput = document.getElementById("compressHTMLInput");
  31. const compressCSSInput = document.getElementById("compressCSSInput");
  32. const lazyLoadImagesInput = document.getElementById("lazyLoadImagesInput");
  33. const contextMenuEnabledInput = document.getElementById("contextMenuEnabledInput");
  34. const appendSaveDateInput = document.getElementById("appendSaveDateInput");
  35. const shadowEnabledInput = document.getElementById("shadowEnabledInput");
  36. const maxResourceSizeInput = document.getElementById("maxResourceSizeInput");
  37. const maxResourceSizeEnabledInput = document.getElementById("maxResourceSizeEnabledInput");
  38. let pendingSave = Promise.resolve();
  39. document.getElementById("resetButton").addEventListener("click", () => {
  40. bgPage.singlefile.config.reset()
  41. .then(refresh)
  42. .then(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. compressHTMLInput.checked = config.compressHTML;
  56. compressCSSInput.checked = config.compressCSS;
  57. lazyLoadImagesInput.checked = config.lazyLoadImages;
  58. contextMenuEnabledInput.checked = config.contextMenuEnabled;
  59. appendSaveDateInput.checked = config.appendSaveDate;
  60. shadowEnabledInput.checked = config.shadowEnabled;
  61. maxResourceSizeEnabledInput.checked = config.maxResourceSizeEnabled;
  62. maxResourceSizeInput.value = config.maxResourceSize;
  63. maxResourceSizeInput.disabled = !config.maxResourceSizeEnabled;
  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. compressHTML: compressHTMLInput.checked,
  75. compressCSS: compressCSSInput.checked,
  76. lazyLoadImages: lazyLoadImagesInput.checked,
  77. contextMenuEnabled: contextMenuEnabledInput.checked,
  78. appendSaveDate: appendSaveDateInput.checked,
  79. shadowEnabled: shadowEnabledInput.checked,
  80. maxResourceSizeEnabled: maxResourceSizeEnabledInput.checked,
  81. maxResourceSize: maxResourceSizeInput.value
  82. });
  83. await pendingSave;
  84. await bgPage.singlefile.ui.update();
  85. }
  86. });
  87. })();