ui-options.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. /*
  2. * Copyright 2010-2019 Gildas Lormeau
  3. * contact : gildas.lormeau <at> gmail.com
  4. *
  5. * This file is part of SingleFile.
  6. *
  7. * The code in this file is free software: you can redistribute it and/or
  8. * modify it under the terms of the GNU Affero General Public License
  9. * (GNU AGPL) as published by the Free Software Foundation, either version 3
  10. * of the License, or (at your option) any later version.
  11. *
  12. * The code in this file 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 GNU Affero
  15. * General Public License for more details.
  16. *
  17. * As additional permission under GNU AGPL version 3 section 7, you may
  18. * distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
  19. * AGPL normally required by section 4, provided you include this license
  20. * notice and a URL through which recipients can access the Corresponding
  21. * Source.
  22. */
  23. /* global browser, window, document, localStorage, FileReader, location, fetch, TextDecoder, DOMParser, HTMLElement */
  24. (async () => {
  25. const HELP_ICON_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABIUlEQVQ4y+2TsarCMBSGvxTBRdqiUZAWOrhJB9EXcPKFfCvfQYfulUKHDqXg4CYUJSioYO4mSDX3ttzt3n87fMlHTpIjlsulxpDZbEYYhgghSNOUOI5Ny2mZYBAELBYLer0eAJ7ncTweKYri4x7LJJRS0u12n7XrukgpjSc0CpVSXK/XZ32/31FKNW85z3PW6zXT6RSAJEnIsqy5UGvNZrNhu90CcDqd+C6tT6J+v//2Th+PB2VZ1hN2Oh3G4zGTyQTbtl/YbrdjtVpxu91+Ljyfz0RRhG3bzOfzF+Y4TvNXvlwuaK2pE4tfzr/wzwsty0IIURlL0998KxRCMBqN8H2/wlzXJQxD2u12vVkeDoeUZUkURRU+GAw4HA7s9/sK+wK6CWHasQ/S/wAAAABJRU5ErkJggg==";
  26. const HELP_PAGE_PATH = "/extension/ui/pages/help.html";
  27. const { DEFAULT_PROFILE_NAME, DISABLED_PROFILE_NAME, CURRENT_PROFILE_NAME } = await browser.runtime.sendMessage({ method: "config.getConstants" });
  28. const removeHiddenElementsLabel = document.getElementById("removeHiddenElementsLabel");
  29. const removeUnusedStylesLabel = document.getElementById("removeUnusedStylesLabel");
  30. const removeUnusedFontsLabel = document.getElementById("removeUnusedFontsLabel");
  31. const removeFramesLabel = document.getElementById("removeFramesLabel");
  32. const removeImportsLabel = document.getElementById("removeImportsLabel");
  33. const removeScriptsLabel = document.getElementById("removeScriptsLabel");
  34. const saveRawPageLabel = document.getElementById("saveRawPageLabel");
  35. const saveToClipboardLabel = document.getElementById("saveToClipboardLabel");
  36. const compressHTMLLabel = document.getElementById("compressHTMLLabel");
  37. const compressCSSLabel = document.getElementById("compressCSSLabel");
  38. const loadDeferredImagesLabel = document.getElementById("loadDeferredImagesLabel");
  39. const loadDeferredImagesMaxIdleTimeLabel = document.getElementById("loadDeferredImagesMaxIdleTimeLabel");
  40. const addMenuEntryLabel = document.getElementById("addMenuEntryLabel");
  41. const filenameTemplateLabel = document.getElementById("filenameTemplateLabel");
  42. const shadowEnabledLabel = document.getElementById("shadowEnabledLabel");
  43. const setMaxResourceSizeLabel = document.getElementById("setMaxResourceSizeLabel");
  44. const maxResourceSizeLabel = document.getElementById("maxResourceSizeLabel");
  45. const confirmFilenameLabel = document.getElementById("confirmFilenameLabel");
  46. const filenameConflictActionLabel = document.getElementById("filenameConflictActionLabel");
  47. const filenameConflictActionUniquifyLabel = document.getElementById("filenameConflictActionUniquifyLabel");
  48. const filenameConflictActionOverwriteLabel = document.getElementById("filenameConflictActionOverwriteLabel");
  49. const filenameConflictActionPromptLabel = document.getElementById("filenameConflictActionPromptLabel");
  50. const removeAudioLabel = document.getElementById("removeAudioLabel");
  51. const removeVideoLabel = document.getElementById("removeVideoLabel");
  52. const displayInfobarLabel = document.getElementById("displayInfobarLabel");
  53. const displayStatsLabel = document.getElementById("displayStatsLabel");
  54. const backgroundSaveLabel = document.getElementById("backgroundSaveLabel");
  55. const autoSaveDelayLabel = document.getElementById("autoSaveDelayLabel");
  56. const autoSaveLoadLabel = document.getElementById("autoSaveLoadLabel");
  57. const autoSaveUnloadLabel = document.getElementById("autoSaveUnloadLabel");
  58. const autoSaveLoadOrUnloadLabel = document.getElementById("autoSaveLoadOrUnloadLabel");
  59. const autoSaveRepeatLabel = document.getElementById("autoSaveRepeatLabel");
  60. const autoSaveRepeatDelayLabel = document.getElementById("autoSaveRepeatDelayLabel");
  61. const removeAlternativeFontsLabel = document.getElementById("removeAlternativeFontsLabel");
  62. const removeAlternativeImagesLabel = document.getElementById("removeAlternativeImagesLabel");
  63. const removeAlternativeMediasLabel = document.getElementById("removeAlternativeMediasLabel");
  64. const titleLabel = document.getElementById("titleLabel");
  65. const userInterfaceLabel = document.getElementById("userInterfaceLabel");
  66. const filenameLabel = document.getElementById("filenameLabel");
  67. const htmlContentLabel = document.getElementById("htmlContentLabel");
  68. const imagesLabel = document.getElementById("imagesLabel");
  69. const stylesheetsLabel = document.getElementById("stylesheetsLabel");
  70. const fontsLabel = document.getElementById("fontsLabel");
  71. const otherResourcesLabel = document.getElementById("otherResourcesLabel");
  72. const autoSaveLabel = document.getElementById("autoSaveLabel");
  73. const autoSettingsLabel = document.getElementById("autoSettingsLabel");
  74. const autoSettingsUrlLabel = document.getElementById("autoSettingsUrlLabel");
  75. const autoSettingsProfileLabel = document.getElementById("autoSettingsProfileLabel");
  76. const autoSettingsAutoSaveProfileLabel = document.getElementById("autoSettingsAutoSaveProfileLabel");
  77. const showAllProfilesLabel = document.getElementById("showAllProfilesLabel");
  78. const showAutoSaveProfileLabel = document.getElementById("showAutoSaveProfileLabel");
  79. const groupDuplicateImagesLabel = document.getElementById("groupDuplicateImagesLabel");
  80. const confirmInfobarLabel = document.getElementById("confirmInfobarLabel");
  81. const infobarTemplateLabel = document.getElementById("infobarTemplateLabel");
  82. const miscLabel = document.getElementById("miscLabel");
  83. const helpLabel = document.getElementById("helpLabel");
  84. const addProfileButton = document.getElementById("addProfileButton");
  85. const deleteProfileButton = document.getElementById("deleteProfileButton");
  86. const renameProfileButton = document.getElementById("renameProfileButton");
  87. const resetButton = document.getElementById("resetButton");
  88. const exportButton = document.getElementById("exportButton");
  89. const importButton = document.getElementById("importButton");
  90. const fileInput = document.getElementById("fileInput");
  91. const profileNamesInput = document.getElementById("profileNamesInput");
  92. const removeHiddenElementsInput = document.getElementById("removeHiddenElementsInput");
  93. const removeUnusedStylesInput = document.getElementById("removeUnusedStylesInput");
  94. const removeUnusedFontsInput = document.getElementById("removeUnusedFontsInput");
  95. const removeFramesInput = document.getElementById("removeFramesInput");
  96. const removeImportsInput = document.getElementById("removeImportsInput");
  97. const removeScriptsInput = document.getElementById("removeScriptsInput");
  98. const saveRawPageInput = document.getElementById("saveRawPageInput");
  99. const saveToClipboardInput = document.getElementById("saveToClipboardInput");
  100. const compressHTMLInput = document.getElementById("compressHTMLInput");
  101. const compressCSSInput = document.getElementById("compressCSSInput");
  102. const loadDeferredImagesInput = document.getElementById("loadDeferredImagesInput");
  103. const loadDeferredImagesMaxIdleTimeInput = document.getElementById("loadDeferredImagesMaxIdleTimeInput");
  104. const contextMenuEnabledInput = document.getElementById("contextMenuEnabledInput");
  105. const filenameTemplateInput = document.getElementById("filenameTemplateInput");
  106. const shadowEnabledInput = document.getElementById("shadowEnabledInput");
  107. const maxResourceSizeInput = document.getElementById("maxResourceSizeInput");
  108. const maxResourceSizeEnabledInput = document.getElementById("maxResourceSizeEnabledInput");
  109. const confirmFilenameInput = document.getElementById("confirmFilenameInput");
  110. const filenameConflictActionInput = document.getElementById("filenameConflictActionInput");
  111. const removeAudioSrcInput = document.getElementById("removeAudioSrcInput");
  112. const removeVideoSrcInput = document.getElementById("removeVideoSrcInput");
  113. const displayInfobarInput = document.getElementById("displayInfobarInput");
  114. const displayStatsInput = document.getElementById("displayStatsInput");
  115. const backgroundSaveInput = document.getElementById("backgroundSaveInput");
  116. const autoSaveDelayInput = document.getElementById("autoSaveDelayInput");
  117. const autoSaveLoadInput = document.getElementById("autoSaveLoadInput");
  118. const autoSaveUnloadInput = document.getElementById("autoSaveUnloadInput");
  119. const autoSaveLoadOrUnloadInput = document.getElementById("autoSaveLoadOrUnloadInput");
  120. const autoSaveRepeatInput = document.getElementById("autoSaveRepeatInput");
  121. const autoSaveRepeatDelayInput = document.getElementById("autoSaveRepeatDelayInput");
  122. const removeAlternativeFontsInput = document.getElementById("removeAlternativeFontsInput");
  123. const removeAlternativeImagesInput = document.getElementById("removeAlternativeImagesInput");
  124. const removeAlternativeMediasInput = document.getElementById("removeAlternativeMediasInput");
  125. const groupDuplicateImagesInput = document.getElementById("groupDuplicateImagesInput");
  126. const infobarTemplateInput = document.getElementById("infobarTemplateInput");
  127. const confirmInfobarInput = document.getElementById("confirmInfobarInput");
  128. const expandAllButton = document.getElementById("expandAllButton");
  129. const rulesDeleteAllButton = document.getElementById("rulesDeleteAllButton");
  130. const ruleUrlInput = document.getElementById("ruleUrlInput");
  131. const ruleProfileInput = document.getElementById("ruleProfileInput");
  132. const ruleAutoSaveProfileInput = document.getElementById("ruleAutoSaveProfileInput");
  133. const ruleEditProfileInput = document.getElementById("ruleEditProfileInput");
  134. const ruleEditAutoSaveProfileInput = document.getElementById("ruleEditAutoSaveProfileInput");
  135. const ruleAddButton = document.getElementById("ruleAddButton");
  136. const rulesElement = document.querySelector(".rules-table");
  137. const rulesContainerElement = document.querySelector(".rules-table-container");
  138. const ruleEditUrlInput = document.getElementById("ruleEditUrlInput");
  139. const ruleEditButton = document.getElementById("ruleEditButton");
  140. const createURLElement = rulesElement.querySelector(".rule-create");
  141. const showAllProfilesInput = document.getElementById("showAllProfilesInput");
  142. const showAutoSaveProfileInput = document.getElementById("showAutoSaveProfileInput");
  143. const resetAllButton = document.getElementById("resetAllButton");
  144. const resetCurrentButton = document.getElementById("resetCurrentButton");
  145. const resetCancelButton = document.getElementById("resetCancelButton");
  146. const confirmButton = document.getElementById("confirmButton");
  147. const cancelButton = document.getElementById("cancelButton");
  148. const promptInput = document.getElementById("promptInput");
  149. const promptCancelButton = document.getElementById("promptCancelButton");
  150. const promptConfirmButton = document.getElementById("promptConfirmButton");
  151. let sidePanelDisplay;
  152. browser.runtime.onMessage.addListener(message => {
  153. if (message.method == "options.refresh" || (message.method == "options.refreshPanel" && sidePanelDisplay)) {
  154. refresh(message.profileName);
  155. }
  156. });
  157. let pendingSave = Promise.resolve();
  158. let autoSaveProfileChanged;
  159. getHelpContents();
  160. ruleProfileInput.onchange = () => {
  161. if (!autoSaveProfileChanged && ruleProfileInput.value != CURRENT_PROFILE_NAME) {
  162. ruleAutoSaveProfileInput.value = ruleProfileInput.value;
  163. }
  164. };
  165. ruleAutoSaveProfileInput.onchange = () => {
  166. autoSaveProfileChanged = true;
  167. };
  168. rulesDeleteAllButton.addEventListener("click", async () => {
  169. if (await confirm(browser.i18n.getMessage("optionsDeleteDisplayedRulesConfirm"))) {
  170. await browser.runtime.sendMessage({ method: "config.deleteRules", profileName: !showAllProfilesInput.checked && profileNamesInput.value });
  171. await refresh();
  172. refreshExternalComponents();
  173. }
  174. }, false);
  175. createURLElement.onsubmit = async event => {
  176. event.preventDefault();
  177. try {
  178. await browser.runtime.sendMessage({ method: "config.addRule", url: ruleUrlInput.value, profileName: ruleProfileInput.value, autoSaveProfileName: ruleAutoSaveProfileInput.value });
  179. ruleUrlInput.value = "";
  180. ruleProfileInput.value = ruleAutoSaveProfileInput.value = DEFAULT_PROFILE_NAME;
  181. autoSaveProfileChanged = false;
  182. await refresh();
  183. refreshExternalComponents();
  184. ruleUrlInput.focus();
  185. } catch (error) {
  186. // ignored
  187. }
  188. };
  189. ruleUrlInput.onclick = ruleUrlInput.onkeyup = ruleUrlInput.onchange = async () => {
  190. ruleAddButton.disabled = !ruleUrlInput.value;
  191. const rules = await browser.runtime.sendMessage({ method: "config.getRules" });
  192. if (rules.find(rule => rule.url == ruleUrlInput.value)) {
  193. ruleAddButton.disabled = true;
  194. }
  195. };
  196. ruleEditUrlInput.onclick = ruleEditUrlInput.onkeyup = ruleEditUrlInput.onchange = async () => {
  197. ruleEditButton.disabled = !ruleEditUrlInput.value;
  198. const rules = await browser.runtime.sendMessage({ method: "config.getRules" });
  199. if (rules.find(rule => rule.url == ruleEditUrlInput.value)) {
  200. ruleEditButton.disabled = true;
  201. }
  202. };
  203. if (getLocalStorageItem("optionShowAutoSaveProfile")) {
  204. showAutoSaveProfileInput.checked = true;
  205. rulesContainerElement.classList.remove("compact");
  206. }
  207. showAutoSaveProfileInput.addEventListener("click", () => {
  208. if (showAutoSaveProfileInput.checked) {
  209. setLocalStorageItem("optionShowAutoSaveProfile", 1);
  210. rulesContainerElement.classList.remove("compact");
  211. } else {
  212. removeLocalStorageItem("optionShowAutoSaveProfile");
  213. rulesContainerElement.classList.add("compact");
  214. }
  215. }, false);
  216. if (getLocalStorageItem("optionShowAllProfiles")) {
  217. showAllProfilesInput.checked = true;
  218. }
  219. showAllProfilesInput.addEventListener("click", () => {
  220. if (showAllProfilesInput.checked) {
  221. setLocalStorageItem("optionShowAllProfiles", 1);
  222. } else {
  223. removeLocalStorageItem("optionShowAllProfiles");
  224. }
  225. }, false);
  226. addProfileButton.addEventListener("click", async () => {
  227. const profileName = await prompt(browser.i18n.getMessage("profileAddPrompt"));
  228. if (profileName) {
  229. try {
  230. await browser.runtime.sendMessage({ method: "config.createProfile", profileName });
  231. if (sidePanelDisplay) {
  232. await refresh();
  233. } else {
  234. await refresh(profileName);
  235. }
  236. refreshExternalComponents();
  237. } catch (error) {
  238. // ignored
  239. }
  240. }
  241. }, false);
  242. deleteProfileButton.addEventListener("click", async () => {
  243. if (await confirm(browser.i18n.getMessage("profileDeleteConfirm"))) {
  244. try {
  245. await browser.runtime.sendMessage({ method: "config.deleteProfile", profileName: profileNamesInput.value });
  246. profileNamesInput.value = null;
  247. await refresh();
  248. refreshExternalComponents();
  249. } catch (error) {
  250. // ignored
  251. }
  252. }
  253. }, false);
  254. renameProfileButton.addEventListener("click", async () => {
  255. const profileName = await prompt(browser.i18n.getMessage("profileRenamePrompt"), profileNamesInput.value);
  256. if (profileName) {
  257. try {
  258. await browser.runtime.sendMessage({ method: "config.renameProfile", profileName: profileNamesInput.value, newProfileName: profileName });
  259. await refresh(profileName);
  260. refreshExternalComponents();
  261. } catch (error) {
  262. // ignored
  263. }
  264. }
  265. }, false);
  266. resetButton.addEventListener("click", async () => {
  267. const choice = await reset();
  268. if (choice) {
  269. if (choice == "all") {
  270. await browser.runtime.sendMessage({ method: "config.resetProfiles" });
  271. await refresh(DEFAULT_PROFILE_NAME);
  272. refreshExternalComponents();
  273. }
  274. if (choice == "current") {
  275. await browser.runtime.sendMessage({ method: "config.resetProfile", profileName: profileNamesInput.value });
  276. await refresh();
  277. refreshExternalComponents();
  278. }
  279. await update();
  280. }
  281. }, false);
  282. exportButton.addEventListener("click", async () => {
  283. await browser.runtime.sendMessage({ method: "config.exportConfig" });
  284. }, false);
  285. importButton.addEventListener("click", () => {
  286. fileInput.onchange = async () => {
  287. if (fileInput.files.length) {
  288. const reader = new FileReader();
  289. reader.readAsText(fileInput.files[0]);
  290. const serializedConfig = await new Promise((resolve, reject) => {
  291. reader.addEventListener("load", () => resolve(reader.result), false);
  292. reader.addEventListener("error", reject, false);
  293. });
  294. const config = JSON.parse(serializedConfig);
  295. await browser.runtime.sendMessage({ method: "config.importConfig", config });
  296. await refresh(DEFAULT_PROFILE_NAME);
  297. fileInput.value = "";
  298. }
  299. };
  300. fileInput.click();
  301. }, false);
  302. autoSaveUnloadInput.addEventListener("click", async () => {
  303. if (!autoSaveLoadInput.checked && !autoSaveUnloadInput.checked) {
  304. autoSaveLoadOrUnloadInput.checked = true;
  305. }
  306. }, false);
  307. autoSaveLoadInput.addEventListener("click", async () => {
  308. if (!autoSaveLoadInput.checked && !autoSaveUnloadInput.checked) {
  309. autoSaveLoadOrUnloadInput.checked = true;
  310. }
  311. }, false);
  312. autoSaveLoadOrUnloadInput.addEventListener("click", async () => {
  313. if (autoSaveLoadOrUnloadInput.checked) {
  314. autoSaveUnloadInput.checked = autoSaveLoadInput.checked = false;
  315. } else {
  316. autoSaveUnloadInput.checked = false;
  317. autoSaveLoadInput.checked = true;
  318. }
  319. }, false);
  320. expandAllButton.addEventListener("click", () => {
  321. if (expandAllButton.className) {
  322. expandAllButton.className = "";
  323. } else {
  324. expandAllButton.className = "opened";
  325. }
  326. document.querySelectorAll("details").forEach(detailElement => detailElement.open = Boolean(expandAllButton.className));
  327. }, false);
  328. removeScriptsInput.addEventListener("click", () => {
  329. if (!removeScriptsInput.checked) {
  330. removeHiddenElementsInput.checked = false;
  331. removeUnusedStylesInput.checked = false;
  332. }
  333. }, false);
  334. document.body.onchange = async event => {
  335. let target = event.target;
  336. if (target != ruleUrlInput && target != ruleProfileInput && target != ruleAutoSaveProfileInput && target != ruleEditUrlInput && target != ruleEditProfileInput && target != ruleEditAutoSaveProfileInput && target != showAutoSaveProfileInput) {
  337. if (target != profileNamesInput && target != showAllProfilesInput) {
  338. await update();
  339. }
  340. if (target == profileNamesInput) {
  341. await refresh(profileNamesInput.value);
  342. if (sidePanelDisplay) {
  343. const tabsData = await browser.runtime.sendMessage({ method: "tabsData.get" });
  344. tabsData.profileName = profileNamesInput.value;
  345. await browser.runtime.sendMessage({ method: "tabsData.set", tabsData });
  346. await browser.runtime.sendMessage({ method: "ui.refreshMenu" });
  347. }
  348. } else {
  349. await refresh();
  350. }
  351. }
  352. };
  353. addProfileButton.title = browser.i18n.getMessage("profileAddButtonTooltip");
  354. deleteProfileButton.title = browser.i18n.getMessage("profileDeleteButtonTooltip");
  355. renameProfileButton.title = browser.i18n.getMessage("profileRenameButtonTooltip");
  356. removeHiddenElementsLabel.textContent = browser.i18n.getMessage("optionRemoveHiddenElements");
  357. removeUnusedStylesLabel.textContent = browser.i18n.getMessage("optionRemoveUnusedStyles");
  358. removeUnusedFontsLabel.textContent = browser.i18n.getMessage("optionRemoveUnusedFonts");
  359. removeFramesLabel.textContent = browser.i18n.getMessage("optionRemoveFrames");
  360. removeImportsLabel.textContent = browser.i18n.getMessage("optionRemoveImports");
  361. removeScriptsLabel.textContent = browser.i18n.getMessage("optionRemoveScripts");
  362. saveRawPageLabel.textContent = browser.i18n.getMessage("optionSaveRawPage");
  363. saveToClipboardLabel.textContent = browser.i18n.getMessage("optionSaveToClipboard");
  364. compressHTMLLabel.textContent = browser.i18n.getMessage("optionCompressHTML");
  365. compressCSSLabel.textContent = browser.i18n.getMessage("optionCompressCSS");
  366. loadDeferredImagesLabel.textContent = browser.i18n.getMessage("optionLoadDeferredImages");
  367. loadDeferredImagesMaxIdleTimeLabel.textContent = browser.i18n.getMessage("optionLoadDeferredImagesMaxIdleTime");
  368. addMenuEntryLabel.textContent = browser.i18n.getMessage("optionAddMenuEntry");
  369. filenameTemplateLabel.textContent = browser.i18n.getMessage("optionFilenameTemplate");
  370. shadowEnabledLabel.textContent = browser.i18n.getMessage("optionDisplayShadow");
  371. setMaxResourceSizeLabel.textContent = browser.i18n.getMessage("optionSetMaxResourceSize");
  372. maxResourceSizeLabel.textContent = browser.i18n.getMessage("optionMaxResourceSize");
  373. confirmFilenameLabel.textContent = browser.i18n.getMessage("optionConfirmFilename");
  374. filenameConflictActionLabel.textContent = browser.i18n.getMessage("optionFilenameConflictAction");
  375. filenameConflictActionUniquifyLabel.textContent = browser.i18n.getMessage("optionFilenameConflictActionUniquify");
  376. filenameConflictActionOverwriteLabel.textContent = browser.i18n.getMessage("optionFilenameConflictActionOverwrite");
  377. filenameConflictActionPromptLabel.textContent = browser.i18n.getMessage("optionFilenameConflictActionPrompt");
  378. removeAudioLabel.textContent = browser.i18n.getMessage("optionRemoveAudio");
  379. removeVideoLabel.textContent = browser.i18n.getMessage("optionRemoveVideo");
  380. displayInfobarLabel.textContent = browser.i18n.getMessage("optionDisplayInfobar");
  381. displayStatsLabel.textContent = browser.i18n.getMessage("optionDisplayStats");
  382. backgroundSaveLabel.textContent = browser.i18n.getMessage("optionBackgroundSave");
  383. autoSaveDelayLabel.textContent = browser.i18n.getMessage("optionAutoSaveDelay");
  384. autoSaveLoadLabel.textContent = browser.i18n.getMessage("optionAutoSaveLoad");
  385. autoSaveUnloadLabel.textContent = browser.i18n.getMessage("optionAutoSaveUnload");
  386. autoSaveLoadOrUnloadLabel.textContent = browser.i18n.getMessage("optionAutoSaveLoadOrUnload");
  387. autoSaveRepeatLabel.textContent = browser.i18n.getMessage("optionAutoSaveRepeat");
  388. autoSaveRepeatDelayLabel.textContent = browser.i18n.getMessage("optionAutoSaveRepeatDelay");
  389. removeAlternativeFontsLabel.textContent = browser.i18n.getMessage("optionRemoveAlternativeFonts");
  390. removeAlternativeImagesLabel.textContent = browser.i18n.getMessage("optionRemoveAlternativeImages");
  391. removeAlternativeMediasLabel.textContent = browser.i18n.getMessage("optionRemoveAlternativeMedias");
  392. groupDuplicateImagesLabel.textContent = browser.i18n.getMessage("optionGroupDuplicateImages");
  393. titleLabel.textContent = browser.i18n.getMessage("optionsTitle");
  394. userInterfaceLabel.textContent = browser.i18n.getMessage("optionsUserInterfaceSubTitle");
  395. filenameLabel.textContent = browser.i18n.getMessage("optionsFileNameSubTitle");
  396. htmlContentLabel.textContent = browser.i18n.getMessage("optionsHTMLContentSubTitle");
  397. imagesLabel.textContent = browser.i18n.getMessage("optionsImagesSubTitle");
  398. stylesheetsLabel.textContent = browser.i18n.getMessage("optionsStylesheetsSubTitle");
  399. fontsLabel.textContent = browser.i18n.getMessage("optionsFontsSubTitle");
  400. otherResourcesLabel.textContent = browser.i18n.getMessage("optionsOtherResourcesSubTitle");
  401. autoSaveLabel.textContent = browser.i18n.getMessage("optionsAutoSaveSubTitle");
  402. miscLabel.textContent = browser.i18n.getMessage("optionsMiscSubTitle");
  403. helpLabel.textContent = browser.i18n.getMessage("optionsHelpLink");
  404. infobarTemplateLabel.textContent = browser.i18n.getMessage("optionInfobarTemplate");
  405. confirmInfobarLabel.textContent = browser.i18n.getMessage("optionConfirmInfobar");
  406. resetButton.textContent = browser.i18n.getMessage("optionsResetButton");
  407. exportButton.textContent = browser.i18n.getMessage("optionsExportButton");
  408. importButton.textContent = browser.i18n.getMessage("optionsImportButton");
  409. resetButton.title = browser.i18n.getMessage("optionsResetTooltip");
  410. autoSettingsLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsSubTitle");
  411. autoSettingsUrlLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsUrl");
  412. autoSettingsProfileLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsProfile");
  413. autoSettingsAutoSaveProfileLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsAutoSaveProfile");
  414. ruleAddButton.title = browser.i18n.getMessage("optionsAddRuleTooltip");
  415. ruleEditButton.title = browser.i18n.getMessage("optionsValidateChangesTooltip");
  416. rulesDeleteAllButton.title = browser.i18n.getMessage("optionsDeleteRulesTooltip");
  417. showAllProfilesLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsShowAllProfiles");
  418. showAutoSaveProfileLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsShowAutoSaveProfile");
  419. ruleUrlInput.placeholder = ruleEditUrlInput.placeholder = browser.i18n.getMessage("optionsAutoSettingsUrlPlaceholder");
  420. resetAllButton.textContent = browser.i18n.getMessage("optionsResetAllButton");
  421. resetCurrentButton.textContent = browser.i18n.getMessage("optionsResetCurrentButton");
  422. resetCancelButton.textContent = promptCancelButton.textContent = cancelButton.textContent = browser.i18n.getMessage("optionsCancelButton");
  423. confirmButton.textContent = promptConfirmButton.textContent = browser.i18n.getMessage("optionsOKButton");
  424. document.getElementById("resetConfirmLabel").textContent = browser.i18n.getMessage("optionsResetConfirm");
  425. if (location.href.endsWith("#")) {
  426. document.querySelector(".new-window-link").remove();
  427. document.documentElement.classList.add("maximized");
  428. }
  429. if (location.href.endsWith("#side-panel")) {
  430. sidePanelDisplay = true;
  431. document.querySelector(".options-title").remove();
  432. document.documentElement.classList.add("side-panel");
  433. const tabsData = await browser.runtime.sendMessage({ method: "tabsData.get" });
  434. refresh(tabsData.profileName);
  435. } else {
  436. refresh();
  437. }
  438. async function refresh(profileName) {
  439. const [profiles, rules] = await Promise.all([browser.runtime.sendMessage({ method: "config.getProfiles" }), browser.runtime.sendMessage({ method: "config.getRules" })]);
  440. const selectedProfileName = profileName || profileNamesInput.value || DEFAULT_PROFILE_NAME;
  441. Array.from(profileNamesInput.childNodes).forEach(node => node.remove());
  442. profileNamesInput.options.length = 0;
  443. ruleProfileInput.options.length = 0;
  444. ruleAutoSaveProfileInput.options.length = 0;
  445. ruleEditProfileInput.options.length = 0;
  446. ruleEditAutoSaveProfileInput.options.length = 0;
  447. let optionElement = document.createElement("option");
  448. optionElement.value = DEFAULT_PROFILE_NAME;
  449. optionElement.textContent = browser.i18n.getMessage("profileDefaultSettings");
  450. [CURRENT_PROFILE_NAME].concat(...Object.keys(profiles)).forEach(profileName => {
  451. const optionElement = document.createElement("option");
  452. optionElement.value = optionElement.textContent = profileName;
  453. if (profileName == DEFAULT_PROFILE_NAME) {
  454. optionElement.textContent = browser.i18n.getMessage("profileDefaultSettings");
  455. }
  456. if (profileName != CURRENT_PROFILE_NAME) {
  457. profileNamesInput.appendChild(optionElement);
  458. }
  459. ruleProfileInput.appendChild(optionElement.cloneNode(true));
  460. ruleAutoSaveProfileInput.appendChild(optionElement.cloneNode(true));
  461. ruleEditProfileInput.appendChild(optionElement.cloneNode(true));
  462. ruleEditAutoSaveProfileInput.appendChild(optionElement.cloneNode(true));
  463. });
  464. profileNamesInput.disabled = profileNamesInput.options.length == 1;
  465. optionElement = document.createElement("option");
  466. optionElement.value = DISABLED_PROFILE_NAME;
  467. optionElement.textContent = browser.i18n.getMessage("profileDisabled");
  468. ruleAutoSaveProfileInput.appendChild(optionElement);
  469. ruleEditAutoSaveProfileInput.appendChild(optionElement.cloneNode(true));
  470. const rulesDataElement = rulesElement.querySelector(".rules-data");
  471. Array.from(rulesDataElement.childNodes).forEach(node => (!node.className || !node.className.includes("rule-edit")) && node.remove());
  472. const editURLElement = rulesElement.querySelector(".rule-edit");
  473. createURLElement.hidden = false;
  474. editURLElement.hidden = true;
  475. ruleProfileInput.value = ruleAutoSaveProfileInput.value = selectedProfileName;
  476. let rulesDisplayed;
  477. rules.forEach(rule => {
  478. if (showAllProfilesInput.checked || selectedProfileName == rule.profile || selectedProfileName == rule.autoSaveProfile) {
  479. rulesDisplayed = true;
  480. const ruleElement = rulesElement.querySelector(".rule-view").cloneNode(true);
  481. const ruleUrlElement = ruleElement.querySelector(".rule-url");
  482. const ruleProfileElement = ruleElement.querySelector(".rule-profile");
  483. const ruleAutoSaveProfileElement = ruleElement.querySelector(".rule-autosave-profile");
  484. ruleUrlElement.textContent = ruleUrlElement.title = rule.url;
  485. ruleProfileElement.textContent = ruleProfileElement.title = getProfileText(rule.profile);
  486. ruleAutoSaveProfileElement.textContent = ruleAutoSaveProfileElement.title = getProfileText(rule.autoSaveProfile);
  487. ruleElement.hidden = false;
  488. ruleElement.className = "tr data";
  489. rulesDataElement.appendChild(ruleElement);
  490. const ruleDeleteButton = ruleElement.querySelector(".rule-delete-button");
  491. const ruleUpdateButton = ruleElement.querySelector(".rule-update-button");
  492. ruleDeleteButton.title = browser.i18n.getMessage("optionsDeleteRuleTooltip");
  493. ruleDeleteButton.addEventListener("click", async () => {
  494. if (await confirm(browser.i18n.getMessage("optionsDeleteRuleConfirm"))) {
  495. await browser.runtime.sendMessage({ method: "config.deleteRule", url: rule.url });
  496. await refresh();
  497. refreshExternalComponents();
  498. }
  499. }, false);
  500. ruleUpdateButton.title = browser.i18n.getMessage("optionsUpdateRuleTooltip");
  501. ruleUpdateButton.addEventListener("click", async () => {
  502. if (editURLElement.hidden) {
  503. createURLElement.hidden = true;
  504. editURLElement.hidden = false;
  505. rulesDataElement.replaceChild(editURLElement, ruleElement);
  506. ruleEditUrlInput.value = rule.url;
  507. ruleEditProfileInput.value = rule.profile;
  508. ruleEditAutoSaveProfileInput.value = rule.autoSaveProfile;
  509. ruleEditUrlInput.focus();
  510. editURLElement.onsubmit = async event => {
  511. event.preventDefault();
  512. rulesElement.appendChild(editURLElement);
  513. await browser.runtime.sendMessage({ method: "config.updateRule", url: rule.url, newUrl: ruleEditUrlInput.value, profileName: ruleEditProfileInput.value, autoSaveProfileName: ruleEditAutoSaveProfileInput.value });
  514. await refresh();
  515. refreshExternalComponents();
  516. ruleUrlInput.focus();
  517. };
  518. }
  519. }, false);
  520. }
  521. });
  522. rulesDeleteAllButton.disabled = !rulesDisplayed;
  523. rulesElement.appendChild(createURLElement);
  524. profileNamesInput.value = selectedProfileName;
  525. renameProfileButton.disabled = deleteProfileButton.disabled = profileNamesInput.value == DEFAULT_PROFILE_NAME;
  526. const profileOptions = profiles[selectedProfileName];
  527. removeHiddenElementsInput.checked = profileOptions.removeHiddenElements;
  528. removeUnusedStylesInput.checked = profileOptions.removeUnusedStyles;
  529. removeUnusedFontsInput.checked = profileOptions.removeUnusedFonts;
  530. removeFramesInput.checked = profileOptions.removeFrames;
  531. removeImportsInput.checked = profileOptions.removeImports;
  532. removeScriptsInput.checked = profileOptions.removeScripts;
  533. saveRawPageInput.checked = profileOptions.saveRawPage;
  534. saveToClipboardInput.checked = profileOptions.saveToClipboard;
  535. compressHTMLInput.checked = profileOptions.compressHTML;
  536. compressCSSInput.checked = profileOptions.compressCSS;
  537. loadDeferredImagesInput.checked = profileOptions.loadDeferredImages;
  538. loadDeferredImagesMaxIdleTimeInput.value = profileOptions.loadDeferredImagesMaxIdleTime;
  539. loadDeferredImagesMaxIdleTimeInput.disabled = !profileOptions.loadDeferredImages || profileOptions.saveRawPage;
  540. contextMenuEnabledInput.checked = profileOptions.contextMenuEnabled;
  541. filenameTemplateInput.value = profileOptions.filenameTemplate;
  542. filenameTemplateInput.disabled = profileOptions.saveToClipboard;
  543. shadowEnabledInput.checked = profileOptions.shadowEnabled;
  544. maxResourceSizeEnabledInput.checked = profileOptions.maxResourceSizeEnabled;
  545. maxResourceSizeInput.value = profileOptions.maxResourceSize;
  546. maxResourceSizeInput.disabled = !profileOptions.maxResourceSizeEnabled;
  547. confirmFilenameInput.checked = profileOptions.confirmFilename;
  548. confirmFilenameInput.disabled = profileOptions.saveToClipboard;
  549. filenameConflictActionInput.value = profileOptions.filenameConflictAction;
  550. filenameConflictActionInput.disabled = profileOptions.saveToClipboard;
  551. removeAudioSrcInput.checked = profileOptions.removeAudioSrc;
  552. removeVideoSrcInput.checked = profileOptions.removeVideoSrc;
  553. displayInfobarInput.checked = profileOptions.displayInfobar;
  554. displayStatsInput.checked = profileOptions.displayStats;
  555. backgroundSaveInput.checked = profileOptions.backgroundSave;
  556. autoSaveDelayInput.value = profileOptions.autoSaveDelay;
  557. autoSaveDelayInput.disabled = !profileOptions.autoSaveLoadOrUnload && !profileOptions.autoSaveLoad;
  558. autoSaveLoadInput.checked = !profileOptions.autoSaveLoadOrUnload && profileOptions.autoSaveLoad;
  559. autoSaveLoadOrUnloadInput.checked = profileOptions.autoSaveLoadOrUnload;
  560. autoSaveUnloadInput.checked = !profileOptions.autoSaveLoadOrUnload && profileOptions.autoSaveUnload;
  561. autoSaveLoadInput.disabled = profileOptions.autoSaveLoadOrUnload;
  562. autoSaveUnloadInput.disabled = profileOptions.autoSaveLoadOrUnload;
  563. autoSaveRepeatInput.checked = profileOptions.autoSaveRepeat;
  564. autoSaveRepeatInput.disabled = !profileOptions.autoSaveLoadOrUnload && !profileOptions.autoSaveLoad;
  565. autoSaveRepeatDelayInput.value = profileOptions.autoSaveRepeatDelay;
  566. autoSaveRepeatDelayInput.disabled = !profileOptions.autoSaveRepeat;
  567. removeAlternativeFontsInput.checked = profileOptions.removeAlternativeFonts;
  568. removeAlternativeImagesInput.checked = profileOptions.removeAlternativeImages;
  569. groupDuplicateImagesInput.checked = profileOptions.groupDuplicateImages;
  570. removeAlternativeMediasInput.checked = profileOptions.removeAlternativeMedias;
  571. infobarTemplateInput.value = profileOptions.infobarTemplate;
  572. confirmInfobarInput.checked = profileOptions.confirmInfobarContent;
  573. removeFramesInput.disabled = saveRawPageInput.checked;
  574. removeFramesInput.checked = removeFramesInput.checked || saveRawPageInput.checked;
  575. loadDeferredImagesInput.disabled = saveRawPageInput.checked;
  576. if (saveRawPageInput.checked) {
  577. loadDeferredImagesInput.checked = false;
  578. }
  579. }
  580. function getProfileText(profileName) {
  581. return profileName == DEFAULT_PROFILE_NAME ? browser.i18n.getMessage("profileDefaultSettings") : profileName == DISABLED_PROFILE_NAME ? browser.i18n.getMessage("profileDisabled") : profileName;
  582. }
  583. async function update() {
  584. await pendingSave;
  585. pendingSave = browser.runtime.sendMessage({
  586. method: "config.updateProfile",
  587. profileName: profileNamesInput.value,
  588. profile: {
  589. removeHiddenElements: removeHiddenElementsInput.checked,
  590. removeUnusedStyles: removeUnusedStylesInput.checked,
  591. removeUnusedFonts: removeUnusedFontsInput.checked,
  592. removeFrames: removeFramesInput.checked,
  593. removeImports: removeImportsInput.checked,
  594. removeScripts: removeScriptsInput.checked,
  595. saveRawPage: saveRawPageInput.checked,
  596. saveToClipboard: saveToClipboardInput.checked,
  597. compressHTML: compressHTMLInput.checked,
  598. compressCSS: compressCSSInput.checked,
  599. loadDeferredImages: loadDeferredImagesInput.checked,
  600. loadDeferredImagesMaxIdleTime: Math.max(loadDeferredImagesMaxIdleTimeInput.value, 0),
  601. contextMenuEnabled: contextMenuEnabledInput.checked,
  602. filenameTemplate: filenameTemplateInput.value,
  603. shadowEnabled: shadowEnabledInput.checked,
  604. maxResourceSizeEnabled: maxResourceSizeEnabledInput.checked,
  605. maxResourceSize: Math.max(maxResourceSizeInput.value, 0),
  606. confirmFilename: confirmFilenameInput.checked,
  607. filenameConflictAction: filenameConflictActionInput.value,
  608. removeAudioSrc: removeAudioSrcInput.checked,
  609. removeVideoSrc: removeVideoSrcInput.checked,
  610. displayInfobar: displayInfobarInput.checked,
  611. displayStats: displayStatsInput.checked,
  612. backgroundSave: backgroundSaveInput.checked,
  613. autoSaveDelay: Math.max(autoSaveDelayInput.value, 0),
  614. autoSaveLoad: autoSaveLoadInput.checked,
  615. autoSaveUnload: autoSaveUnloadInput.checked,
  616. autoSaveLoadOrUnload: autoSaveLoadOrUnloadInput.checked,
  617. autoSaveRepeat: autoSaveRepeatInput.checked,
  618. autoSaveRepeatDelay: Math.max(autoSaveRepeatDelayInput.value, 1),
  619. removeAlternativeFonts: removeAlternativeFontsInput.checked,
  620. removeAlternativeImages: removeAlternativeImagesInput.checked,
  621. removeAlternativeMedias: removeAlternativeMediasInput.checked,
  622. groupDuplicateImages: groupDuplicateImagesInput.checked,
  623. infobarTemplate: infobarTemplateInput.value,
  624. confirmInfobarContent: confirmInfobarInput.checked
  625. }
  626. });
  627. await pendingSave;
  628. }
  629. async function refreshExternalComponents() {
  630. await browser.runtime.sendMessage({ method: "ui.refreshMenu" });
  631. if (sidePanelDisplay) {
  632. await browser.runtime.sendMessage({ method: "options.refresh", profileName: profileNamesInput.value });
  633. } else {
  634. await browser.runtime.sendMessage({ method: "options.refreshPanel", profileName: profileNamesInput.value });
  635. }
  636. }
  637. async function confirm(message) {
  638. document.getElementById("confirmLabel").textContent = message;
  639. document.getElementById("formConfirmContainer").hidden = false;
  640. confirmButton.focus();
  641. document.body.style.setProperty("overflow-y", "hidden");
  642. return new Promise(resolve => {
  643. confirmButton.onclick = event => hideAndResolve(event, true);
  644. cancelButton.onclick = event => hideAndResolve(event);
  645. window.onkeyup = event => {
  646. if (event.key == "Escape") {
  647. hideAndResolve(event);
  648. }
  649. };
  650. function hideAndResolve(event, value) {
  651. event.preventDefault();
  652. document.getElementById("formConfirmContainer").hidden = true;
  653. document.body.style.setProperty("overflow-y", "");
  654. resolve(value);
  655. }
  656. });
  657. }
  658. async function reset() {
  659. document.getElementById("formResetContainer").hidden = false;
  660. resetCancelButton.focus();
  661. document.body.style.setProperty("overflow-y", "hidden");
  662. return new Promise(resolve => {
  663. resetAllButton.onclick = event => hideAndResolve(event, "all");
  664. resetCurrentButton.onclick = event => hideAndResolve(event, "current");
  665. resetCancelButton.onclick = event => hideAndResolve(event);
  666. window.onkeyup = event => {
  667. if (event.key == "Escape") {
  668. hideAndResolve(event);
  669. }
  670. };
  671. function hideAndResolve(event, value) {
  672. event.preventDefault();
  673. document.getElementById("formResetContainer").hidden = true;
  674. document.body.style.setProperty("overflow-y", "");
  675. resolve(value);
  676. }
  677. });
  678. }
  679. async function prompt(message, defaultValue = "") {
  680. document.getElementById("promptLabel").textContent = message;
  681. document.getElementById("formPromptContainer").hidden = false;
  682. promptInput.value = defaultValue;
  683. promptInput.focus();
  684. document.body.style.setProperty("overflow-y", "hidden");
  685. return new Promise(resolve => {
  686. promptConfirmButton.onclick = event => hideAndResolve(event, promptInput.value);
  687. promptCancelButton.onclick = event => hideAndResolve(event);
  688. window.onkeyup = event => {
  689. if (event.key == "Escape") {
  690. hideAndResolve(event);
  691. }
  692. };
  693. function hideAndResolve(event, value) {
  694. event.preventDefault();
  695. document.getElementById("formPromptContainer").hidden = true;
  696. document.body.style.setProperty("overflow-y", "");
  697. resolve(value);
  698. }
  699. });
  700. }
  701. async function getHelpContents() {
  702. const helpPage = await fetch(browser.runtime.getURL(HELP_PAGE_PATH));
  703. const content = new TextDecoder().decode(await helpPage.arrayBuffer());
  704. const doc = (new DOMParser()).parseFromString(content, "text/html");
  705. const items = doc.querySelectorAll("[data-options-label]");
  706. items.forEach(itemElement => {
  707. const optionLabel = document.getElementById(itemElement.dataset.optionsLabel);
  708. const helpIcon = document.createElement("img");
  709. helpIcon.className = "help-icon";
  710. helpIcon.src = HELP_ICON_URL;
  711. helpIcon.onclick = () => {
  712. helpContent.hidden = !helpContent.hidden;
  713. return false;
  714. };
  715. helpIcon.tabIndex = 0;
  716. helpIcon.onkeyup = event => {
  717. if (event.code == "Enter") {
  718. helpContent.hidden = !helpContent.hidden;
  719. return false;
  720. }
  721. };
  722. optionLabel.appendChild(helpIcon);
  723. const helpContent = document.createElement("div");
  724. helpContent.hidden = true;
  725. helpContent.className = "help-content";
  726. itemElement.childNodes.forEach(node => {
  727. if (node instanceof HTMLElement && node.className != "option") {
  728. helpContent.appendChild(document.importNode(node, true));
  729. }
  730. });
  731. helpContent.querySelectorAll("a[href]").forEach(linkElement => {
  732. const hrefValue = linkElement.getAttribute("href");
  733. if (hrefValue.startsWith("#")) {
  734. linkElement.href = browser.runtime.getURL(HELP_PAGE_PATH + linkElement.getAttribute("href"));
  735. linkElement.target = "_blank";
  736. }
  737. });
  738. optionLabel.parentElement.insertAdjacentElement("afterEnd", helpContent);
  739. });
  740. }
  741. function getLocalStorageItem(key) {
  742. try {
  743. return localStorage.getItem(key);
  744. } catch (error) {
  745. // ignored
  746. }
  747. }
  748. function setLocalStorageItem(key, value) {
  749. try {
  750. return localStorage.setItem(key, value);
  751. } catch (error) {
  752. // ignored
  753. }
  754. }
  755. function removeLocalStorageItem(key) {
  756. try {
  757. return localStorage.removeItem(key);
  758. } catch (error) {
  759. // ignored
  760. }
  761. }
  762. })();