mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const danmaku_1 = require("./danmaku");
|
|
class XmlDanmaku extends danmaku_1.Danmaku {
|
|
constructor({ content, time, type, fontSize, color, timeStamp, pool, userHash, rowId }) {
|
|
super({ content, time, type, fontSize, color });
|
|
this.timeStamp = parseInt(timeStamp);
|
|
this.pool = parseInt(pool);
|
|
this.userHash = userHash;
|
|
this.rowId = parseInt(rowId);
|
|
this.pDataArray = [time, type, fontSize, color, timeStamp, pool, userHash, rowId];
|
|
}
|
|
text() {
|
|
const pData = this.pDataArray.join(',');
|
|
return `<d p="${pData}">${this.content}</d>`;
|
|
}
|
|
static parse(element) {
|
|
const pData = element.getAttribute('p');
|
|
const [time, type, fontSize, color, timeStamp, pool, userHash, rowId] = pData.split(',');
|
|
const content = element.innerHTML;
|
|
return new XmlDanmaku({ content, time, type, fontSize, color, timeStamp, pool, userHash, rowId });
|
|
}
|
|
}
|
|
exports.XmlDanmaku = XmlDanmaku;
|
|
class XmlDanmakuDocument {
|
|
constructor(xml) {
|
|
this.xml = xml;
|
|
const document = new DOMParser().parseFromString(xml, 'application/xml').documentElement;
|
|
this.danmakus = [...document.querySelectorAll('d[p]')].map(it => XmlDanmaku.parse(it));
|
|
}
|
|
}
|
|
exports.XmlDanmakuDocument = XmlDanmakuDocument;
|