Browse Source

moved isAllowedURL into core

Gildas 7 years ago
parent
commit
78551c9d0e
4 changed files with 14 additions and 16 deletions
  1. 6 1
      extension/core/bg/bg.js
  2. 4 4
      extension/ui/bg/ui-button.js
  3. 3 3
      extension/ui/bg/ui-menu.js
  4. 1 8
      extension/ui/bg/ui.js

+ 6 - 1
extension/core/bg/bg.js

@@ -22,6 +22,8 @@
 
 singlefile.core = (() => {
 
+	const FORBIDDEN_URLS = ["https://chrome.google.com", "https://addons.mozilla.org"];
+
 	const contentScriptFiles = [
 		"lib/browser-polyfill/custom-browser-polyfill.js",
 		"/extension/index.js",
@@ -64,7 +66,7 @@ singlefile.core = (() => {
 		const tabsData = await singlefile.storage.get();
 		delete tabsData[tabId];
 		await singlefile.storage.set(tabsData);
-	});	
+	});
 
 	return {
 		async processTab(tab, processOptions = {}) {
@@ -79,6 +81,9 @@ singlefile.core = (() => {
 				}
 				resolve();
 			});
+		},
+		isAllowedURL(url) {
+			return url && (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("file://")) && !FORBIDDEN_URLS.find(storeUrl => url.startsWith(storeUrl));
 		}
 	};
 

+ 4 - 4
extension/ui/bg/ui-button.js

@@ -29,12 +29,12 @@ singlefile.ui.button = (() => {
 	const BUTTON_PROPERTIES = [{ name: "color", browserActionMethod: "setBadgeBackgroundColor" }, { name: "path", browserActionMethod: "setIcon" }, { name: "text", browserActionMethod: "setBadgeText" }, { name: "title", browserActionMethod: "setTitle" }];
 
 	browser.browserAction.onClicked.addListener(async tab => {
-		if (singlefile.ui.isAllowedURL(tab.url)) {
+		if (singlefile.core.isAllowedURL(tab.url)) {
 			const tabs = await browser.tabs.query({ currentWindow: true, highlighted: true });
 			if (!tabs.length) {
 				singlefile.ui.processTab(tab);
 			} else {
-				tabs.forEach(tab => singlefile.ui.isAllowedURL(tab.url) && singlefile.ui.processTab(tab));
+				tabs.forEach(tab => singlefile.core.isAllowedURL(tab.url) && singlefile.ui.processTab(tab));
 			}
 		}
 	});
@@ -89,8 +89,8 @@ singlefile.ui.button = (() => {
 	async function onTabActivated(tab) {
 		const autoSave = await singlefile.ui.autosave.isEnabled(tab.id);
 		await refresh(tab.id, getProperties(tab.id, { autoSave }));
-		if (singlefile.ui.isAllowedURL(tab.url) && browser.browserAction && browser.browserAction.enable && browser.browserAction.disable) {
-			if (singlefile.ui.isAllowedURL(tab.url)) {
+		if (singlefile.core.isAllowedURL(tab.url) && browser.browserAction && browser.browserAction.enable && browser.browserAction.disable) {
+			if (singlefile.core.isAllowedURL(tab.url)) {
 				try {
 					await browser.browserAction.enable(tab.id);
 				} catch (error) {

+ 3 - 3
extension/ui/bg/ui-menu.js

@@ -157,15 +157,15 @@ singlefile.ui.menu = (() => {
 				}
 				if (event.menuItemId == MENU_ID_SAVE_SELECTED_TABS) {
 					const tabs = await browser.tabs.query({ currentWindow: true, highlighted: true });
-					tabs.forEach(tab => singlefile.ui.isAllowedURL(tab.url) && singlefile.ui.processTab(tab));
+					tabs.forEach(tab => singlefile.core.isAllowedURL(tab.url) && singlefile.ui.processTab(tab));
 				}
 				if (event.menuItemId == MENU_ID_SAVE_UNPINNED_TABS) {
 					const tabs = await browser.tabs.query({ currentWindow: true, pinned: false });
-					tabs.forEach(tab => singlefile.ui.isAllowedURL(tab.url) && singlefile.ui.processTab(tab));
+					tabs.forEach(tab => singlefile.core.isAllowedURL(tab.url) && singlefile.ui.processTab(tab));
 				}
 				if (event.menuItemId == MENU_ID_SAVE_ALL_TABS) {
 					const tabs = await browser.tabs.query({ currentWindow: true });
-					tabs.forEach(tab => singlefile.ui.isAllowedURL(tab.url) && singlefile.ui.processTab(tab));
+					tabs.forEach(tab => singlefile.core.isAllowedURL(tab.url) && singlefile.ui.processTab(tab));
 				}
 				if (event.menuItemId == MENU_ID_AUTO_SAVE_TAB) {
 					const tabsData = await singlefile.storage.get();

+ 1 - 8
extension/ui/bg/ui.js

@@ -22,11 +22,8 @@
 
 singlefile.ui = (() => {
 
-	const FORBIDDEN_URLS = ["https://chrome.google.com", "https://addons.mozilla.org"];
-
 	return {
-		processTab,
-		isAllowedURL
+		processTab
 	};
 
 	async function processTab(tab, options = {}) {
@@ -41,8 +38,4 @@ singlefile.ui = (() => {
 		}
 	}
 
-	function isAllowedURL(url) {
-		return url && (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("file://")) && !FORBIDDEN_URLS.find(storeUrl => url.startsWith(storeUrl));
-	}
-
 })();