Skip to content

Commit

Permalink
Better, more logical paste
Browse files Browse the repository at this point in the history
  • Loading branch information
rberenguel committed Nov 24, 2024
1 parent c1ebf51 commit 711faa6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "Goita",
"description": "Take a screenshot, add arrows and sh*t as you wish. With blackjack, and memes",
"version": "2.0.0",
"version": "2.0.1",
"permissions": [
"tabs",
"activeTab",
Expand Down
34 changes: 31 additions & 3 deletions src/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,10 @@ const setupAllTheThings = (testImage, basepath) => () => {

document.addEventListener("paste", (event) => {
const clipboardData = event.clipboardData || window.clipboardData;
console.info(clipboardData);
if (clipboardData) {
const pastedText = clipboardData.getData("text");
console.info(pastedText);
if (pastedText && kind === "memes") {
// Can I take this out? It's the same as the callback-meme
// Can I take this out? It's the same as the callback-meme, and repeated below
const container = document.getElementById("meme-container");

if (container) {
Expand All @@ -248,6 +246,36 @@ const setupAllTheThings = (testImage, basepath) => () => {
selected = pastedMeme;
displayMemes = false;
}
const pastedImage = clipboardData.files[0];
if (pastedImage && pastedImage.type.startsWith("image")) {
const reader = new FileReader();
reader.onload = (e) => {
const base64Image = e.target.result;

const container = document.getElementById("meme-container");

if (container) {
container.remove();
}
let x = 0,
y = 0;
if (lastClick) {
x = lastClick.offsetX;
y = lastClick.offsetY;
}
const pastedMeme = new Image(x, y, base64Image, svg);
kind = null;
searchText = "";
filterText.style.display = "none";
filteredMemes.style.display = "none";
setBadge("empty");
window._elements[pastedMeme.id] = pastedMeme;
selected = pastedMeme;
displayMemes = false;
};

reader.readAsDataURL(pastedImage);
}
}
});

Expand Down

0 comments on commit 711faa6

Please sign in to comment.