feat: CSP Violation ( 感叹号图标被拦截 )
All checks were successful
Extension Build & Release / build (push) Successful in 48s
All checks were successful
Extension Build & Release / build (push) Successful in 48s
This commit is contained in:
@@ -52,7 +52,14 @@ const extractTweetData = (tweetElement: HTMLElement): TweetData | null => {
|
||||
const authorElement = tweetElement.querySelector('[data-testid="User-Name"]');
|
||||
const linkElement = tweetElement.querySelector('time')?.parentElement as HTMLAnchorElement;
|
||||
|
||||
if (!textElement || !authorElement || !linkElement) return null;
|
||||
if (!textElement || !authorElement || !linkElement) {
|
||||
console.debug('[InsightReply] Missing elements for tweet extraction:', {
|
||||
hasText: !!textElement,
|
||||
hasAuthor: !!authorElement,
|
||||
hasLink: !!linkElement
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
const getStat = (testid: string) => {
|
||||
const el = tweetElement.querySelector(`[data-testid="${testid}"]`);
|
||||
@@ -146,19 +153,40 @@ const injectInsightButton = (tweetElement: HTMLElement) => {
|
||||
btnContainer.style.marginLeft = '12px';
|
||||
btnContainer.style.cursor = 'pointer';
|
||||
|
||||
btnContainer.innerHTML = `
|
||||
<div style="padding: 4px; border-radius: 9999px; transition: background 0.2s;" onmouseover="this.style.background='rgba(139, 92, 246, 0.1)'" onmouseout="this.style.background='transparent'">
|
||||
const innerDiv = document.createElement('div');
|
||||
innerDiv.style.cssText = 'padding: 4px; border-radius: 9999px; transition: background 0.2s;';
|
||||
|
||||
// Use event listeners instead of inline handlers to comply with Content Security Policy
|
||||
innerDiv.addEventListener('mouseover', () => {
|
||||
innerDiv.style.background = 'rgba(139, 92, 246, 0.1)';
|
||||
});
|
||||
innerDiv.addEventListener('mouseout', () => {
|
||||
innerDiv.style.background = 'transparent';
|
||||
});
|
||||
|
||||
innerDiv.innerHTML = `
|
||||
<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor" style="color: #8B5CF6;">
|
||||
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
`;
|
||||
`;
|
||||
btnContainer.appendChild(innerDiv);
|
||||
|
||||
btnContainer.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
console.log('[InsightReply] Insight button clicked');
|
||||
|
||||
const data = extractTweetData(tweetElement);
|
||||
if (data) {
|
||||
chrome.runtime.sendMessage({ type: 'SHOW_INSIGHT', payload: data });
|
||||
console.log('[InsightReply] Extracted Tweet Data:', data);
|
||||
chrome.runtime.sendMessage({ type: 'SHOW_INSIGHT', payload: data }, (response) => {
|
||||
console.log('[InsightReply] Background script responsed SHOW_INSIGHT with:', response);
|
||||
if (chrome.runtime.lastError) {
|
||||
console.error('[InsightReply] Error sending SHOW_INSIGHT message:', chrome.runtime.lastError);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.warn('[InsightReply] Failed to extract tweet data on click');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user