options.js 4.4 KB

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