32 lines
948 B
JavaScript
32 lines
948 B
JavaScript
chrome.runtime.onInstalled.addListener(() => {
|
|
chrome.tabs.query({ url: "*://*.x.com/*" }, (tabs) => {
|
|
for (let tab of tabs) {
|
|
chrome.scripting.executeScript({
|
|
target: {tabId: tab.id, allFrames: true},
|
|
files: ['content.js']
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
|
if (changeInfo.status === 'complete' && /^https:\/\/(www\.)?(x|twitter)\.com/.test(tab.url)) {
|
|
chrome.scripting.executeScript({
|
|
target: {tabId: tabId, allFrames: true},
|
|
files: ['content.js']
|
|
});
|
|
}
|
|
});
|
|
|
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
if (request.action === "fetchData") {
|
|
fetch(request.url)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
sendResponse({ data: data });
|
|
})
|
|
.catch(error => console.error("Error fetching token data:", error));
|
|
return true; // Will respond asynchronously
|
|
}
|
|
});
|