add first version of coordinate saving to add-on #4

This commit is contained in:
Michi 2024-11-14 21:57:46 +01:00
parent 5efe19df58
commit 94fb124a40
3 changed files with 16 additions and 3 deletions

View file

@ -35,7 +35,8 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
"description":"Short description of the step", "description":"Short description of the step",
"action":message.triggerName, "action":message.triggerName,
"element":message.stepElement, "element":message.stepElement,
"image":message.image "image":message.image,
"elementPosition":message.elementPosition
} }
steps.push(step); steps.push(step);
return sendResponse({ success: true, message: "Step successfully added to guide" }); return sendResponse({ success: true, message: "Step successfully added to guide" });

View file

@ -73,6 +73,12 @@ document.addEventListener('click', function(){
viewportX, viewportY, croppedWidth, croppedHeight, viewportX, viewportY, croppedWidth, croppedHeight,
0, 0, croppedWidth, croppedHeight 0, 0, croppedWidth, croppedHeight
); );
// calculate coordinates of the clicked element
const elementStartX = Math.max((rect.left - (parentRect.left - pixelPadding / 2)), 0);
const elementStartY = Math.max((rect.top - (parentRect.top - pixelPadding / 2)), 0);
const elementEndX = elementStartX + rect.width;
const elementEndY = elementStartY + rect.height;
const croppedDataUrl = canvas.toDataURL("image/jpeg"); const croppedDataUrl = canvas.toDataURL("image/jpeg");
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
@ -80,7 +86,13 @@ document.addEventListener('click', function(){
image: croppedDataUrl, image: croppedDataUrl,
stepLabel: elementText, stepLabel: elementText,
stepElement: elementSelector, stepElement: elementSelector,
triggerName: "click" triggerName: "click",
elementPosition: {
startX: elementStartX,
startY: elementStartY,
endX: elementEndX,
endY: elementEndY
}
}, (response) => { }, (response) => {
console.log(response); console.log(response);
}); });

View file

@ -1,7 +1,7 @@
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "Cl1ck Gu1de", "name": "Cl1ck Gu1de",
"version": "0.0.4", "version": "0.0.5",
"description": "A browser add-on which records the steps clicked on a page and generates a easy to understand guide from it.", "description": "A browser add-on which records the steps clicked on a page and generates a easy to understand guide from it.",
"permissions": ["scripting", "activeTab", "downloads", "tabs", "storage"], "permissions": ["scripting", "activeTab", "downloads", "tabs", "storage"],
"host_permissions": ["<all_urls>"], "host_permissions": ["<all_urls>"],