options.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2011 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. (function() {
  21. var removeScriptsInput, removeFramesInput, removeObjectsInput, removeHiddenInput, removeUnusedCSSRulesInput, processInBackgroundInput, getRawDocInput, sendToPageArchiverInput, displayBannerInput, displayInContextMenuInput, bgPage = chrome.extension
  22. .getBackgroundPage(), config;
  23. function refresh() {
  24. config = bgPage.singlefile.config.get();
  25. removeFramesInput.checked = config.removeFrames;
  26. removeScriptsInput.checked = config.removeScripts;
  27. removeObjectsInput.checked = config.removeObjects;
  28. removeHiddenInput.checked = config.removeHidden;
  29. removeUnusedCSSRulesInput.checked = config.removeUnusedCSSRules;
  30. displayInContextMenuInput.checked = config.displayInContextMenu;
  31. displayBannerInput.checked = config.displayBanner;
  32. processInBackgroundInput.checked = config.processInBackground;
  33. getRawDocInput.checked = config.getRawDoc;
  34. sendToPageArchiverInput.checked = config.sendToPageArchiver;
  35. if (displayBannerInput.checked)
  36. processInBackgroundInput.checked = processInBackgroundInput.disabled = true;
  37. }
  38. function update() {
  39. bgPage.singlefile.config.set({
  40. removeFrames : removeFramesInput.checked,
  41. removeScripts : removeScriptsInput.checked,
  42. removeObjects : removeObjectsInput.checked,
  43. removeHidden : removeHiddenInput.checked,
  44. removeUnusedCSSRules : removeUnusedCSSRulesInput.checked,
  45. displayInContextMenu : displayInContextMenuInput.checked,
  46. displayBanner : displayBannerInput.checked,
  47. displayProcessedPage : !displayBannerInput.checked,
  48. processInBackground : processInBackgroundInput.checked,
  49. getRawDoc : getRawDocInput.checked,
  50. sendToPageArchiver : sendToPageArchiverInput.checked
  51. });
  52. }
  53. function updateProcessInBackground() {
  54. processInBackgroundInput.checked = processInBackgroundInput.disabled = displayBannerInput.checked;
  55. update();
  56. }
  57. removeFramesInput = document.getElementById("removeFramesInput");
  58. removeScriptsInput = document.getElementById("removeScriptsInput");
  59. removeObjectsInput = document.getElementById("removeObjectsInput");
  60. removeHiddenInput = document.getElementById("removeHiddenInput");
  61. removeUnusedCSSRulesInput = document.getElementById("removeUnusedCSSRulesInput");
  62. displayInContextMenuInput = document.getElementById("displayInContextMenuInput");
  63. displayBannerInput = document.getElementById("displayBannerInput");
  64. processInBackgroundInput = document.getElementById("processInBackgroundInput");
  65. getRawDocInput = document.getElementById("getRawDocInput");
  66. sendToPageArchiverInput = document.getElementById("sendToPageArchiverInput");
  67. displayInContextMenuInput.addEventListener("click", bgPage.singlefile.refreshMenu);
  68. displayBannerInput.addEventListener("click", updateProcessInBackground, false);
  69. document.getElementById("resetButton").addEventListener("click", function() {
  70. bgPage.singlefile.config.reset();
  71. refresh();
  72. update();
  73. }, false);
  74. addEventListener("click", function(event) {
  75. var tooltip;
  76. if (event.target.className == "question-mark") {
  77. tooltip = event.target.parentElement.parentElement.children[2];
  78. tooltip.style.display = tooltip.style.display == "block" ? "none" : "block";
  79. event.preventDefault();
  80. }
  81. }, false);
  82. document.getElementById("popupContent").onchange = update;
  83. refresh();
  84. })();