The Facts tab retrieves structured data from Wikidata to display quick reference information about people, places, organizations, and other entities in an organized table format.
How It Works
Entity Search
The extension searches Wikidata’s entity database using the selected term to find the closest matching entity.
Retrieve Entity ID
Wikidata returns an entity ID (e.g., Q5373) that uniquely identifies the subject.
Fetch Entity Data
Using the entity ID, the extension fetches complete structured data including all properties and values.
Parse and Display
The extension extracts relevant properties (birth date, occupation, etc.) and displays them in a readable table.
API Endpoints Used
The Facts tab uses two Wikidata API endpoints:
1. Entity Search
// From background.js:141-159
`https://www.wikidata.org/w/api.php?action=wbsearchentities&search={term}&language={lang}&limit=1&format=json&origin=*`
This returns the entity ID and basic information.
2. Entity Data Fetch
// From background.js:161-177
`https://www.wikidata.org/wiki/Special:EntityData/{entityId}.json`
This returns the complete entity data with all properties, claims, and values.
Wikidata is Wikipedia’s structured knowledge base containing millions of entities with machine-readable facts.
Code Implementation
From content.js:743-795, the two-step fetch process:
async function fetchFactsData ( term ) {
// Step 1: Search for entity
const searchResponse = await chrome . runtime . sendMessage ({
action: 'searchWikidata' ,
term: term ,
language: currentLanguage
});
const entityId = searchResponse . data . id ;
// Step 2: Fetch entity details
const entityResponse = await chrome . runtime . sendMessage ({
action: 'fetchWikidataEntity' ,
entityId: entityId ,
language: currentLanguage
});
const factsData = entityResponse . data ;
setCache ( term , 'facts' , factsData );
renderFactsContent ( factsData , contentArea );
}
Property Mapping
Wikidata uses property IDs (P31, P569, etc.) that need to be translated to human-readable labels. The extension maps 30+ common properties:
// From background.js:190-220
const propertyMap = {
P31: language === 'ar' ? 'النوع' : 'Instance of' ,
P569: language === 'ar' ? 'تاريخ الميلاد' : 'Born' ,
P570: language === 'ar' ? 'تاريخ الوفاة' : 'Died' ,
P27: language === 'ar' ? 'الجنسية' : 'Country' ,
P106: language === 'ar' ? 'المهنة' : 'Occupation' ,
P800: language === 'ar' ? 'أعمال بارزة' : 'Notable work' ,
P17: language === 'ar' ? 'البلد' : 'Country' ,
P1082: language === 'ar' ? 'عدد السكان' : 'Population' ,
P625: language === 'ar' ? 'الإحداثيات' : 'Coordinates' ,
P36: language === 'ar' ? 'العاصمة' : 'Capital' ,
P571: language === 'ar' ? 'تاريخ التأسيس' : 'Founded' ,
P112: language === 'ar' ? 'المؤسس' : 'Founded by' ,
P159: language === 'ar' ? 'المقر' : 'Headquarters' ,
P169: language === 'ar' ? 'الرئيس التنفيذي' : 'CEO' ,
P856: language === 'ar' ? 'الموقع الرسمي' : 'Website' ,
P166: language === 'ar' ? 'جوائز' : 'Awards' ,
// ... and 15+ more properties
};
What Users See
The Facts tab displays:
Label : The entity’s official name from Wikidata
Description : A brief description (e.g., “American author and entrepreneur”)
2. Facts Table
A two-column table with property labels and values:
Property Value Born January 15, 1929 Died April 4, 1968 Country United States of America Occupation Civil rights activist, Baptist minister
// Table rendering from content.js:797-842
function renderFactsContent ( data , contentArea ) {
// Title
const title = document . createElement ( 'h3' );
title . textContent = data . label ;
// Description
if ( data . description ) {
const desc = document . createElement ( 'p' );
desc . textContent = data . description ;
}
// Facts table
const table = document . createElement ( 'table' );
for ( const fact of data . facts ) {
const tr = document . createElement ( 'tr' );
const tdLabel = document . createElement ( 'td' );
tdLabel . textContent = fact . label ;
const tdValue = document . createElement ( 'td' );
tdValue . textContent = fact . value ;
tr . appendChild ( tdLabel );
tr . appendChild ( tdValue );
table . appendChild ( tr );
}
}
The extension displays up to 3 values per property when multiple values exist (e.g., multiple occupations or awards).
Data Type Handling
Wikidata values come in different types that require special parsing:
// From background.js:307-358
function extractWikidataValue ( snak , langCode , entity ) {
switch ( datavalue . type ) {
case 'time' :
// Parse +YYYY-MM-DDT00:00:00Z format
const date = new Date ( year , month - 1 , day );
return date . toLocaleDateString ( langCode , options );
case 'quantity' :
// Format numbers with locale-aware separators
const amount = parseFloat ( datavalue . value . amount );
return amount . toLocaleString ( langCode );
case 'globecoordinate' :
// Format GPS coordinates
const lat = datavalue . value . latitude . toFixed ( 4 );
const lon = datavalue . value . longitude . toFixed ( 4 );
return ` ${ lat } , ${ lon } ` ;
case 'wikibase-entityid' :
// Return entity ID (linking not yet implemented)
return datavalue . value . id ;
case 'string' :
case 'monolingualtext' :
// Return text as-is
return datavalue . value ;
}
}
Full dates : “January 15, 1929” (English) or “15 يناير 1929” (Arabic)
Year only : “1929” when month/day are 0
Locale-aware : Uses toLocaleDateString() for proper formatting
Population : “331,893,745” (English) or “٣٣١٬٨٩٣٬٧٤٥” (Arabic)
Area : Uses locale-specific thousand separators
Formatted as decimal degrees with 4 decimal places: “40.7128, -74.0060”
Entity Types Supported
The Facts tab works best for:
People : birth/death dates, nationality, occupation, education, awards
Places : country, population, area, capital, coordinates, timezone
Organizations : founded date, founder, headquarters, CEO, industry, website
Creative Works : author, genre, country of origin, original language
The property mapping prioritizes the most commonly useful properties for each entity type.
Language Support
The Facts tab fully supports bilingual display:
Property labels : Translated to English or Arabic
Entity labels : Retrieved in the requested language with fallback
Descriptions : Retrieved in the requested language with fallback
Values : Formatted according to locale (dates, numbers)
// From background.js:178-184
const langCode = language === 'ar' ? 'ar' : 'en' ;
const fallbackLang = langCode === 'ar' ? 'en' : 'ar' ;
const label = entity . labels ?.[ langCode ]?. value
|| entity . labels ?.[ fallbackLang ]?. value
|| entityId ;
Error Handling
Displays: “No quick facts available for [term].” when Wikidata has no matching entity.
Displays: “No quick facts available.” when the entity exists but has none of the mapped properties.
Displays: “Unable to fetch facts. Please try again.” for network or API errors.
The Facts tab requires two sequential API calls (search + fetch), making it slightly slower than other tabs. Results are cached to improve subsequent lookups.
Data Source
Wikidata : Free, no authentication required