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 document */
  21. (() => {
  22. const browser = this.browser || this.chrome;
  23. browser.runtime.getBackgroundPage(bgPage => {
  24. const removeHiddenInput = document.getElementById("removeHiddenInput");
  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. document.getElementById("resetButton").addEventListener("click", () => {
  39. bgPage.singlefile.config.reset()
  40. .then(refresh)
  41. .then(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. removeHiddenInput.checked = config.removeHidden;
  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. compressHTMLInput.checked = config.compressHTML;
  55. compressCSSInput.checked = config.compressCSS;
  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. }
  64. async function update() {
  65. await bgPage.singlefile.config.set({
  66. removeHidden: removeHiddenInput.checked,
  67. removeUnusedCSSRules: removeUnusedCSSRulesInput.checked,
  68. removeFrames: removeFramesInput.checked,
  69. removeImports: removeImportsInput.checked,
  70. removeScripts: removeScriptsInput.checked,
  71. saveRawPage: saveRawPageInput.checked,
  72. compressHTML: compressHTMLInput.checked,
  73. compressCSS: compressCSSInput.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. });
  81. await bgPage.singlefile.ui.update();
  82. }
  83. });
  84. })();