Spaces:
Running
Running
Ryan Christian D. Deniega commited on
Commit Β·
ad25f0b
1
Parent(s): 7a99ea1
fix(extension): block social URLs in popup, show paste-text hint
Browse files- extension/popup.js +28 -2
extension/popup.js
CHANGED
|
@@ -50,6 +50,13 @@ function isUrl(s) {
|
|
| 50 |
try { new URL(s); return s.startsWith('http'); } catch { return false }
|
| 51 |
}
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
// ββ Render helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 54 |
|
| 55 |
function renderResult(result, container) {
|
|
@@ -135,12 +142,16 @@ const currentUrlEl = document.getElementById('current-url')
|
|
| 135 |
// Auto-populate input with current tab URL if it's a news article
|
| 136 |
chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => {
|
| 137 |
const url = tab?.url ?? ''
|
| 138 |
-
if (url && !url.startsWith('chrome') && !
|
| 139 |
currentUrlEl.textContent = url
|
| 140 |
currentUrlEl.title = url
|
| 141 |
verifyInput.value = url
|
| 142 |
} else {
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
}
|
| 145 |
})
|
| 146 |
|
|
@@ -156,6 +167,21 @@ btnVerify.addEventListener('click', async () => {
|
|
| 156 |
<div class="spinner" aria-hidden="true"></div><br>Analyzing claimβ¦
|
| 157 |
</div>`
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
const type = isUrl(raw) ? 'VERIFY_URL' : 'VERIFY_TEXT'
|
| 160 |
const payload = type === 'VERIFY_URL' ? { type, url: raw } : { type, text: raw }
|
| 161 |
const resp = await msg(payload)
|
|
|
|
| 50 |
try { new URL(s); return s.startsWith('http'); } catch { return false }
|
| 51 |
}
|
| 52 |
|
| 53 |
+
function isSocialUrl(s) {
|
| 54 |
+
try {
|
| 55 |
+
const h = new URL(s).hostname
|
| 56 |
+
return h.includes('facebook.com') || h.includes('x.com') || h.includes('twitter.com')
|
| 57 |
+
} catch { return false }
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
// ββ Render helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 61 |
|
| 62 |
function renderResult(result, container) {
|
|
|
|
| 142 |
// Auto-populate input with current tab URL if it's a news article
|
| 143 |
chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => {
|
| 144 |
const url = tab?.url ?? ''
|
| 145 |
+
if (url && !url.startsWith('chrome') && !isSocialUrl(url)) {
|
| 146 |
currentUrlEl.textContent = url
|
| 147 |
currentUrlEl.title = url
|
| 148 |
verifyInput.value = url
|
| 149 |
} else {
|
| 150 |
+
const h = (() => { try { return new URL(url).hostname } catch { return '' } })()
|
| 151 |
+
const site = h.includes('x.com') || h.includes('twitter.com') ? 'x.com / twitter.com'
|
| 152 |
+
: h.includes('facebook.com') ? 'facebook.com'
|
| 153 |
+
: 'social media'
|
| 154 |
+
currentUrlEl.textContent = `${site} β paste post text below`
|
| 155 |
}
|
| 156 |
})
|
| 157 |
|
|
|
|
| 167 |
<div class="spinner" aria-hidden="true"></div><br>Analyzing claimβ¦
|
| 168 |
</div>`
|
| 169 |
|
| 170 |
+
// Block social media URLs β backend can't scrape them
|
| 171 |
+
if (isSocialUrl(raw)) {
|
| 172 |
+
btnVerify.disabled = false
|
| 173 |
+
btnVerify.setAttribute('aria-busy', 'false')
|
| 174 |
+
btnVerify.textContent = 'Verify Claim'
|
| 175 |
+
verifyResult.innerHTML = `
|
| 176 |
+
<div class="state-error" role="alert">
|
| 177 |
+
Facebook, X, and Twitter URLs can't be scraped by the backend.<br>
|
| 178 |
+
<span style="font-size:10px;color:var(--text-muted)">
|
| 179 |
+
Paste the post's text/caption directly instead, or let the extension auto-scan your feed.
|
| 180 |
+
</span>
|
| 181 |
+
</div>`
|
| 182 |
+
return
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
const type = isUrl(raw) ? 'VERIFY_URL' : 'VERIFY_TEXT'
|
| 186 |
const payload = type === 'VERIFY_URL' ? { type, url: raw } : { type, text: raw }
|
| 187 |
const resp = await msg(payload)
|