diff --git a/README.md b/README.md index 1fad94b..f3b8a23 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ # click-guide A browser add-on which records the steps clicked on a page and generates a easy to understand guide from it. + +Similar to tango.us/dubble.so/folge.me/magichow.co but all local - no data leaves your device + +## To-Do MVP: +- [x] identify element selector or id +- [x] create a screenshot of the steps +- [x] ability to save multiple steps +- [x] export guide as json file +- [ ] add recording start/stop functionality +- [ ] create basic popup UI + +### Additional nice to have: +- [ ] Viewer for Guide JSON +- [ ] Editor for Guide +- [ ] improve error handling + +### Maybe far in the future: +- [ ] Optional cloud for sharing guide as link diff --git a/chrome/background.js b/chrome/background.js index 45b5110..b2b4908 100644 --- a/chrome/background.js +++ b/chrome/background.js @@ -1,21 +1,40 @@ // Background Worker +let steps = []; + chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { - console.log(message.action); - if (message.action == "captureScreenshot"){ - chrome.tabs.captureVisibleTab(null, { format: "jpeg" }, (dataUrl) => { - if (chrome.runtime.lastError) { - console.error("Error capturing screenshot: ", chrome.runtime.lastError); - sendResponse({ success: false, error: chrome.runtime.lastError }); - return; + switch(message.action){ + case "captureScreenshot": + chrome.tabs.captureVisibleTab(null, { format: "jpeg" }, (dataUrl) => { + if (chrome.runtime.lastError) { + console.error("Error capturing screenshot: ", chrome.runtime.lastError); + sendResponse({ success: false, error: chrome.runtime.lastError }); + return; + } + + sendResponse({ success: true, screenshot: dataUrl }); + }); + return true; + case "saveStep": + try{ + const step = { + "label":message.stepLabel, + "description":"Short description of the step", + "action":message.triggerName, + "element":message.stepElement, + "image":message.image + } + steps.push(step); + return sendResponse({ success: true, message: "Step successfully added to guide" }); } - - sendResponse({ success: true, screenshot: dataUrl }); - }); - return true; + catch(error){ + return sendResponse({ success: false, message: error }); + } + case "generateGuide": + return sendResponse({ success: true, guide: steps });; + case "debug": + default: + console.log(message.action); + break; } - /*chrome.scripting.executeScript({ - target: {tabId: tabs[0].id}, - files: ['test.js'] - });*/ }); \ No newline at end of file diff --git a/chrome/content.js b/chrome/content.js index 657f638..7418567 100644 --- a/chrome/content.js +++ b/chrome/content.js @@ -7,7 +7,6 @@ document.addEventListener('click', function(){ const element = event.target; const elementText = element.textContent; // gets the text of the clicked element const elementSelector = element.id; // the id of the clicked element, if exists (else its empty) - //console.log(elementText + ";" + elementSelector); const rect = element.getBoundingClientRect(); // create a rectangle from the element @@ -30,7 +29,15 @@ document.addEventListener('click', function(){ ); const croppedDataUrl = canvas.toDataURL("image/jpeg"); - console.log(croppedDataUrl); + chrome.runtime.sendMessage({ + action: "saveStep", + image: croppedDataUrl, + stepLabel: elementText, + stepElement: elementSelector, + triggerName: "click" + }, (response) => { + console.log(response); + }); }; } else { console.error("Error, while capturing the screenshot:", response.error); diff --git a/chrome/popup.html b/chrome/popup.html index dbf97b6..d4f7d04 100644 --- a/chrome/popup.html +++ b/chrome/popup.html @@ -9,6 +9,7 @@