32 lines
1006 B
JavaScript
32 lines
1006 B
JavaScript
document.addEventListener("DOMContentLoaded", async () => {
|
|
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
|
|
// Inject inject.js into page
|
|
chrome.scripting.executeScript({
|
|
target: { tabId: tab.id },
|
|
func: () => {
|
|
const script = document.createElement("script");
|
|
script.src = chrome.runtime.getURL("inject.js");
|
|
document.documentElement.appendChild(script);
|
|
script.remove();
|
|
}
|
|
});
|
|
|
|
// Wait for content.js to relay message from injected script
|
|
chrome.runtime.onMessage.addListener(function listener(message) {
|
|
if (message?.type === "PRODUCT_DATA") {
|
|
const data = message.data;
|
|
|
|
const output = document.getElementById("output");
|
|
output.textContent = JSON.stringify(data, null, 2);
|
|
|
|
document.getElementById("copyBtn").onclick = () => {
|
|
navigator.clipboard.writeText(output.textContent);
|
|
alert("Copied!");
|
|
};
|
|
|
|
chrome.runtime.onMessage.removeListener(listener);
|
|
}
|
|
});
|
|
});
|