mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-25 13:39:06 +01:00
enhance: read theme color nodeinfo (#8977)
* provide theme color in nodeinfo metadata * read theme color from nodeinfo Prefer to read the theme color from the nodeinfo since it is more performant than performing selector search on a DOM.
This commit is contained in:
parent
a60b0dd757
commit
278b7a70a7
@ -78,6 +78,7 @@ const nodeinfo2 = async () => {
|
|||||||
enableEmail: meta.enableEmail,
|
enableEmail: meta.enableEmail,
|
||||||
enableServiceWorker: meta.enableServiceWorker,
|
enableServiceWorker: meta.enableServiceWorker,
|
||||||
proxyAccountName: proxyAccount ? proxyAccount.username : null,
|
proxyAccountName: proxyAccount ? proxyAccount.username : null,
|
||||||
|
themeColor: meta.themeColor || '#86b300',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -34,7 +34,7 @@ export async function fetchInstanceMetadata(instance: Instance, force = false):
|
|||||||
const [favicon, icon, themeColor, name, description] = await Promise.all([
|
const [favicon, icon, themeColor, name, description] = await Promise.all([
|
||||||
fetchFaviconUrl(instance, dom).catch(() => null),
|
fetchFaviconUrl(instance, dom).catch(() => null),
|
||||||
fetchIconUrl(instance, dom, manifest).catch(() => null),
|
fetchIconUrl(instance, dom, manifest).catch(() => null),
|
||||||
getThemeColor(dom, manifest).catch(() => null),
|
getThemeColor(info, dom, manifest).catch(() => null),
|
||||||
getSiteName(info, dom, manifest).catch(() => null),
|
getSiteName(info, dom, manifest).catch(() => null),
|
||||||
getDescription(info, dom, manifest).catch(() => null),
|
getDescription(info, dom, manifest).catch(() => null),
|
||||||
]);
|
]);
|
||||||
@ -208,8 +208,8 @@ async function fetchIconUrl(instance: Instance, doc: DOMWindow['document'] | nul
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getThemeColor(doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> {
|
async function getThemeColor(info: NodeInfo | null, doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> {
|
||||||
const themeColor = doc?.querySelector('meta[name="theme-color"]')?.getAttribute('content') || manifest?.theme_color;
|
const themeColor = info?.metadata?.themeColor || doc?.querySelector('meta[name="theme-color"]')?.getAttribute('content') || manifest?.theme_color;
|
||||||
|
|
||||||
if (themeColor) {
|
if (themeColor) {
|
||||||
const color = new tinycolor(themeColor);
|
const color = new tinycolor(themeColor);
|
||||||
|
Loading…
Reference in New Issue
Block a user