Skip to content

Commit

Permalink
nicer icon, change icon on success only, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mpec committed Jul 14, 2020
1 parent dff2037 commit 462c45d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This is a chrome extension to save image from https://zespolmi.pl to clipboard
This is a chrome extension to copy image from https://zespolmi.pl to clipboard
39 changes: 20 additions & 19 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
chrome.browserAction.onClicked.addListener(function() {
chrome.tabs.query({
currentWindow: true,
active: true
}, function(tab) {
chrome.tabs.sendMessage(tab[0].id, {message: "copy_image"});

chrome.browserAction.setIcon({
path: "icon-saved.png",
tabId: tab[0].id
});

setTimeout(function(){
chrome.browserAction.onClicked.addListener(function () {
chrome.tabs.query({
currentWindow: true,
active: true
}, function (tab) {
chrome.tabs.sendMessage(tab[0].id, { message: "copy_image" });
});
});

chrome.runtime.onMessage.addListener(
function(request) {
if (request.message == "success")
chrome.browserAction.setIcon({
path: "icon.png",
tabId: tab[0].id
path: "icon-saved.png"
});
}, 2000)

});
});

setTimeout(function () {
chrome.browserAction.setIcon({
path: "icon.png"
});
}, 2000)
});
32 changes: 17 additions & 15 deletions src/content.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
function (request, sender, sendResponse) {

if( request.message === "copy_image" ) {
const img = document.querySelector("#contentimg .img-responsive");
if(img){
var canvas = document.createElement("canvas");
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
canvas.getContext("2d").drawImage(img, 0, 0);
canvas.toBlob(function(blob) {
navigator.clipboard.write([
if (request.message === "copy_image") {
const img = document.querySelector("#contentimg .img-responsive");

if (img) {
var canvas = document.createElement("canvas");
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
canvas.getContext("2d").drawImage(img, 0, 0);

canvas.toBlob(function (blob) {
navigator.clipboard.write([
new ClipboardItem({
[blob.type]: blob
})
])
});
]);
});

chrome.runtime.sendMessage({message: "success"});
}
}
}
}
);
Binary file modified src/icon-saved.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 modified src/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 17 additions & 10 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
{
"manifest_version": 2,

"name": "ZespolMi - image saver",
"description": "Save the current image from zespolmi.pl",
"version": "1.0",
"name": "ZespolMi - image copier",
"description": "Copy the current image from zespolmi.pl to clipboard",
"version": "1.1",
"background": {
"scripts": ["background.js"]
"scripts": [
"background.js"
]
},
"content_scripts": [
{
"matches": ["https://zespolmi.pl/*"],
"js": ["content.js"]
"matches": [
"https://zespolmi.pl/*"
],
"js": [
"content.js"
]
}
],
"permissions": ["tabs"],
],
"permissions": [
"tabs"
],
"browser_action": {
"default_icon": "icon.png",
"default_title": "Save"
"default_title": "Copy"
}
}

0 comments on commit 462c45d

Please sign in to comment.