Browse Source

don't restrict infobar displaying to file: URIs (fix #406)

Former-commit-id: cd3549393363bd86e7c5ee7dfd08c646889ee1d6
Gildas 5 năm trước cách đây
mục cha
commit
85ee22fbec
1 tập tin đã thay đổi với 13 bổ sung18 xóa
  1. 13 18
      common/ui/content/content-infobar-web.js

+ 13 - 18
common/ui/content/content-infobar-web.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global document, Node, window, top, getComputedStyle, location, setTimeout */
+/* global document, Node, window, top, getComputedStyle, setTimeout */
 
 (() => {
 
@@ -32,7 +32,7 @@
 
 	const browser = this.browser;
 
-	if (window == top && location && location.href && location.href.startsWith("file:///")) {
+	if (window == top) {
 		if (document.readyState == "loading") {
 			document.addEventListener("DOMContentLoaded", displayIcon, false);
 		} else {
@@ -42,28 +42,23 @@
 
 	async function displayIcon() {
 		let singleFileComment = document.documentElement.childNodes[0];
-		if (!isSingleFileComment(singleFileComment)) {
-			singleFileComment = findSingleFileComment();
-		}
-		if (singleFileComment) {
+		if (singleFileComment && isSingleFileComment(singleFileComment)) {
 			const info = singleFileComment.textContent.split("\n");
 			const [, , url, saveDate, ...infoData] = info;
-			let options;
-			if (browser && browser.runtime && browser.runtime.sendMessage) {
-				options = await browser.runtime.sendMessage({ method: "tabs.getOptions", url });
-			} else {
-				options = { displayInfobar: true };
-			}
-			if (options.displayInfobar) {
-				initInfobar(url, saveDate, infoData);
+			if (url && saveDate) {
+				let options;
+				if (browser && browser.runtime && browser.runtime.sendMessage) {
+					options = await browser.runtime.sendMessage({ method: "tabs.getOptions", url });
+				} else {
+					options = { displayInfobar: true };
+				}
+				if (options.displayInfobar) {
+					initInfobar(url, saveDate, infoData);
+				}
 			}
 		}
 	}
 
-	function findSingleFileComment(node = document.documentElement) {
-		return node.childNodes && node.childNodes.length ? Array.from(node.childNodes).find(findSingleFileComment) : isSingleFileComment(node);
-	}
-
 	function isSingleFileComment(node) {
 		return node.nodeType == Node.COMMENT_NODE && node.textContent.includes(SINGLEFILE_COMMENT);
 	}