build all

Refactor utility functions for improved readability and consistency

- Updated compatibility.js to use consistent line endings and formatting.
- Refactored component.js for better readability and structure, including consistent use of arrow functions and binding.
- Simplified dom.js functions with consistent formatting and improved readability.
- Enhanced emitter.js with consistent formatting and arrow function usage.
- Streamlined error.js for improved readability and consistency.
- Refactored file.js to use consistent formatting and improved readability.
- Improved format.js functions for better readability and consistency.
- Updated index.js to maintain consistent export formatting.
- Refactored property.js for improved readability and consistency.
- Enhanced subtitle.js with consistent formatting and improved readability.
- Refactored time.js for better readability and consistent formatting.

fix: update lint script to target only source files for consistency

Revert "fix: restore export statements for various plugins and update type definitions for better clarity"

This reverts commit b5e969d81ec765cd8a34b06e6ef4f232ef25087f.

fix: restore export statements for various plugins and update type definitions for better clarity

Refactor type definitions to use interfaces instead of type aliases for better extensibility and clarity across i18n, icons, option, player, quality, setting, subtitle, template, and utils modules.
This commit is contained in:
Harvey Zack committed 2025-08-03 13:17:33 +08:00
1 parent 532dd67cfd
commit 35ad9883af
447 files changed
+18248 -17946

No files matched your search

@@ -1,88 +1,93 @@
function getMode(key) {
switch (key) {
case 1:
case 2:
case 3:
return 0;
case 4:
return 2;
case 5:
return 1;
default:
return 0;
}
switch (key) {
case 1:
case 2:
case 3:
return 0
case 4:
return 2
case 5:
return 1
default:
return 0
}
}
function bilibiliDanmuParseFromXml(xmlString) {
if (typeof xmlString !== 'string') return [];
const reg = new RegExp(/<d (?:.*? )??p="(?<p>.+?)"(?: .*?)?>(?<text>.+?)<\/d>/gs);
const matches = xmlString.matchAll(reg);
return Array.from(matches)
.map((match) => {
const attr = match.groups.p.split(',');
if (attr.length >= 8) {
const text = match.groups.text
.trim()
.replaceAll('&quot;', '"')
.replaceAll('&apos;', "'")
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>')
.replaceAll('&amp;', '&');
if (typeof xmlString !== 'string')
return []
const reg = /<d[^>]*?p="(?<p>[^"]+)"[^>]*>(?<text>.*?)<\/d>/gs
const matches = xmlString.matchAll(reg)
return Array.from(matches)
.map((match) => {
const attr = match.groups.p.split(',')
if (attr.length >= 8) {
const text = match.groups.text
.trim()
.replaceAll('&quot;', '"')
.replaceAll('&apos;', '\'')
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>')
.replaceAll('&amp;', '&')
return {
text,
time: Number(attr[0]),
mode: getMode(Number(attr[1])),
fontSize: Number(attr[2]),
color: `#${Number(attr[3]).toString(16)}`,
timestamp: Number(attr[4]),
pool: Number(attr[5]),
userID: attr[6],
rowID: Number(attr[7]),
};
} else {
return null;
}
})
.filter(Boolean);
return {
text,
time: Number(attr[0]),
mode: getMode(Number(attr[1])),
fontSize: Number(attr[2]),
color: `#${Number(attr[3]).toString(16)}`,
timestamp: Number(attr[4]),
pool: Number(attr[5]),
userID: attr[6],
rowID: Number(attr[7]),
}
}
else {
return null
}
})
.filter(Boolean)
}
function onmessage({ data }) {
const { xml, id } = data;
if (!id || !xml) return;
const danmus = bilibiliDanmuParseFromXml(xml);
self.postMessage({ danmus, id });
const { xml, id } = data
if (!id || !xml)
return
const danmus = bilibiliDanmuParseFromXml(xml)
globalThis.postMessage({ danmus, id })
}
function createWorker() {
const workerText = `
const workerText = `
${getMode.toString()}
${bilibiliDanmuParseFromXml.toString()}
onmessage = ${onmessage.toString()}
`;
const blob = new Blob([workerText], { type: 'application/javascript' });
return new Worker(URL.createObjectURL(blob));
`
const blob = new Blob([workerText], { type: 'application/javascript' })
return new Worker(URL.createObjectURL(blob))
}
export function bilibiliDanmuParseFromUrl(url) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const res = await fetch(url);
const xml = await res.text();
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const res = await fetch(url)
const xml = await res.text()
try {
const worker = createWorker();
worker.onmessage = (event) => {
const { danmus, id } = event.data;
if (!id || !danmus) return;
resolve(danmus);
worker.terminate();
};
worker.postMessage({ xml, id: Date.now() });
// eslint-disable-next-line no-unused-vars
} catch (error) {
const danmus = bilibiliDanmuParseFromXml(xml);
resolve(danmus);
}
});
try {
const worker = createWorker()
worker.onmessage = (event) => {
const { danmus, id } = event.data
if (!id || !danmus)
return
resolve(danmus)
worker.terminate()
}
worker.postMessage({ xml, id: Date.now() })
}
catch (error) {
console.error('Error parsing Bilibili Danmu:', error)
const danmus = bilibiliDanmuParseFromXml(xml)
resolve(danmus)
}
})
}