From e4aa82fe32bb28f420f4b310bdbe5079a3811ef6 Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Thu, 27 Apr 2017 20:59:19 +0200 Subject: [PATCH] Change menu ID format + fix new tab URL having the protocol duplicated --- src/content/content.js | 16 ++++++++-------- src/manifest.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/content/content.js b/src/content/content.js index 44e7cc1..ef82ba4 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -19,13 +19,11 @@ let imgs = document.getElementsByTagName("img"); for (let i = 0; i < imgs.length; i++) { /** @type HTMLElement */ let img = imgs[i]; - if (img.hasAttribute("contextmenu") && !img.getAttribute("contextmenu").startsWith("new-tab-image@exe-boss:menu")) { + if (img.hasAttribute("contextmenu") && !img.getAttribute("contextmenu").startsWith("eb-img-menu:")) { continue; } - let menuId = "new-tab-image@exe-boss:menu?id=" + i; + let menuId = "eb-img-menu:" + Math.floor(Math.random() * 65535 + 1).toString(16) + ":" + i.toString(16); - /** @type String */ - let functionName = Math.floor(Math.random() * 65535 + 1).toString(16); /** @type HTMLMenuElement */ let menu = document.createElement("menu"); menu.setAttribute("type", "context"); @@ -44,10 +42,12 @@ for (let i = 0; i < imgs.length; i++) { } else { let protocolRegex = /^\w+:\/\//; let hostNameRegex = /^\w+.\w+/; - if (url.match(hostNameRegex)) { - url = window.location.protocol + "//" + url; - } else if (!url.match(protocolRegex)) { - url = window.location.protocol + "//" + window.location.host + '/' + url; + if (!url.match(protocolRegex)) { + if (url.match(hostNameRegex)) { + url = window.location.protocol + "//" + url; + } else { + url = window.location.protocol + "//" + window.location.host + '/' + url; + } } } // calling `browser.tabs.create({url: String(message.url)});` here causes an error for some odd reason diff --git a/src/manifest.json b/src/manifest.json index c2dc113..4b89c6e 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -8,7 +8,7 @@ "manifest_version": 2, "name": "View Image in New Tab", - "version": "0.1.0", + "version": "0.1.1", "author": "ExE Boss", "icons": {