diff --git a/Builds/mltshp.chrome.crx b/Builds/mltshp.chrome.crx old mode 100644 new mode 100755 index 1ec5d37..fd68980 Binary files a/Builds/mltshp.chrome.crx and b/Builds/mltshp.chrome.crx differ diff --git a/Builds/mltshp.firefox.xpi b/Builds/mltshp.firefox.xpi old mode 100644 new mode 100755 index 94af759..6876b43 Binary files a/Builds/mltshp.firefox.xpi and b/Builds/mltshp.firefox.xpi differ diff --git a/Source/WebExtension/background.html b/Source/WebExtension/background.html deleted file mode 100644 index 9d59b3a..0000000 --- a/Source/WebExtension/background.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Source/WebExtension/background.js b/Source/WebExtension/background.js index 6740384..6bbcc78 100644 --- a/Source/WebExtension/background.js +++ b/Source/WebExtension/background.js @@ -1,31 +1,39 @@ /** * Returns a handler which will open a new window when activated. */ -function getClickHandler() { - return function(info, tab) { - source_url = tab.url - if (source_url == info.srcUrl) { - path_array = source_url.split('/'); - source_url = path_array[0] + "//" + path_array[2]; - } - chrome.tabs.sendMessage(tab.id, "getAltText", { frameId: info.frameId }, data => { - chrome.windows.create({ - "url": "https://mltshp.com/tools/p?url=" + escape(info.srcUrl) + "&source_url=" + escape(source_url) + '&alt=' + escape(data.alt), - "type": 'popup', - "height": 650, - "width": 850, - "top": (screen.height / 2) - (650 / 2), - "left": (screen.width / 2) - (850 / 2) - }); + +const menuItemId = 'mltshpplgn' + +const getClickHandler = (info, tab) => { + + source_url = tab.url + if (source_url == info.srcUrl) { + path_array = source_url.split('/'); + source_url = path_array[0] + "//" + path_array[2]; + } + + chrome.tabs.sendMessage(tab.id, "getAltText", { frameId: info.frameId }, data => { + chrome.windows.create({ + "url": "https://mltshp.com/tools/p?url=" + encodeURIComponent(info.srcUrl) + "&source_url=" + encodeURIComponent(source_url) + '&alt=' + encodeURIComponent(data.alt), + "type": 'popup', + "height": 650, + "width": 850, }); - }; + }); }; + /** * Create a context menu which will only show up for images. */ chrome.contextMenus.create({ + "id": menuItemId, "title": "Save this image on MLTSHP", "type": "normal", "contexts": ["image"], - "onclick": getClickHandler() }); + +chrome.contextMenus.onClicked.addListener(function (info, tab) { + if (info.menuItemId === menuItemId) { + getClickHandler(info, tab) + } +}); \ No newline at end of file diff --git a/Source/WebExtension/content.js b/Source/WebExtension/content.js index 2af8139..716fb12 100644 --- a/Source/WebExtension/content.js +++ b/Source/WebExtension/content.js @@ -1,10 +1,10 @@ -var clickedEl = null; +let clickedEl = null; -document.addEventListener("contextmenu", function(event){ +document.addEventListener("contextmenu", function (event) { clickedEl = event.target; }, true); -chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { +chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { if (request == "getAltText") { sendResponse({ alt: clickedEl.getAttribute('alt') || '' diff --git a/Source/WebExtension/manifest.json b/Source/WebExtension/manifest.json index 363a680..62b6abe 100644 --- a/Source/WebExtension/manifest.json +++ b/Source/WebExtension/manifest.json @@ -1,10 +1,15 @@ { "name": "mltshp", - "version": "2.0", - "manifest_version": 2, + "version": "3.0", + "manifest_version": 3, "description": "Post photos to mltshp.com.", - "browser_action": { - "default_icon": "icon_48.png", + "action": { + "default_icon": { + "16": "icon_16.png", + "48": "icon_48.png", + "96": "icon_96.png", + "128": "icon_128.png" + }, "default_popup": "menu.html", "default_title": "MLTSHP" }, @@ -16,12 +21,24 @@ }, "content_scripts": [ { - "matches": ["*://*/*"], - "js": ["content.js"] + "matches": [ + "*://*/*" + ], + "js": [ + "content.js" + ] } ], "background": { - "page": "background.html" + "service_worker": "background.js" }, - "permissions": ["tabs", "contextMenus", "http://*/*", "http://*/", "https://*/"] -} + "optional_host_permissions": [ + "http://*/*", + "http://*/", + "https://*/" + ], + "permissions": [ + "tabs", + "contextMenus" + ] +} \ No newline at end of file diff --git a/Source/WebExtension/menu.html b/Source/WebExtension/menu.html index be1d400..cf079d1 100644 --- a/Source/WebExtension/menu.html +++ b/Source/WebExtension/menu.html @@ -1,15 +1,14 @@ - + - +

Right-click on any image to upload it to MLTSHP

- - - \ No newline at end of file + + diff --git a/Source/WebExtensionFirefox/README b/Source/WebExtensionFirefox/README new file mode 100644 index 0000000..6759f89 --- /dev/null +++ b/Source/WebExtensionFirefox/README @@ -0,0 +1,7 @@ +A MLTSHP extension for all browsers that support the WebExtension format. Currently this includes: +- Chrome +- Opera +- Firefox +- Microsoft Edge + +Based on https://github.com/torrez/mlkshk.chrome \ No newline at end of file diff --git a/Source/WebExtensionFirefox/background.js b/Source/WebExtensionFirefox/background.js new file mode 100644 index 0000000..6bbcc78 --- /dev/null +++ b/Source/WebExtensionFirefox/background.js @@ -0,0 +1,39 @@ +/** + * Returns a handler which will open a new window when activated. + */ + +const menuItemId = 'mltshpplgn' + +const getClickHandler = (info, tab) => { + + source_url = tab.url + if (source_url == info.srcUrl) { + path_array = source_url.split('/'); + source_url = path_array[0] + "//" + path_array[2]; + } + + chrome.tabs.sendMessage(tab.id, "getAltText", { frameId: info.frameId }, data => { + chrome.windows.create({ + "url": "https://mltshp.com/tools/p?url=" + encodeURIComponent(info.srcUrl) + "&source_url=" + encodeURIComponent(source_url) + '&alt=' + encodeURIComponent(data.alt), + "type": 'popup', + "height": 650, + "width": 850, + }); + }); +}; + +/** + * Create a context menu which will only show up for images. + */ +chrome.contextMenus.create({ + "id": menuItemId, + "title": "Save this image on MLTSHP", + "type": "normal", + "contexts": ["image"], +}); + +chrome.contextMenus.onClicked.addListener(function (info, tab) { + if (info.menuItemId === menuItemId) { + getClickHandler(info, tab) + } +}); \ No newline at end of file diff --git a/Source/WebExtensionFirefox/content.js b/Source/WebExtensionFirefox/content.js new file mode 100644 index 0000000..716fb12 --- /dev/null +++ b/Source/WebExtensionFirefox/content.js @@ -0,0 +1,13 @@ +let clickedEl = null; + +document.addEventListener("contextmenu", function (event) { + clickedEl = event.target; +}, true); + +chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { + if (request == "getAltText") { + sendResponse({ + alt: clickedEl.getAttribute('alt') || '' + }); + } +}); diff --git a/Source/WebExtensionFirefox/icon_128.png b/Source/WebExtensionFirefox/icon_128.png new file mode 100644 index 0000000..e2370ad Binary files /dev/null and b/Source/WebExtensionFirefox/icon_128.png differ diff --git a/Source/WebExtensionFirefox/icon_16.png b/Source/WebExtensionFirefox/icon_16.png new file mode 100644 index 0000000..faae89e Binary files /dev/null and b/Source/WebExtensionFirefox/icon_16.png differ diff --git a/Source/WebExtensionFirefox/icon_48.png b/Source/WebExtensionFirefox/icon_48.png new file mode 100644 index 0000000..d0cfe49 Binary files /dev/null and b/Source/WebExtensionFirefox/icon_48.png differ diff --git a/Source/WebExtensionFirefox/icon_96.png b/Source/WebExtensionFirefox/icon_96.png new file mode 100644 index 0000000..6b0ce16 Binary files /dev/null and b/Source/WebExtensionFirefox/icon_96.png differ diff --git a/Source/WebExtensionFirefox/manifest.json b/Source/WebExtensionFirefox/manifest.json new file mode 100644 index 0000000..53f875b --- /dev/null +++ b/Source/WebExtensionFirefox/manifest.json @@ -0,0 +1,51 @@ +{ + "name": "mltshp", + "version": "3.0", + "manifest_version": 3, + "description": "Post photos to mltshp.com.", + "browser_specific_settings": { + "gecko": { + "id": "{13e446e1-2a83-49ff-8cf1-cf2d84896826}" + } + }, + "action": { + "default_icon": { + "16": "icon_16.png", + "48": "icon_48.png", + "96": "icon_96.png", + "128": "icon_128.png" + }, + "default_popup": "menu.html", + "default_title": "MLTSHP" + }, + "icons": { + "16": "icon_16.png", + "48": "icon_48.png", + "96": "icon_96.png", + "128": "icon_128.png" + }, + "content_scripts": [ + { + "matches": [ + "*://*/*" + ], + "js": [ + "content.js" + ] + } + ], + "background": { + "scripts": [ + "background.js" + ] + }, + "host_permissions": [ + "http://*/*", + "http://*/", + "https://*/" + ], + "permissions": [ + "tabs", + "contextMenus" + ] +} \ No newline at end of file diff --git a/Source/WebExtensionFirefox/menu.html b/Source/WebExtensionFirefox/menu.html new file mode 100644 index 0000000..cf079d1 --- /dev/null +++ b/Source/WebExtensionFirefox/menu.html @@ -0,0 +1,14 @@ + + + + +

Right-click on any image to upload it to MLTSHP

+ +