Ryan Christian D. Deniega commited on
Commit
6911f3f
Β·
1 Parent(s): b1c84b5

feat(extension): production API URL, PH news site support, article auto-verify

Browse files

- background.js: default apiBase β†’ https://philverify.web.app/api
- manifest.json: fix host_permissions (add philverify.web.app, remove dead api.philverify.com)
- manifest.json: expand content_scripts to 14 Philippine news sites
(Rappler, Inquirer, GMA, PhilStar, Manila Times, MB, ABS-CBN, PNA, bworld, Interaksyon)
- content.js: fix 'Open full analysis' link localhost β†’ https://philverify.web.app
- content.js: add autoVerifyPage() β€” on news article pages, injects a fixed
top banner with verdict, credibility score, and triggered signals; auto-dismisses
after 5s if Credible
- popup.js: fix 'Open Full Dashboard' localhost β†’ https://philverify.web.app
- popup.html: update settings hint to show production URL

extension/background.js CHANGED
@@ -20,7 +20,7 @@ const MAX_HISTORY = 50
20
 
21
  // ── Default settings ──────────────────────────────────────────────────────────
22
  const DEFAULT_SETTINGS = {
23
- apiBase: 'http://localhost:8000',
24
  autoScan: true, // Automatically scan Facebook feed posts
25
  }
26
 
 
20
 
21
  // ── Default settings ──────────────────────────────────────────────────────────
22
  const DEFAULT_SETTINGS = {
23
+ apiBase: 'https://philverify.web.app/api',
24
  autoScan: true, // Automatically scan Facebook feed posts
25
  }
26
 
extension/content.js CHANGED
@@ -220,7 +220,7 @@
220
  ${safeText(topSource.title?.slice(0, 60) ?? topSource.source_name ?? 'View source')} β†—
221
  </a>
222
  </div>` : ''}
223
- <a href="http://localhost:5173" target="_blank" rel="noreferrer" class="pv-open-full">
224
  Open full analysis β†—
225
  </a>
226
  `
@@ -373,7 +373,108 @@
373
 
374
  init()
375
 
376
- // React to autoScan toggle without requiring page reload
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
  chrome.storage.onChanged.addListener((changes, area) => {
378
  if (area !== 'local' || !changes.settings) return
379
  const autoScan = changes.settings.newValue?.autoScan
 
220
  ${safeText(topSource.title?.slice(0, 60) ?? topSource.source_name ?? 'View source')} β†—
221
  </a>
222
  </div>` : ''}
223
+ <a href="https://philverify.web.app" target="_blank" rel="noreferrer" class="pv-open-full">
224
  Open full analysis β†—
225
  </a>
226
  `
 
373
 
374
  init()
375
 
376
+ // ── Auto-verify news article pages (non-Facebook) ─────────────────────────
377
+ // When the content script runs on a PH news site (not the homepage),
378
+ // it auto-verifies the current URL and injects a floating verdict banner.
379
+
380
+ const IS_FACEBOOK = window.location.hostname.includes('facebook.com')
381
+
382
+ async function autoVerifyPage() {
383
+ const url = window.location.href
384
+ const path = new URL(url).pathname
385
+ // Skip homepages and section indexes (very short paths like / or /news)
386
+ if (!path || path.length < 8 || path.split('/').filter(Boolean).length < 2) return
387
+
388
+ const banner = document.createElement('div')
389
+ banner.id = 'pv-auto-banner'
390
+ banner.setAttribute('role', 'status')
391
+ banner.setAttribute('aria-live', 'polite')
392
+ banner.style.cssText = [
393
+ 'position:fixed;top:0;left:0;right:0;z-index:2147483647',
394
+ 'background:#141414;border-bottom:2px solid rgba(220,38,38,0.4)',
395
+ 'padding:7px 16px;display:flex;align-items:center;justify-content:space-between;gap:12px',
396
+ 'font-family:system-ui,sans-serif;font-size:11px;color:#a89f94',
397
+ 'box-shadow:0 2px 16px rgba(0,0,0,0.6)',
398
+ ].join(';')
399
+
400
+ banner.innerHTML = `
401
+ <div style="display:flex;align-items:center;gap:8px;min-width:0;overflow:hidden;">
402
+ <span style="font-weight:800;letter-spacing:0.1em;color:#f5f0e8;flex-shrink:0;">
403
+ PHIL<span style="color:#dc2626">VERIFY</span>
404
+ </span>
405
+ <span id="pv-auto-status" style="display:flex;align-items:center;gap:6px;overflow:hidden;">
406
+ <span class="pv-spinner" aria-hidden="true"></span>
407
+ <span style="white-space:nowrap;">Verifying article…</span>
408
+ </span>
409
+ </div>
410
+ <div style="display:flex;align-items:center;gap:8px;flex-shrink:0;">
411
+ <a id="pv-open-full"
412
+ href="https://philverify.web.app"
413
+ target="_blank"
414
+ rel="noreferrer"
415
+ style="color:#dc2626;font-size:9px;font-weight:700;letter-spacing:0.1em;text-decoration:none;border:1px solid rgba(220,38,38,0.35);padding:3px 8px;border-radius:2px;white-space:nowrap;"
416
+ aria-label="Open PhilVerify dashboard">
417
+ FULL ANALYSIS β†—
418
+ </a>
419
+ <button id="pv-close-banner"
420
+ style="background:none;border:none;color:#5c554e;cursor:pointer;font-size:13px;padding:2px 4px;line-height:1;flex-shrink:0;"
421
+ aria-label="Dismiss PhilVerify banner">βœ•</button>
422
+ </div>
423
+ `
424
+
425
+ document.body.insertAdjacentElement('afterbegin', banner)
426
+ // Push page content down so banner doesn't overlap
427
+ document.documentElement.style.marginTop = '36px'
428
+
429
+ document.getElementById('pv-close-banner').addEventListener('click', () => {
430
+ banner.remove()
431
+ document.documentElement.style.marginTop = ''
432
+ })
433
+
434
+ try {
435
+ const response = await new Promise((resolve, reject) => {
436
+ chrome.runtime.sendMessage({ type: 'VERIFY_URL', url }, (resp) => {
437
+ if (chrome.runtime.lastError) reject(new Error(chrome.runtime.lastError.message))
438
+ else if (!resp?.ok) reject(new Error(resp?.error ?? 'Unknown error'))
439
+ else resolve(resp.result)
440
+ })
441
+ })
442
+
443
+ const color = VERDICT_COLORS[response.verdict] ?? '#5c554e'
444
+ const statusEl = document.getElementById('pv-auto-status')
445
+ if (statusEl) {
446
+ statusEl.innerHTML = `
447
+ <span style="width:8px;height:8px;border-radius:50%;background:${color};flex-shrink:0;" aria-hidden="true"></span>
448
+ <span style="color:${color};font-weight:700;">${safeText(response.verdict)}</span>
449
+ <span style="color:#5c554e;margin-left:2px;">${Math.round(response.final_score)}% credibility</span>
450
+ ${response.layer1?.triggered_features?.length
451
+ ? `<span style="color:#5c554e;margin-left:4px;font-size:9px;">Β· ${safeText(response.layer1.triggered_features[0])}</span>`
452
+ : ''}
453
+ `
454
+ }
455
+ banner.style.borderBottomColor = color + '88'
456
+ // Update full-analysis link to deep-link with the URL pre-filled
457
+ const fullLink = document.getElementById('pv-open-full')
458
+ if (fullLink) fullLink.href = `https://philverify.web.app`
459
+
460
+ // Auto-dismiss if credible and user hasn't interacted
461
+ if (response.verdict === 'Credible') {
462
+ setTimeout(() => {
463
+ if (document.contains(banner)) {
464
+ banner.remove()
465
+ document.documentElement.style.marginTop = ''
466
+ }
467
+ }, 5000)
468
+ }
469
+ } catch (_) {
470
+ banner.remove()
471
+ document.documentElement.style.marginTop = ''
472
+ }
473
+ }
474
+
475
+ if (!IS_FACEBOOK) {
476
+ autoVerifyPage()
477
+ }
478
  chrome.storage.onChanged.addListener((changes, area) => {
479
  if (area !== 'local' || !changes.settings) return
480
  const autoScan = changes.settings.newValue?.autoScan
extension/manifest.json CHANGED
@@ -13,8 +13,8 @@
13
  "host_permissions": [
14
  "https://www.facebook.com/*",
15
  "https://facebook.com/*",
16
- "http://localhost:8000/*",
17
- "https://api.philverify.com/*"
18
  ],
19
 
20
  "background": {
@@ -24,7 +24,31 @@
24
 
25
  "content_scripts": [
26
  {
27
- "matches": ["https://www.facebook.com/*", "https://facebook.com/*"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  "js": ["content.js"],
29
  "css": ["content.css"],
30
  "run_at": "document_idle"
 
13
  "host_permissions": [
14
  "https://www.facebook.com/*",
15
  "https://facebook.com/*",
16
+ "https://philverify.web.app/*",
17
+ "http://localhost:8000/*"
18
  ],
19
 
20
  "background": {
 
24
 
25
  "content_scripts": [
26
  {
27
+ "matches": [
28
+ "https://www.facebook.com/*",
29
+ "https://facebook.com/*"
30
+ ],
31
+ "js": ["content.js"],
32
+ "css": ["content.css"],
33
+ "run_at": "document_idle"
34
+ },
35
+ {
36
+ "matches": [
37
+ "https://www.rappler.com/*",
38
+ "https://rappler.com/*",
39
+ "https://www.inquirer.net/*",
40
+ "https://business.inquirer.net/*",
41
+ "https://newsinfo.inquirer.net/*",
42
+ "https://technology.inquirer.net/*",
43
+ "https://www.gmanetwork.com/*",
44
+ "https://www.philstar.com/*",
45
+ "https://www.manilatimes.net/*",
46
+ "https://www.mb.com.ph/*",
47
+ "https://news.abs-cbn.com/*",
48
+ "https://www.pna.gov.ph/*",
49
+ "https://www.bworldonline.com/*",
50
+ "https://interaksyon.philstar.com/*"
51
+ ],
52
  "js": ["content.js"],
53
  "css": ["content.css"],
54
  "run_at": "document_idle"
extension/popup.html CHANGED
@@ -427,7 +427,7 @@
427
  aria-describedby="api-base-hint"
428
  >
429
  <span id="api-base-hint" style="font-size:9px;color:var(--text-muted);">
430
- Default: http://localhost:8000 β€” change for production deployment.
431
  </span>
432
  </div>
433
  <div class="toggle-row">
 
427
  aria-describedby="api-base-hint"
428
  >
429
  <span id="api-base-hint" style="font-size:9px;color:var(--text-muted);">
430
+ Production: https://philverify.web.app/api β€” use http://localhost:8000 for local dev.
431
  </span>
432
  </div>
433
  <div class="toggle-row">
extension/popup.js CHANGED
@@ -78,7 +78,7 @@ function renderResult(result, container) {
78
  <div class="result-label" style="margin-bottom:4px;">Top Source</div>
79
  <a href="${safeUrl(topSource.url)}" target="_blank" rel="noreferrer">${safeText(topSource.title?.slice(0, 55) ?? topSource.source_name ?? 'View')} β†—</a>
80
  </div>` : ''}
81
- <a class="open-full" href="http://localhost:5173" target="_blank" rel="noreferrer">
82
  Open Full Dashboard β†—
83
  </a>
84
  </div>
 
78
  <div class="result-label" style="margin-bottom:4px;">Top Source</div>
79
  <a href="${safeUrl(topSource.url)}" target="_blank" rel="noreferrer">${safeText(topSource.title?.slice(0, 55) ?? topSource.source_name ?? 'View')} β†—</a>
80
  </div>` : ''}
81
+ <a class="open-full" href="https://philverify.web.app" target="_blank" rel="noreferrer">
82
  Open Full Dashboard β†—
83
  </a>
84
  </div>