From 75e47cc163e30fc336f268f6dedda12a29a00114 Mon Sep 17 00:00:00 2001 From: Raphael Piccolo Date: Mon, 13 May 2024 22:51:32 +0200 Subject: [PATCH] up --- background.js | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ icon.png | Bin 0 -> 4458 bytes manifest.json | 29 +++++++++++++ popup.html | 39 +++++++++++++++++ 4 files changed, 185 insertions(+) create mode 100644 background.js create mode 100644 icon.png create mode 100644 manifest.json create mode 100644 popup.html diff --git a/background.js b/background.js new file mode 100644 index 0000000..c079f7f --- /dev/null +++ b/background.js @@ -0,0 +1,117 @@ +// Define a variable to store last call URL info +let lastCallInfo = { date: '', result: '' }; + +// Function to update last call URL info +function updateLastCallInfo(date, result) { + lastCallInfo.date = date; + lastCallInfo.result = result; +} + +// Function to send last call URL info to popup +function sendLastCallInfoToPopup() { + chrome.runtime.sendMessage({ type: 'updatePopup', date: lastCallInfo.date, result: lastCallInfo.result }); +} + +// Message listener for communication with popup +chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { + if (message.type === 'getLastCallInfo') { + // Send last call URL info to popup + sendLastCallInfoToPopup(); + } else if (message.type === 'callURLManually') { + // Call URL function manually + callURL(); + } +}); + +// Function to call the URL +async function callURL() { + try { + const bookmarks = await exportBookmarks(); + const response = await fetch('https://httptest.raphaelpiccolo.com/error', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(bookmarks) + }); + const text = await response.text(); + console.log('réponse', text); + // Update last call URL info + updateLastCallInfo(new Date().toLocaleString(), text); + // Send updated info to popup + sendLastCallInfoToPopup(); + } catch (err) { + console.error('Une erreur est survenue lors de l\'appel à l\'URL :', err); + // Update last call URL info with error + updateLastCallInfo(new Date().toLocaleString(), 'Error: ' + err.message); + // Send updated info to popup + sendLastCallInfoToPopup(); + } +} + +// Get bookmarks recursively +function getBookmarks(node) { + if (node.children) { + const bookmarks = []; + for (const child of node.children) { + if (child.url) { + bookmarks.push({ title: child.title, url: child.url }); + } else { + bookmarks.push({ folder: child.title, children: getBookmarks(child) }); + } + } + return bookmarks; + } +} + +// Function to export bookmarks +async function exportBookmarks() { + return new Promise((resolve, reject) => { + chrome.bookmarks.getTree((nodes) => { + const bookmarks = getBookmarks(nodes[0]); + resolve(bookmarks); + }); + }); +} + +// Event listeners for bookmarks changes +chrome.bookmarks.onCreated.addListener(callURL); +chrome.bookmarks.onChanged.addListener(callURL); +chrome.bookmarks.onImportEnded.addListener(callURL); +chrome.bookmarks.onMoved.addListener(callURL); +chrome.bookmarks.onChildrenReordered.addListener(callURL); + +// Call URL function on chrome boot +setTimeout(callURL, 10000); + + + + + +async function pushActivity(tab) { + var url = (await chrome.tabs.get(tab)).url; + console.log(url); +} + +chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { + // Vérifier si l'URL a changé + if (changeInfo.url) { + pushActivity(tabId); + } +}); + +chrome.tabs.onActivated.addListener((tab) => { pushActivity(tab.tabId) }); + + + +// window.setInterval(checkBrowserFocus, 1000); + +// function checkBrowserFocus() { + +// chrome.windows.getCurrent(function (browser) { + +// console.log(browser.focused) + +// }) + +// } \ No newline at end of file diff --git a/icon.png b/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..96a9572d13f637e28c79b7dc683b40787c263181 GIT binary patch literal 4458 zcmds)c~nzZ9>+1pB`i8^>L8%fsWVXqtpZ9^lvpGJ$qS%JDFOyXMP*4{00lyfZNVKG zMMV@!t+*3Gh02l#BA|jIh9$BjfIuXWfDn?9`10o7aHeO*IdkTZnZG>eci#Kn`?Ob9>{Or}o;ugcs%KLv{#Ut|*x)3DSbNzs~H;AufGFzF zgCHP+9QN`!v3?y$2Mjkc0olQRGs6ouYt&!|G?I=mdW}he20Lj?FMQ`tQ0<_X7jT>? z`>5MmAfRS4L0+gq5GJ$V-+!Vug^v%22~2KmQ$nY|-L$D6EWvr>WaJw*h<$xPKsl(# zcoH0z(dm80AxuPr!#4&8sGq@j$6&zaKgJFwQ|IPZYcwF9|C0b3>^w6X5KoQh_h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++!v(zCqrkyn rNX0a55iLBWUcke{hc?q{aTCY6+s+01enAHRG)=td-tKvBp-27>8HpDg literal 0 HcmV?d00001 diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..b7dc4c9 --- /dev/null +++ b/manifest.json @@ -0,0 +1,29 @@ +{ + "manifest_version": 3, + "name": "favoris backup", + "description": "Link to G Suite Certification website", + "version": "1.2", + "icons": { + "128": "icon.png" + }, + "action": { + "default_icon": { + "128": "icon.png" + }, + "default_title": "Click Me", + "default_popup": "popup.html" + }, + "background": { + "service_worker": "background.js" + }, + "host_permissions": [ + "https://httptest.raphaelpiccolo.com/*" + ], + "permissions": [ + "unlimitedStorage", + "notifications", + "bookmarks", + "tabs", + "nativeMessaging" + ] +} diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..3c09bb6 --- /dev/null +++ b/popup.html @@ -0,0 +1,39 @@ + + + + + + Popup + + + +

Last Call URL Date:

+

Result:

+
+ + + + +