瀏覽代碼

hide unsupported menu entry/options

Gildas 3 年之前
父節點
當前提交
266d19cff2
共有 3 個文件被更改,包括 79 次插入59 次删除
  1. 59 52
      src/ui/bg/ui-menus.js
  2. 15 2
      src/ui/bg/ui-options.js
  3. 5 5
      src/ui/pages/options.html

+ 59 - 52
src/ui/bg/ui-menus.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global browser, URL */
+/* global browser, URL, navigator */
 
 import * as config from "./../../core/bg/config.js";
 import { queryTabs } from "./../../core/bg/tabs-util.js";
@@ -32,6 +32,9 @@ import * as button from "./ui-button.js";
 
 const menus = browser.menus;
 const BROWSER_MENUS_API_SUPPORTED = menus && menus.onClicked && menus.create && menus.update && menus.removeAll;
+const AUTO_SAVE_SUPPORTED = !/Safari/.test(navigator.userAgent) || /Chrome/.test(navigator.userAgent);
+const SELECTABLE_TABS_SUPPORTED = !/Safari/.test(navigator.userAgent) || /Chrome/.test(navigator.userAgent);
+
 const MENU_ID_SAVE_PAGE = "save-page";
 const MENU_ID_EDIT_AND_SAVE_PAGE = "edit-and-save-page";
 const MENU_ID_SAVE_WITH_PROFILE = "save-with-profile";
@@ -204,11 +207,13 @@ async function createMenus(tab) {
 			parentId: MENU_ID_SAVE_TABS
 		});
 		if (options.contextMenuEnabled) {
-			menus.create({
-				id: MENU_ID_SAVE_SELECTED_TABS,
-				contexts: pageContextsEnabled,
-				title: MENU_SAVE_SELECTED_TABS_MESSAGE
-			});
+			if (SELECTABLE_TABS_SUPPORTED) {
+				menus.create({
+					id: MENU_ID_SAVE_SELECTED_TABS,
+					contexts: pageContextsEnabled,
+					title: MENU_SAVE_SELECTED_TABS_MESSAGE
+				});
+			}
 			menus.create({
 				id: MENU_ID_SAVE_UNPINNED_TABS,
 				contexts: pageContextsEnabled,
@@ -324,52 +329,54 @@ async function createMenus(tab) {
 				});
 			}
 		}
-		menus.create({
-			id: MENU_ID_AUTO_SAVE,
-			contexts: defaultContexts,
-			title: MENU_AUTOSAVE_MESSAGE
-		});
-		menus.create({
-			id: MENU_ID_AUTO_SAVE_DISABLED,
-			type: "radio",
-			title: MENU_AUTOSAVE_DISABLED_MESSAGE,
-			contexts: defaultContexts,
-			checked: true,
-			parentId: MENU_ID_AUTO_SAVE
-		});
-		menusCheckedState.set(MENU_ID_AUTO_SAVE_DISABLED, true);
-		menus.create({
-			id: MENU_ID_AUTO_SAVE_TAB,
-			type: "radio",
-			title: MENU_AUTOSAVE_TAB_MESSAGE,
-			contexts: defaultContexts,
-			checked: false,
-			parentId: MENU_ID_AUTO_SAVE
-		});
-		menusCheckedState.set(MENU_ID_AUTO_SAVE_TAB, false);
-		menus.create({
-			id: MENU_ID_AUTO_SAVE_UNPINNED,
-			type: "radio",
-			title: MENU_AUTOSAVE_UNPINNED_TABS_MESSAGE,
-			contexts: defaultContexts,
-			checked: false,
-			parentId: MENU_ID_AUTO_SAVE
-		});
-		menusCheckedState.set(MENU_ID_AUTO_SAVE_UNPINNED, false);
-		menus.create({
-			id: MENU_ID_AUTO_SAVE_ALL,
-			type: "radio",
-			title: MENU_AUTOSAVE_ALL_TABS_MESSAGE,
-			contexts: defaultContexts,
-			checked: false,
-			parentId: MENU_ID_AUTO_SAVE
-		});
-		menusCheckedState.set(MENU_ID_AUTO_SAVE_ALL, false);
-		menus.create({
-			id: "separator-4",
-			contexts: defaultContexts,
-			type: "separator"
-		});
+		if (AUTO_SAVE_SUPPORTED) {
+			menus.create({
+				id: MENU_ID_AUTO_SAVE,
+				contexts: defaultContexts,
+				title: MENU_AUTOSAVE_MESSAGE
+			});
+			menus.create({
+				id: MENU_ID_AUTO_SAVE_DISABLED,
+				type: "radio",
+				title: MENU_AUTOSAVE_DISABLED_MESSAGE,
+				contexts: defaultContexts,
+				checked: true,
+				parentId: MENU_ID_AUTO_SAVE
+			});
+			menusCheckedState.set(MENU_ID_AUTO_SAVE_DISABLED, true);
+			menus.create({
+				id: MENU_ID_AUTO_SAVE_TAB,
+				type: "radio",
+				title: MENU_AUTOSAVE_TAB_MESSAGE,
+				contexts: defaultContexts,
+				checked: false,
+				parentId: MENU_ID_AUTO_SAVE
+			});
+			menusCheckedState.set(MENU_ID_AUTO_SAVE_TAB, false);
+			menus.create({
+				id: MENU_ID_AUTO_SAVE_UNPINNED,
+				type: "radio",
+				title: MENU_AUTOSAVE_UNPINNED_TABS_MESSAGE,
+				contexts: defaultContexts,
+				checked: false,
+				parentId: MENU_ID_AUTO_SAVE
+			});
+			menusCheckedState.set(MENU_ID_AUTO_SAVE_UNPINNED, false);
+			menus.create({
+				id: MENU_ID_AUTO_SAVE_ALL,
+				type: "radio",
+				title: MENU_AUTOSAVE_ALL_TABS_MESSAGE,
+				contexts: defaultContexts,
+				checked: false,
+				parentId: MENU_ID_AUTO_SAVE
+			});
+			menusCheckedState.set(MENU_ID_AUTO_SAVE_ALL, false);
+			menus.create({
+				id: "separator-4",
+				contexts: defaultContexts,
+				type: "separator"
+			});
+		}
 		menus.create({
 			id: MENU_ID_BATCH_SAVE_URLS,
 			contexts: defaultContexts,

+ 15 - 2
src/ui/bg/ui-options.js

@@ -21,11 +21,14 @@
  *   Source.
  */
 
-/* global browser, window, document, localStorage, FileReader, location, fetch, TextDecoder, DOMParser, HTMLElement */
+/* global browser, window, document, localStorage, FileReader, location, fetch, TextDecoder, DOMParser, HTMLElement, navigator */
 
 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==";
 const HELP_PAGE_PATH = "/src/ui/pages/help.html";
 let DEFAULT_PROFILE_NAME, DISABLED_PROFILE_NAME, CURRENT_PROFILE_NAME;
+const AUTO_SAVE_SUPPORTED = !/Safari/.test(navigator.userAgent) || /Chrome/.test(navigator.userAgent);
+const BACKGROUND_SAVE_SUPPORTED = !/(Mobile.*Firefox|Chrome.*Safari)/.test(navigator.userAgent);
+
 browser.runtime.sendMessage({ method: "config.getConstants" }).then(data => ({ DEFAULT_PROFILE_NAME, DISABLED_PROFILE_NAME, CURRENT_PROFILE_NAME } = data));
 const removeHiddenElementsLabel = document.getElementById("removeHiddenElementsLabel");
 const removeUnusedStylesLabel = document.getElementById("removeUnusedStylesLabel");
@@ -264,7 +267,6 @@ const promptCancelButton = document.getElementById("promptCancelButton");
 const promptConfirmButton = document.getElementById("promptConfirmButton");
 const manifest = browser.runtime.getManifest();
 const requestPermissionIdentity = manifest.optional_permissions && manifest.optional_permissions.includes("identity");
-
 let sidePanelDisplay;
 if (location.href.endsWith("#side-panel")) {
 	sidePanelDisplay = true;
@@ -654,6 +656,17 @@ browser.runtime.sendMessage({ method: "tabsData.get" }).then(allTabsData => {
 	tabsData = allTabsData;
 	return refresh(tabsData.profileName);
 });
+if (!AUTO_SAVE_SUPPORTED) {
+	document.getElementById("autoSaveSection").hidden = true;
+	document.getElementById("showAutoSaveProfileOption").hidden = true;
+	rulesContainerElement.classList.add("compact");
+}
+if (!BACKGROUND_SAVE_SUPPORTED) {
+	document.getElementById("backgroundSaveOptions").hidden = true;
+	document.getElementById("confirmFilenameOption").hidden = true;
+	document.getElementById("filenameConflictAction").hidden = true;
+}
+
 getHelpContents();
 
 async function refresh(profileName) {

+ 5 - 5
src/ui/pages/options.html

@@ -73,11 +73,11 @@
 					</select>
 				</div>
 			</div>
-			<div class="option">
+			<div class="option" id="confirmFilenameOption">
 				<label for="confirmFilenameInput" id="confirmFilenameLabel"></label>
 				<input type="checkbox" id="confirmFilenameInput">
 			</div>
-			<div class="option">
+			<div class="option" id="filenameConflictAction">
 				<label for="filenameConflictActionInput" id="filenameConflictActionLabel"></label>
 				<select id="filenameConflictActionInput">
 					<option id="filenameConflictActionUniquifyLabel" value="uniquify"></option>
@@ -364,7 +364,7 @@
 				<input type="text" id="allowedBookmarkFoldersInput">
 			</div>
 		</details>
-		<details>
+		<details id="autoSaveSection">
 			<summary id="autoSaveLabel"></summary>
 			<div class="option">
 				<label for="autoSaveLoadOrUnloadInput" id="autoSaveLoadOrUnloadLabel"></label>
@@ -413,7 +413,7 @@
 				<label for="woleetKeyInput" id="woleetKeyLabel"></label>
 				<input type="text" id="woleetKeyInput">
 			</div>
-			<div class="option">
+			<div class="option" id="backgroundSaveOptions">
 				<label for="backgroundSaveInput" id="backgroundSaveLabel"></label>
 				<input type="checkbox" id="backgroundSaveInput">
 			</div>
@@ -467,7 +467,7 @@
 				<label for="showAllProfilesInput" id="showAllProfilesLabel"></label>
 				<input type="checkbox" id="showAllProfilesInput">
 			</div>
-			<div class="option">
+			<div class="option" id="showAutoSaveProfileOption">
 				<label for="showAutoSaveProfileInput" id="showAutoSaveProfileLabel"></label>
 				<input type="checkbox" id="showAutoSaveProfileInput">
 			</div>