Added "Font" suggestions

This commit is contained in:
nutty
2026-08-10 01:24:13 +10:00
parent 3cbb047d29
commit 7d2e19179d
2 changed files with 99 additions and 46 deletions
+53
View File
@@ -170,6 +170,24 @@ function LoadJSON(settingsJson) {
inputElement.setAttribute('list', 'streamer-bot-actions');
inputElement.autocomplete = 'off';
break;
case 'font':
inputElement = document.createElement('input');
inputElement.type = 'text';
inputElement.placeholder = 'Type to search...';
inputElement.id = setting.id; //Added setting ID
inputElement.value = settingsMap.has(setting.id) ? settingsMap.get(setting.id) : setting.defaultValue;
inputElement.setAttribute('list', 'fonts');
inputElement.autocomplete = 'off';
// Trigger permission prompt and load fonts on first click/focus
inputElement.addEventListener('focus', async function loadOnce() {
// Remove listener so it only triggers once per session
inputElement.removeEventListener('focus', loadOnce);
inputElement.placeholder = 'Type to search...';
await PopulateFontDatalist();
}, { once: true });
break;
case 'button':
inputElement = document.createElement('button');
inputElement.id = setting.id; //Added setting ID
@@ -377,6 +395,38 @@ async function GetSBActions() {
document.body.appendChild(datalistElement);
}
async function PopulateFontDatalist() {
if (!('queryLocalFonts' in window)) {
console.warn("Local Font Access API is not supported in this browser. Font auto-suggestions will be disabled.");
return;
}
try {
// Request permission and fetch local fonts
const availableFonts = await window.queryLocalFonts();
// Extract unique font family names and sort them alphabetically
const fontFamilies = [...new Set(availableFonts.map(font => font.family))].sort();
// Create the datalist element
const datalistElement = document.createElement('datalist');
datalistElement.id = 'fonts';
// Append each font family as an option
fontFamilies.forEach(family => {
const option = document.createElement('option');
option.value = family;
datalistElement.appendChild(option);
});
document.body.appendChild(datalistElement);
console.debug(`Loaded ${fontFamilies.length} local fonts into auto-suggest.`);
} catch (err) {
console.error("Permission denied or error fetching local fonts:", err);
}
}
/////////////////////////
@@ -543,3 +593,6 @@ LoadSettingsFromStorage();
// Load default settings
LoadJSON(settingsJson);
// Populate local fonts for auto-suggest
PopulateFontDatalist();
+5 -5
View File
@@ -20,8 +20,8 @@
{
"id": "line1Font",
"label": "Font",
"description": "",
"type": "text",
"description": "<a href=\"ms-settings:fonts\">Check installed fonts</a>",
"type": "font",
"defaultValue": "",
"showIf": "enableLine1",
"group": "Appearance"
@@ -112,8 +112,8 @@
{
"id": "line2Font",
"label": "Font",
"description": "",
"type": "text",
"description": "<a href=\"ms-settings:fonts\">Check installed PC fonts</a>",
"type": "font",
"defaultValue": "",
"showIf": "enableLine2",
"group": "Appearance"
@@ -204,7 +204,7 @@
{
"id": "line3Font",
"label": "Font",
"description": "",
"description": "<a href=\"ms-settings:fonts\">Check installed PC fonts</a>",
"type": "text",
"defaultValue": "",
"showIf": "enableLine3",