-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
71 lines (61 loc) · 2.72 KB
/
content.js
File metadata and controls
71 lines (61 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
if (typeof html2canvas !== 'undefined') {
console.log('html2canvas is loaded correctly.');
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'captureTweet') {
const tweetLink = request.tweetLink;
const tokenName = request.tokenName;
const ticker = request.ticker;
const devBuyPrompt = request.devBuyPrompt;
// Log received data for debugging
console.log('Received message in content script:');
console.log('Tweet Link:', tweetLink);
console.log('Token Name:', tokenName);
console.log('Ticker:', ticker);
console.log('Dev Buy:', devBuyPrompt);
// Capture the tweet from the currently rendered page
let tweet = document.querySelector('[data-testid="tweet"]');
if (!tweet) {
tweet = document.querySelector('[data-testid="cellInnerDiv"]');
}
if (tweet) {
console.log('Tweet found, capturing image.');
html2canvas(tweet, {
useCORS: true,
backgroundColor: 'black'
}).then(canvas => {
const imgData = canvas.toDataURL('image/png');
// Log the image data for debugging
console.log('Captured Image Data:', imgData);
// Send the image data and other inputs back to the popup
sendResponse({
success: true,
image: imgData,
tokenName: tokenName,
ticker: ticker,
devBuyPrompt: devBuyPrompt // Include devBuyPrompt in the response
});
}).catch(error => {
console.error('Error capturing tweet:', error);
sendResponse({ success: false, message: 'Failed to capture the tweet.' });
});
} else {
console.error('Failed to find the tweet content.');
sendResponse({ success: false, message: 'Failed to fetch the tweet content.' });
}
// Indicate that we will send a response asynchronously
return true;
}
});
} else {
console.error('html2canvas is not loaded correctly.');
}
chrome.runtime.onInstalled.addListener(() => {
console.log("Extension installed");
});
chrome.action.onClicked.addListener((tab) => {
console.log('Injecting content script');
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ['content.js']
});
});