Repository navigation
Expand file tree
/
Copy pathpopup.js
More file actions
53 lines (51 loc) · 1.94 KB
/
Copy pathpopup.js
File metadata and controls
53 lines (51 loc) · 1.94 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
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
func: () => window.lastFontifyFontInfo
}, (results) => {
if (results && results[0] && results[0].result) {
const fontInfo = results[0].result;
document.getElementById('font-info').textContent = `Font: ${fontInfo.family} | Weight: ${fontInfo.weight} | Style: ${fontInfo.style}`;
const family = sanitizeFontFamily(fontInfo.family);
showFontDownloads(family);
} else {
document.getElementById('font-info').textContent = 'Click on any text to get font info.';
document.getElementById('font-downloads').innerHTML = '';
}
});
});
function sanitizeFontFamily(family) {
// Remove quotes and extra fallbacks
return family.split(',')[0].replace(/['"]/g, '').trim();
}
function showFontDownloads(family) {
const downloadsDiv = document.getElementById('font-downloads');
const sources = [
{
name: 'Google Fonts',
url: `https://fonts.google.com/specimen/${encodeURIComponent(family)}`
},
{
name: 'Adobe Fonts',
url: `https://fonts.adobe.com/search?query=${encodeURIComponent(family)}`
},
{
name: 'DaFont',
url: `https://www.dafont.com/search.php?q=${encodeURIComponent(family)}`
},
{
name: 'CufonFonts',
url: `https://www.cufonfonts.com/search?query=${encodeURIComponent(family)}`
},
{
name: 'Fontesk',
url: `https://fontesk.com/?s=${encodeURIComponent(family)}`
}
];
downloadsDiv.innerHTML =
'<div style="font-weight:bold;margin-bottom:8px;">Download this font family from trusted sources:</div>' +
'<ul style="padding-left:18px;">' +
sources.map(src => `<li><a href="${src.url}" target="_blank">${src.name}</a></li>`).join('') +
'</ul>' +
'<div style="font-size:12px;color:#888;margin-top:8px;">If the font is not available on one source, try the others.</div>';
}