Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to Chrome and Firefox Extensions #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Builds/mltshp.chrome.crx
100644 → 100755
Binary file not shown.
Binary file modified Builds/mltshp.firefox.xpi
100644 → 100755
Binary file not shown.
8 changes: 0 additions & 8 deletions Source/WebExtension/background.html

This file was deleted.

44 changes: 26 additions & 18 deletions Source/WebExtension/background.js
Original file line number Diff line number Diff line change
@@ -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)
}
});
6 changes: 3 additions & 3 deletions Source/WebExtension/content.js
Original file line number Diff line number Diff line change
@@ -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') || ''
Expand Down
35 changes: 26 additions & 9 deletions Source/WebExtension/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand All @@ -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"
]
}
19 changes: 9 additions & 10 deletions Source/WebExtension/menu.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<html>
<style type="text/css">
<style type="text/css">
p {
font-size: 11px;
color: #333;
font-family: Helvetica, sans-serif;
width: 100px;
font-size: 11px;
color: #333;
font-family: Helvetica, sans-serif;
width: 100px;
}
</style>
</style>

<body>
<body>
<p>Right-click on any image to upload it to MLTSHP</p>
</body>

</html>
</body>
</html>
7 changes: 7 additions & 0 deletions Source/WebExtensionFirefox/README
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions Source/WebExtensionFirefox/background.js
Original file line number Diff line number Diff line change
@@ -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)
}
});
13 changes: 13 additions & 0 deletions Source/WebExtensionFirefox/content.js
Original file line number Diff line number Diff line change
@@ -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') || ''
});
}
});
Binary file added Source/WebExtensionFirefox/icon_128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Source/WebExtensionFirefox/icon_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Source/WebExtensionFirefox/icon_48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Source/WebExtensionFirefox/icon_96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions Source/WebExtensionFirefox/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
14 changes: 14 additions & 0 deletions Source/WebExtensionFirefox/menu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<style type="text/css">
p {
font-size: 11px;
color: #333;
font-family: Helvetica, sans-serif;
width: 100px;
}
</style>

<body>
<p>Right-click on any image to upload it to MLTSHP</p>
</body>
</html>