// ==UserScript==
// @name Return YouTube Comment Username
// @name:ja YouTubeコメント欄の名前を元に戻す
// @name:zh-CN 恢復 YouTube 评论用户名
// @name:zh-TW 恢復 YouTube 評論名稱
// @version 0.3.7
// @author yakisova41
// @license MIT
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAADL1JREFUeJztnXtsVFUexz93mAJtsFChtTy1UgRBqlhqgqihPggBCbtmfbCuCoi7fxglRhYwyvpK3OAbHzHiYmQTVoEFdtWIPFUUUXC7vJt1eSlQYctTKGVaOr/942x3pnPvPO+r7ZxPcpLOnDPn/ub+vvM7555XDREhbQzDAAYDlcAtwBXpV+I4Apz02wiPOQ2sB9YBXyPSmG4FRsoCMIwgMBq4B7gZ6JHuxTSu8jOwGlgK/DVVMSQXgHL8b4EngJ72bNR4xA/ADEQWJyuYWACG0Q/4CzDSMdM0XvIxcB8ix+MViC8Aw7gcWIv+1bd19gO/QGSrVaa1AAxjMMr5xW5apvGMk8B4RL6KzQiYihrGEFSvUju//dANWIlh3Bib0TICGMZFQBXQyzPTNF7yH+BKRA43vxGJAIbRAdXh085vvxQB86PfiG4CHgVMIULT7hiLYdzT/EI1AYZxIbAX6OqfXRoPOQqUIHKmOQJMRjs/m+gB3AeRJmCyf7ZofOLXAIZAKfBvn43ReE8Y6BUAxvtticYXAsCIAHqcP5u5JgD089sKjW8M1gLIbgYYohYSXOC3JRpfqA8AOX5bofGNTgEg6LcVGv8IAh38NkITQ0EBXHQRnDoFR45AOOzapQKA4VrtmtQZORLmz4faWjh+HKqroaYG6uthxQqYNAmCLgRrAdHJx1RUJLJsmaREdbXIDTc4ef0mLQA/0+DBIvv2peb8ZkIhkUmTHBOAISDOxxVNUrp3h02b4NJL0/9sOAwTJsDHH9u1IqwF4BcffQS33pr550+ehMsuU32GzAmbF4Vq3Of66+05H6BbN3j8cdumOB8BhgyBUaOgvBz694fiYsjNhcZGCIVg3z7YsQPWr4e1a+HcOUcv3yZYtAjuuMN+PWfOQGGhnXsYdqYTmJ8vMn26yM6d6XVojh8XeeUVkd69/e+QeZVyckROnkzvPiVizBhbnUB7AsjJEZkxw/4XOntW5LHHRIJB/x3kdiotdcbxzcyYYUsAmfcBBg2C776DOXOgq83lhLm58NxzsGoV9Gjnm46LHd5v09Pezr3MhpZuuQWWLYMuXeKXqauDXbvUUGZtrRrFKipSwrn4YuvPVFbCunVw441w9GhGprV6zp93tr7GtI8EaEnaYWPMGJFz56zDUUODyLvviowbJ9K5c/w6hg4Vef55FfqtWLVKJBDwP1y7kS6+2Nkm4JFHbDUB6Qlg2DCR06etDVm6VGTAgPQM6NtXZO1a6/qefNJ/Z7mRAgGRmhrnBHDttR4JoEsXke+/NxsQDqsngEyN6NhRZMkSc73nz4sMHOi+Q/Lz1XfzUgTz5jnj/CNHRDp08EgAL79sbcS991qXv/BCkUGDlIOT1Z2bK7J9u7nu995z3xlDhohs2yZSUuKdAAYOFGlstC+AWbPs2pKiAAYOVO17LHPntiyXkyMydarI7t2RMg0NIm++KdKtm6pn9WpzKigQKS8319/YqNpMN50xdKi61tGjIjfd5J0I3nrLnvP37hXJy/NIAPPnmw3Yvr3lr7tbN5HPPotvcFWVihaxhEKRDt+aNeb8adPcdURZWeRajY0iM2d6I4DOnUW+/TZtv4uI6jyXlzthRwoCKCiw7vXfdVfLL1NVldxwqwGj3bsj9UyaZM5fudJdR1x1lfma8+al1nTZTYWFIl9+mfy+RVNb6+SagBQEcP/91k6L7nzMmZPel4hmzZpIPSUl5vz6encfCYcNs7ZrwwaR4mL3RdCpk8izz4rU1SW/V8uXi1xyiZPXT0EAixebDXnhhUj+oEGqxx5LOKzaubFjRZ5+2rqMiGpeoq9nNTZQVOSeA66+Ov4NP3hQpKLCfRGASK9eIo8+qprRmhqRpiaREydEtm4VefFFkWuuceO6KQjg4EHzjYmegHjpJeub98wzLet5/XXrcrNntyz344/mMmVl7t344cPjC0BERaB4TzptPyWZC8jPh969ze9v2BD5e/Roc/5PP6mx/WhWrrS+xv79LV+HQuYyubkJzbSFkWRNbOfOsGABzJ0LHdrfAurEcwFWY/Z1dXD6dOR1//7mMsuWmeeooz8TzQ8/tHydn28uc+JEQjNtEUhxPuzhh9UKnIkT1WocJwkGoawMKirUeoqCAjXBdvasWhq+Z4+aeNu8Of59zPTSCXOtnBE9SZOfb/3r3LbN/F68WbDoCBAMqpUusRyPc9Dl0aPQqZN1Xqqk86seM0at45swQS3btkt5OUyerBaHFBYmLx8KqSXiCxfC8uXQ1GTfhoRtxKhR5jZxx45Ifv/+1u3m3Xeb67Ia+GhoaPk0YdUhO3xYxDCs7QuFErffbnHqlMj48Zm3vWVlIh9+aM+G6mr1KB7v3jjSB6irM7+Xlxf5O1446hVz0lxRkQqdsRw61FLFY8eay6xfr0xtTeTnq1/gzJnpfS4YVJ/ZvBnG2zyXY9AgeP99+PRT635aqiYlzLVqe4uLVbsZDsOxY2o+Oidmf+nEifDaaypk5eWpkGW1aKRjx8jfPXqodjaWREufZ82yv1uma1cYNsw6b/dutTsnEZdfnlpz0L27Wgk8YkT6NiZi9GjYulU1S9Gd81RJGCKCQeswW1oaKWM1fNscohYutH6MbCYcFrnzTjWluWmTOf/QIW9G5NxOffuK7NqVWahPlbNnM2mWUhgH2LrVfLGpUyP5U6akbqTVdHIiJk/233l2U36+9UynG4RCIpWVDgvAaqBn7dpIfiAgsnFjcuMWLVLGpcqCBf47z27q0EHNZXhJbW06U9spCMDqSSAcbjlEWlgYf2arqUnknXfUmHc8QcXy6qt2Fzq0jjRtmj1nZsrnn6f6dJCCAAzDuv2qqlILOZrL5eSo9nzJEpHNm9WY9htviFxxhbnOBx9U7Xs0oZD6tYwc6b/jnEj9+sVfPucF0c20LQGA9TStiJqdav5lp5uCQfU8fPPNajze62VZbqe33/bW4bEcOJCKb1IUgGGo6VErNmxIfzFocyosVLOFfjvL6dS7d/yV017ywAMOCQDUqN+xY9YXqq9Xiq+oSD53n5cncttt6hHx3DmRM2dEunb132lOptmzvXV0PDZtSiqA9DaHVlaqgZno0cBYamvVXMD+/WrSJBxWgy09eqhBkwEDzIM306apgaP2wpYtcOWVfluhKC1Vk0nWZLA5dMQItYDSSaqr7Y5pt57Up4+z98YuDz2UMAKkvzdw40Y1dfnJJ7aE2YL8fOjTx7n6/GT4cL8taEl5ecLszDaH1tTAuHFqj+C6dUpL6dLUBF98AVOmQEkJHDiQkSmtjtYS+puJN8/xP+zNpKxZo1LPnmp2q6IChg6Ffv3UxtELLlAzimfOqJnDPXvUxMWWLbB6dfvcAGpjZs4VEu8eNvQZQU6zeDHcfrvfVkQ4f17NulpH6QYtAKe57rrIr66hwXpNhZOIJF+iVlUVTwBntACym2P6lLDspiGAjgDZTEhHgOzmQAD178M02ck+3QRkN9u1ALKbrwyBc4DN7TWaNsjPQKHuBGYvHyDSoDuB2cu7kOlsoKatsxaRb0EJQEeA7OI8MK35hX4KyD7mILKz+YUhcAqwOAhA0w75EPglIv+P+joCZA/fAL+Jdj5oAWQLfwNuQsR0oIMWQPvnReBXiJy1ygyiBdBeqQN+h8jCRIV0BGh/hIB5wIBkzgcVAfQ4QNtnP7AR+DuwApGfU/2gF03AR0AGh9dogK6YR2tPoSZyDgM/ATsROZXpBQyBI0BRxiYm5iRQisgxl+rX2MTtoeBntfNbN4ZADWDvn89ZsxcYjIjF4b+a1oKbTwEztPNbP24JYCOwzIV6NQ7jhgAEmI5ksmVY4zVudAI/QORrh+vUuITTEaABmO1gfRqXcVoAryAS90AaTevDEPW4VuJAXbWo8eeMR6U03uNkBHhKO7/t4VQn8F/AOw7Uo/EYpyLAdEQaHahH4zFOCOBzRBL8Ww9Na8auAMLAdIds0fiAXQH8GZF/OGWMxnvsCKAe+IODtmh8wM5TwAuItJPjPbOXTCPAEdRyY00bJ1MBPG61yUDT9shEANuA95w3ReMHmQjg94g48F+LNa2BdDuBKxBZ5ZYxGu9JJwI0ATNctEXjA+lEgD8hssNNYzTek+oZQaeBp1y0Q+MTqTYBf0TksNvGaLwnlSbgIDDXA1s0PpBKBJgV73ABTdsnmQD+CbzvkS0aH0gmgOmxhwpp2heJBLAckXVeGqPxnnidwEZglse2aHwgXgR4C5HvvTZG4z1WAjgJPOODLRofsBKAPtUji4gVwD7gTZ9s0fhAbCdQn+qRZURHgG+ApT7aovGBZgHoUz2ylGYBLEJEH+aYhQRQZ8s+4bchGn8wBCoR+cxvQzT+8F/HY9h040De8wAAAABJRU5ErkJggg==
// @namespace https://yt-returnname-api.pages.dev/extension/
// @description This script replaces the "handle" in the YouTube comments section to user name
// @description:ja YouTubeのコメント欄の名前をハンドル(@...)からユーザー名に書き換えます。
// @description:zh-TW 此腳本將 YouTube 評論部分中的“handle”替換為用戶名
// @description:zh-CN 此脚本将 YouTube 评论部分中的“handle”替换为用户名
// @match https://www.youtube.com/*
// @grant unsafeWindow
// @run-at document-end
// ==/UserScript==
const inject = ()=>{var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
// node_modules/fast-xml-parser/src/util.js
var require_util = __commonJS({
"node_modules/fast-xml-parser/src/util.js"(exports2) {
"use strict";
var nameStartChar = ":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
var nameChar = nameStartChar + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
var nameRegexp = "[" + nameStartChar + "][" + nameChar + "]*";
var regexName = new RegExp("^" + nameRegexp + "$");
var getAllMatches = function(string, regex) {
const matches = [];
let match = regex.exec(string);
while (match) {
const allmatches = [];
allmatches.startIndex = regex.lastIndex - match[0].length;
const len = match.length;
for (let index = 0; index < len; index++) {
allmatches.push(match[index]);
}
matches.push(allmatches);
match = regex.exec(string);
}
return matches;
};
var isName = function(string) {
const match = regexName.exec(string);
return !(match === null || typeof match === "undefined");
};
exports2.isExist = function(v) {
return typeof v !== "undefined";
};
exports2.isEmptyObject = function(obj) {
return Object.keys(obj).length === 0;
};
exports2.merge = function(target, a, arrayMode) {
if (a) {
const keys = Object.keys(a);
const len = keys.length;
for (let i = 0; i < len; i++) {
if (arrayMode === "strict") {
target[keys[i]] = [a[keys[i]]];
} else {
target[keys[i]] = a[keys[i]];
}
}
}
};
exports2.getValue = function(v) {
if (exports2.isExist(v)) {
return v;
} else {
return "";
}
};
exports2.isName = isName;
exports2.getAllMatches = getAllMatches;
exports2.nameRegexp = nameRegexp;
}
});
// node_modules/fast-xml-parser/src/validator.js
var require_validator = __commonJS({
"node_modules/fast-xml-parser/src/validator.js"(exports2) {
"use strict";
var util = require_util();
var defaultOptions = {
allowBooleanAttributes: false,
//A tag can have attributes without any value
unpairedTags: []
};
exports2.validate = function(xmlData, options) {
options = Object.assign({}, defaultOptions, options);
const tags = [];
let tagFound = false;
let reachedRoot = false;
if (xmlData[0] === "\uFEFF") {
xmlData = xmlData.substr(1);
}
for (let i = 0; i < xmlData.length; i++) {
if (xmlData[i] === "<" && xmlData[i + 1] === "?") {
i += 2;
i = readPI(xmlData, i);
if (i.err)
return i;
} else if (xmlData[i] === "<") {
let tagStartPos = i;
i++;
if (xmlData[i] === "!") {
i = readCommentAndCDATA(xmlData, i);
continue;
} else {
let closingTag = false;
if (xmlData[i] === "/") {
closingTag = true;
i++;
}
let tagName = "";
for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== "\n" && xmlData[i] !== "\r"; i++) {
tagName += xmlData[i];
}
tagName = tagName.trim();
if (tagName[tagName.length - 1] === "/") {
tagName = tagName.substring(0, tagName.length - 1);
i--;
}
if (!validateTagName(tagName)) {
let msg;
if (tagName.trim().length === 0) {
msg = "Invalid space after '<'.";
} else {
msg = "Tag '" + tagName + "' is an invalid name.";
}
return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i));
}
const result = readAttributeStr(xmlData, i);
if (result === false) {
return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
}
let attrStr = result.value;
i = result.index;
if (attrStr[attrStr.length - 1] === "/") {
const attrStrStart = i - attrStr.length;
attrStr = attrStr.substring(0, attrStr.length - 1);
const isValid = validateAttributeString(attrStr, options);
if (isValid === true) {
tagFound = true;
} else {
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
}
} else if (closingTag) {
if (!result.tagClosed) {
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
} else if (attrStr.trim().length > 0) {
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
} else {
const otg = tags.pop();
if (tagName !== otg.tagName) {
let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
return getErrorObject(
"InvalidTag",
"Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.",
getLineNumberForPosition(xmlData, tagStartPos)
);
}
if (tags.length == 0) {
reachedRoot = true;
}
}
} else {
const isValid = validateAttributeString(attrStr, options);
if (isValid !== true) {
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
}
if (reachedRoot === true) {
return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i));
} else if (options.unpairedTags.indexOf(tagName) !== -1) {
} else {
tags.push({ tagName, tagStartPos });
}
tagFound = true;
}
for (i++; i < xmlData.length; i++) {
if (xmlData[i] === "<") {
if (xmlData[i + 1] === "!") {
i++;
i = readCommentAndCDATA(xmlData, i);
continue;
} else if (xmlData[i + 1] === "?") {
i = readPI(xmlData, ++i);
if (i.err)
return i;
} else {
break;
}
} else if (xmlData[i] === "&") {
const afterAmp = validateAmpersand(xmlData, i);
if (afterAmp == -1)
return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
i = afterAmp;
} else {
if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i));
}
}
}
if (xmlData[i] === "<") {
i--;
}
}
} else {
if (isWhiteSpace(xmlData[i])) {
continue;
}
return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
}
}
if (!tagFound) {
return getErrorObject("InvalidXml", "Start tag expected.", 1);
} else if (tags.length == 1) {
return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
} else if (tags.length > 0) {
return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
}
return true;
};
function isWhiteSpace(char) {
return char === " " || char === " " || char === "\n" || char === "\r";
}
function readPI(xmlData, i) {
const start = i;
for (; i < xmlData.length; i++) {
if (xmlData[i] == "?" || xmlData[i] == " ") {
const tagname = xmlData.substr(start, i - start);
if (i > 5 && tagname === "xml") {
return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i));
} else if (xmlData[i] == "?" && xmlData[i + 1] == ">") {
i++;
break;
} else {
continue;
}
}
}
return i;
}
function readCommentAndCDATA(xmlData, i) {
if (xmlData.length > i + 5 && xmlData[i + 1] === "-" && xmlData[i + 2] === "-") {
for (i += 3; i < xmlData.length; i++) {
if (xmlData[i] === "-" && xmlData[i + 1] === "-" && xmlData[i + 2] === ">") {
i += 2;
break;
}
}
} else if (xmlData.length > i + 8 && xmlData[i + 1] === "D" && xmlData[i + 2] === "O" && xmlData[i + 3] === "C" && xmlData[i + 4] === "T" && xmlData[i + 5] === "Y" && xmlData[i + 6] === "P" && xmlData[i + 7] === "E") {
let angleBracketsCount = 1;
for (i += 8; i < xmlData.length; i++) {
if (xmlData[i] === "<") {
angleBracketsCount++;
} else if (xmlData[i] === ">") {
angleBracketsCount--;
if (angleBracketsCount === 0) {
break;
}
}
}
} else if (xmlData.length > i + 9 && xmlData[i + 1] === "[" && xmlData[i + 2] === "C" && xmlData[i + 3] === "D" && xmlData[i + 4] === "A" && xmlData[i + 5] === "T" && xmlData[i + 6] === "A" && xmlData[i + 7] === "[") {
for (i += 8; i < xmlData.length; i++) {
if (xmlData[i] === "]" && xmlData[i + 1] === "]" && xmlData[i + 2] === ">") {
i += 2;
break;
}
}
}
return i;
}
var doubleQuote = '"';
var singleQuote = "'";
function readAttributeStr(xmlData, i) {
let attrStr = "";
let startChar = "";
let tagClosed = false;
for (; i < xmlData.length; i++) {
if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
if (startChar === "") {
startChar = xmlData[i];
} else if (startChar !== xmlData[i]) {
} else {
startChar = "";
}
} else if (xmlData[i] === ">") {
if (startChar === "") {
tagClosed = true;
break;
}
}
attrStr += xmlData[i];
}
if (startChar !== "") {
return false;
}
return {
value: attrStr,
index: i,
tagClosed
};
}
var validAttrStrRegxp = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
function validateAttributeString(attrStr, options) {
const matches = util.getAllMatches(attrStr, validAttrStrRegxp);
const attrNames = {};
for (let i = 0; i < matches.length; i++) {
if (matches[i][1].length === 0) {
return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i]));
} else if (matches[i][3] !== void 0 && matches[i][4] === void 0) {
return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i]));
} else if (matches[i][3] === void 0 && !options.allowBooleanAttributes) {
return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
}
const attrName = matches[i][2];
if (!validateAttrName(attrName)) {
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
}
if (!attrNames.hasOwnProperty(attrName)) {
attrNames[attrName] = 1;
} else {
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
}
}
return true;
}
function validateNumberAmpersand(xmlData, i) {
let re = /\d/;
if (xmlData[i] === "x") {
i++;
re = /[\da-fA-F]/;
}
for (; i < xmlData.length; i++) {
if (xmlData[i] === ";")
return i;
if (!xmlData[i].match(re))
break;
}
return -1;
}
function validateAmpersand(xmlData, i) {
i++;
if (xmlData[i] === ";")
return -1;
if (xmlData[i] === "#") {
i++;
return validateNumberAmpersand(xmlData, i);
}
let count = 0;
for (; i < xmlData.length; i++, count++) {
if (xmlData[i].match(/\w/) && count < 20)
continue;
if (xmlData[i] === ";")
break;
return -1;
}
return i;
}
function getErrorObject(code, message, lineNumber) {
return {
err: {
code,
msg: message,
line: lineNumber.line || lineNumber,
col: lineNumber.col
}
};
}
function validateAttrName(attrName) {
return util.isName(attrName);
}
function validateTagName(tagname) {
return util.isName(tagname);
}
function getLineNumberForPosition(xmlData, index) {
const lines = xmlData.substring(0, index).split(/\r?\n/);
return {
line: lines.length,
// column number is last line's length + 1, because column numbering starts at 1:
col: lines[lines.length - 1].length + 1
};
}
function getPositionFromMatch(match) {
return match.startIndex + match[1].length;
}
}
});
// node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js
var require_OptionsBuilder = __commonJS({
"node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js"(exports2) {
var defaultOptions = {
preserveOrder: false,
attributeNamePrefix: "@_",
attributesGroupName: false,
textNodeName: "#text",
ignoreAttributes: true,
removeNSPrefix: false,
// remove NS from tag name or attribute name if true
allowBooleanAttributes: false,
//a tag can have attributes without any value
//ignoreRootElement : false,
parseTagValue: true,
parseAttributeValue: false,
trimValues: true,
//Trim string values of tag and attributes
cdataPropName: false,
numberParseOptions: {
hex: true,
leadingZeros: true,
eNotation: true
},
tagValueProcessor: function(tagName, val2) {
return val2;
},
attributeValueProcessor: function(attrName, val2) {
return val2;
},
stopNodes: [],
//nested tags will not be parsed even for errors
alwaysCreateTextNode: false,
isArray: () => false,
commentPropName: false,
unpairedTags: [],
processEntities: true,
htmlEntities: false,
ignoreDeclaration: false,
ignorePiTags: false,
transformTagName: false,
transformAttributeName: false,
updateTag: function(tagName, jPath, attrs) {
return tagName;
}
// skipEmptyListItem: false
};
var buildOptions = function(options) {
return Object.assign({}, defaultOptions, options);
};
exports2.buildOptions = buildOptions;
exports2.defaultOptions = defaultOptions;
}
});
// node_modules/fast-xml-parser/src/xmlparser/xmlNode.js
var require_xmlNode = __commonJS({
"node_modules/fast-xml-parser/src/xmlparser/xmlNode.js"(exports2, module2) {
"use strict";
var XmlNode = class {
constructor(tagname) {
this.tagname = tagname;
this.child = [];
this[":@"] = {};
}
add(key, val2) {
if (key === "__proto__")
key = "#__proto__";
this.child.push({ [key]: val2 });
}
addChild(node) {
if (node.tagname === "__proto__")
node.tagname = "#__proto__";
if (node[":@"] && Object.keys(node[":@"]).length > 0) {
this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] });
} else {
this.child.push({ [node.tagname]: node.child });
}
}
};
module2.exports = XmlNode;
}
});
// node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js
var require_DocTypeReader = __commonJS({
"node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js"(exports2, module2) {
var util = require_util();
function readDocType(xmlData, i) {
const entities = {};
if (xmlData[i + 3] === "O" && xmlData[i + 4] === "C" && xmlData[i + 5] === "T" && xmlData[i + 6] === "Y" && xmlData[i + 7] === "P" && xmlData[i + 8] === "E") {
i = i + 9;
let angleBracketsCount = 1;
let hasBody = false, comment = false;
let exp = "";
for (; i < xmlData.length; i++) {
if (xmlData[i] === "<" && !comment) {
if (hasBody && isEntity(xmlData, i)) {
i += 7;
[entityName, val, i] = readEntityExp(xmlData, i + 1);
if (val.indexOf("&") === -1)
entities[validateEntityName(entityName)] = {
regx: RegExp(`&${entityName};`, "g"),
val
};
} else if (hasBody && isElement(xmlData, i))
i += 8;
else if (hasBody && isAttlist(xmlData, i))
i += 8;
else if (hasBody && isNotation(xmlData, i))
i += 9;
else if (isComment)
comment = true;
else
throw new Error("Invalid DOCTYPE");
angleBracketsCount++;
exp = "";
} else if (xmlData[i] === ">") {
if (comment) {
if (xmlData[i - 1] === "-" && xmlData[i - 2] === "-") {
comment = false;
angleBracketsCount--;
}
} else {
angleBracketsCount--;
}
if (angleBracketsCount === 0) {
break;
}
} else if (xmlData[i] === "[") {
hasBody = true;
} else {
exp += xmlData[i];
}
}
if (angleBracketsCount !== 0) {
throw new Error(`Unclosed DOCTYPE`);
}
} else {
throw new Error(`Invalid Tag instead of DOCTYPE`);
}
return { entities, i };
}
function readEntityExp(xmlData, i) {
let entityName2 = "";
for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"'); i++) {
entityName2 += xmlData[i];
}
entityName2 = entityName2.trim();
if (entityName2.indexOf(" ") !== -1)
throw new Error("External entites are not supported");
const startChar = xmlData[i++];
let val2 = "";
for (; i < xmlData.length && xmlData[i] !== startChar; i++) {
val2 += xmlData[i];
}
return [entityName2, val2, i];
}
function isComment(xmlData, i) {
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "-" && xmlData[i + 3] === "-")
return true;
return false;
}
function isEntity(xmlData, i) {
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "N" && xmlData[i + 4] === "T" && xmlData[i + 5] === "I" && xmlData[i + 6] === "T" && xmlData[i + 7] === "Y")
return true;
return false;
}
function isElement(xmlData, i) {
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "L" && xmlData[i + 4] === "E" && xmlData[i + 5] === "M" && xmlData[i + 6] === "E" && xmlData[i + 7] === "N" && xmlData[i + 8] === "T")
return true;
return false;
}
function isAttlist(xmlData, i) {
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "A" && xmlData[i + 3] === "T" && xmlData[i + 4] === "T" && xmlData[i + 5] === "L" && xmlData[i + 6] === "I" && xmlData[i + 7] === "S" && xmlData[i + 8] === "T")
return true;
return false;
}
function isNotation(xmlData, i) {
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "N" && xmlData[i + 3] === "O" && xmlData[i + 4] === "T" && xmlData[i + 5] === "A" && xmlData[i + 6] === "T" && xmlData[i + 7] === "I" && xmlData[i + 8] === "O" && xmlData[i + 9] === "N")
return true;
return false;
}
function validateEntityName(name) {
if (util.isName(name))
return name;
else
throw new Error(`Invalid entity name ${name}`);
}
module2.exports = readDocType;
}
});
// node_modules/strnum/strnum.js
var require_strnum = __commonJS({
"node_modules/strnum/strnum.js"(exports2, module2) {
var hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
var numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
if (!Number.parseInt && window.parseInt) {
Number.parseInt = window.parseInt;
}
if (!Number.parseFloat && window.parseFloat) {
Number.parseFloat = window.parseFloat;
}
var consider = {
hex: true,
leadingZeros: true,
decimalPoint: ".",
eNotation: true
//skipLike: /regex/
};
function toNumber(str, options = {}) {
options = Object.assign({}, consider, options);
if (!str || typeof str !== "string")
return str;
let trimmedStr = str.trim();
if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr))
return str;
else if (options.hex && hexRegex.test(trimmedStr)) {
return Number.parseInt(trimmedStr, 16);
} else {
const match = numRegex.exec(trimmedStr);
if (match) {
const sign = match[1];
const leadingZeros = match[2];
let numTrimmedByZeros = trimZeros(match[3]);
const eNotation = match[4] || match[6];
if (!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".")
return str;
else if (!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".")
return str;
else {
const num = Number(trimmedStr);
const numStr = "" + num;
if (numStr.search(/[eE]/) !== -1) {
if (options.eNotation)
return num;
else
return str;
} else if (eNotation) {
if (options.eNotation)
return num;
else
return str;
} else if (trimmedStr.indexOf(".") !== -1) {
if (numStr === "0" && numTrimmedByZeros === "")
return num;
else if (numStr === numTrimmedByZeros)
return num;
else if (sign && numStr === "-" + numTrimmedByZeros)
return num;
else
return str;
}
if (leadingZeros) {
if (numTrimmedByZeros === numStr)
return num;
else if (sign + numTrimmedByZeros === numStr)
return num;
else
return str;
}
if (trimmedStr === numStr)
return num;
else if (trimmedStr === sign + numStr)
return num;
return str;
}
} else {
return str;
}
}
}
function trimZeros(numStr) {
if (numStr && numStr.indexOf(".") !== -1) {
numStr = numStr.replace(/0+$/, "");
if (numStr === ".")
numStr = "0";
else if (numStr[0] === ".")
numStr = "0" + numStr;
else if (numStr[numStr.length - 1] === ".")
numStr = numStr.substr(0, numStr.length - 1);
return numStr;
}
return numStr;
}
module2.exports = toNumber;
}
});
// node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js
var require_OrderedObjParser = __commonJS({
"node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js"(exports2, module2) {
"use strict";
var util = require_util();
var xmlNode = require_xmlNode();
var readDocType = require_DocTypeReader();
var toNumber = require_strnum();
var regx = "<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)".replace(/NAME/g, util.nameRegexp);
var OrderedObjParser = class {
constructor(options) {
this.options = options;
this.currentNode = null;
this.tagsNodeStack = [];
this.docTypeEntities = {};
this.lastEntities = {
"apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
"gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
"lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
"quot": { regex: /&(quot|#34|#x22);/g, val: '"' }
};
this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" };
this.htmlEntities = {
"space": { regex: /&(nbsp|#160);/g, val: " " },
// "lt" : { regex: /&(lt|#60);/g, val: "<" },
// "gt" : { regex: /&(gt|#62);/g, val: ">" },
// "amp" : { regex: /&(amp|#38);/g, val: "&" },
// "quot" : { regex: /&(quot|#34);/g, val: "\"" },
// "apos" : { regex: /&(apos|#39);/g, val: "'" },
"cent": { regex: /&(cent|#162);/g, val: "\xA2" },
"pound": { regex: /&(pound|#163);/g, val: "\xA3" },
"yen": { regex: /&(yen|#165);/g, val: "\xA5" },
"euro": { regex: /&(euro|#8364);/g, val: "\u20AC" },
"copyright": { regex: /&(copy|#169);/g, val: "\xA9" },
"reg": { regex: /&(reg|#174);/g, val: "\xAE" },
"inr": { regex: /&(inr|#8377);/g, val: "\u20B9" }
};
this.addExternalEntities = addExternalEntities;
this.parseXml = parseXml;
this.parseTextData = parseTextData;
this.resolveNameSpace = resolveNameSpace;
this.buildAttributesMap = buildAttributesMap;
this.isItStopNode = isItStopNode;
this.replaceEntitiesValue = replaceEntitiesValue;
this.readStopNodeData = readStopNodeData;
this.saveTextToParentTag = saveTextToParentTag;
this.addChild = addChild;
}
};
function addExternalEntities(externalEntities) {
const entKeys = Object.keys(externalEntities);
for (let i = 0; i < entKeys.length; i++) {
const ent = entKeys[i];
this.lastEntities[ent] = {
regex: new RegExp("&" + ent + ";", "g"),
val: externalEntities[ent]
};
}
}
function parseTextData(val2, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
if (val2 !== void 0) {
if (this.options.trimValues && !dontTrim) {
val2 = val2.trim();
}
if (val2.length > 0) {
if (!escapeEntities)
val2 = this.replaceEntitiesValue(val2);
const newval = this.options.tagValueProcessor(tagName, val2, jPath, hasAttributes, isLeafNode);
if (newval === null || newval === void 0) {
return val2;
} else if (typeof newval !== typeof val2 || newval !== val2) {
return newval;
} else if (this.options.trimValues) {
return parseValue(val2, this.options.parseTagValue, this.options.numberParseOptions);
} else {
const trimmedVal = val2.trim();
if (trimmedVal === val2) {
return parseValue(val2, this.options.parseTagValue, this.options.numberParseOptions);
} else {
return val2;
}
}
}
}
}
function resolveNameSpace(tagname) {
if (this.options.removeNSPrefix) {
const tags = tagname.split(":");
const prefix = tagname.charAt(0) === "/" ? "/" : "";
if (tags[0] === "xmlns") {
return "";
}
if (tags.length === 2) {
tagname = prefix + tags[1];
}
}
return tagname;
}
var attrsRegx = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm");
function buildAttributesMap(attrStr, jPath, tagName) {
if (!this.options.ignoreAttributes && typeof attrStr === "string") {
const matches = util.getAllMatches(attrStr, attrsRegx);
const len = matches.length;
const attrs = {};
for (let i = 0; i < len; i++) {
const attrName = this.resolveNameSpace(matches[i][1]);
let oldVal = matches[i][4];
let aName = this.options.attributeNamePrefix + attrName;
if (attrName.length) {
if (this.options.transformAttributeName) {
aName = this.options.transformAttributeName(aName);
}
if (aName === "__proto__")
aName = "#__proto__";
if (oldVal !== void 0) {
if (this.options.trimValues) {
oldVal = oldVal.trim();
}
oldVal = this.replaceEntitiesValue(oldVal);
const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);
if (newVal === null || newVal === void 0) {
attrs[aName] = oldVal;
} else if (typeof newVal !== typeof oldVal || newVal !== oldVal) {
attrs[aName] = newVal;
} else {
attrs[aName] = parseValue(
oldVal,
this.options.parseAttributeValue,
this.options.numberParseOptions
);
}
} else if (this.options.allowBooleanAttributes) {
attrs[aName] = true;
}
}
}
if (!Object.keys(attrs).length) {
return;
}
if (this.options.attributesGroupName) {
const attrCollection = {};
attrCollection[this.options.attributesGroupName] = attrs;
return attrCollection;
}
return attrs;
}
}
var parseXml = function(xmlData) {
xmlData = xmlData.replace(/\r\n?/g, "\n");
const xmlObj = new xmlNode("!xml");
let currentNode = xmlObj;
let textData = "";
let jPath = "";
for (let i = 0; i < xmlData.length; i++) {
const ch = xmlData[i];
if (ch === "<") {
if (xmlData[i + 1] === "/") {
const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
let tagName = xmlData.substring(i + 2, closeIndex).trim();
if (this.options.removeNSPrefix) {
const colonIndex = tagName.indexOf(":");
if (colonIndex !== -1) {
tagName = tagName.substr(colonIndex + 1);
}
}
if (this.options.transformTagName) {
tagName = this.options.transformTagName(tagName);
}
if (currentNode) {
textData = this.saveTextToParentTag(textData, currentNode, jPath);
}
const lastTagName = jPath.substring(jPath.lastIndexOf(".") + 1);
if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) {
throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
}
let propIndex = 0;
if (lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1) {
propIndex = jPath.lastIndexOf(".", jPath.lastIndexOf(".") - 1);
this.tagsNodeStack.pop();
} else {
propIndex = jPath.lastIndexOf(".");
}
jPath = jPath.substring(0, propIndex);
currentNode = this.tagsNodeStack.pop();
textData = "";
i = closeIndex;
} else if (xmlData[i + 1] === "?") {
let tagData = readTagExp(xmlData, i, false, "?>");
if (!tagData)
throw new Error("Pi Tag is not closed.");
textData = this.saveTextToParentTag(textData, currentNode, jPath);
if (this.options.ignoreDeclaration && tagData.tagName === "?xml" || this.options.ignorePiTags) {
} else {
const childNode = new xmlNode(tagData.tagName);
childNode.add(this.options.textNodeName, "");
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) {
childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
}
this.addChild(currentNode, childNode, jPath);
}
i = tagData.closeIndex + 1;
} else if (xmlData.substr(i + 1, 3) === "!--") {
const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
if (this.options.commentPropName) {
const comment = xmlData.substring(i + 4, endIndex - 2);
textData = this.saveTextToParentTag(textData, currentNode, jPath);
currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]);
}
i = endIndex;
} else if (xmlData.substr(i + 1, 2) === "!D") {
const result = readDocType(xmlData, i);
this.docTypeEntities = result.entities;
i = result.i;
} else if (xmlData.substr(i + 1, 2) === "![") {
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
const tagExp = xmlData.substring(i + 9, closeIndex);
textData = this.saveTextToParentTag(textData, currentNode, jPath);
if (this.options.cdataPropName) {
currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
} else {
let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
if (val2 == void 0)
val2 = "";
currentNode.add(this.options.textNodeName, val2);
}
i = closeIndex + 2;
} else {
let result = readTagExp(xmlData, i, this.options.removeNSPrefix);
let tagName = result.tagName;
let tagExp = result.tagExp;
let attrExpPresent = result.attrExpPresent;
let closeIndex = result.closeIndex;
if (this.options.transformTagName) {
tagName = this.options.transformTagName(tagName);
}
if (currentNode && textData) {
if (currentNode.tagname !== "!xml") {
textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
}
}
const lastTag = currentNode;
if (lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1) {
currentNode = this.tagsNodeStack.pop();
jPath = jPath.substring(0, jPath.lastIndexOf("."));
}
if (tagName !== xmlObj.tagname) {
jPath += jPath ? "." + tagName : tagName;
}
if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
let tagContent = "";
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
i = result.closeIndex;
} else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
i = result.closeIndex;
} else {
const result2 = this.readStopNodeData(xmlData, tagName, closeIndex + 1);
if (!result2)
throw new Error(`Unexpected end of ${tagName}`);
i = result2.i;
tagContent = result2.tagContent;
}
const childNode = new xmlNode(tagName);
if (tagName !== tagExp && attrExpPresent) {
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
}
if (tagContent) {
tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
}
jPath = jPath.substr(0, jPath.lastIndexOf("."));
childNode.add(this.options.textNodeName, tagContent);
this.addChild(currentNode, childNode, jPath);
} else {
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
if (tagName[tagName.length - 1] === "/") {
tagName = tagName.substr(0, tagName.length - 1);
tagExp = tagName;
} else {
tagExp = tagExp.substr(0, tagExp.length - 1);
}
if (this.options.transformTagName) {
tagName = this.options.transformTagName(tagName);
}
const childNode = new xmlNode(tagName);
if (tagName !== tagExp && attrExpPresent) {
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
}
this.addChild(currentNode, childNode, jPath);
jPath = jPath.substr(0, jPath.lastIndexOf("."));
} else {
const childNode = new xmlNode(tagName);
this.tagsNodeStack.push(currentNode);
if (tagName !== tagExp && attrExpPresent) {
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
}
this.addChild(currentNode, childNode, jPath);
currentNode = childNode;
}
textData = "";
i = closeIndex;
}
}
} else {
textData += xmlData[i];
}
}
return xmlObj.child;
};
function addChild(currentNode, childNode, jPath) {
const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"]);
if (result === false) {
} else if (typeof result === "string") {
childNode.tagname = result;
currentNode.addChild(childNode);
} else {
currentNode.addChild(childNode);
}
}
var replaceEntitiesValue = function(val2) {
if (this.options.processEntities) {
for (let entityName2 in this.docTypeEntities) {
const entity = this.docTypeEntities[entityName2];
val2 = val2.replace(entity.regx, entity.val);
}
for (let entityName2 in this.lastEntities) {
const entity = this.lastEntities[entityName2];
val2 = val2.replace(entity.regex, entity.val);
}
if (this.options.htmlEntities) {
for (let entityName2 in this.htmlEntities) {
const entity = this.htmlEntities[entityName2];
val2 = val2.replace(entity.regex, entity.val);
}
}
val2 = val2.replace(this.ampEntity.regex, this.ampEntity.val);
}
return val2;
};
function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
if (textData) {
if (isLeafNode === void 0)
isLeafNode = Object.keys(currentNode.child).length === 0;
textData = this.parseTextData(
textData,
currentNode.tagname,
jPath,
false,
currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false,
isLeafNode
);
if (textData !== void 0 && textData !== "")
currentNode.add(this.options.textNodeName, textData);
textData = "";
}
return textData;
}
function isItStopNode(stopNodes, jPath, currentTagName) {
const allNodesExp = "*." + currentTagName;
for (const stopNodePath in stopNodes) {
const stopNodeExp = stopNodes[stopNodePath];
if (allNodesExp === stopNodeExp || jPath === stopNodeExp)
return true;
}
return false;
}
function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
let attrBoundary;
let tagExp = "";
for (let index = i; index < xmlData.length; index++) {
let ch = xmlData[index];
if (attrBoundary) {
if (ch === attrBoundary)
attrBoundary = "";
} else if (ch === '"' || ch === "'") {
attrBoundary = ch;
} else if (ch === closingChar[0]) {
if (closingChar[1]) {
if (xmlData[index + 1] === closingChar[1]) {
return {
data: tagExp,
index
};
}
} else {
return {
data: tagExp,
index
};
}
} else if (ch === " ") {
ch = " ";
}
tagExp += ch;
}
}
function findClosingIndex(xmlData, str, i, errMsg) {
const closingIndex = xmlData.indexOf(str, i);
if (closingIndex === -1) {
throw new Error(errMsg);
} else {
return closingIndex + str.length - 1;
}
}
function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
const result = tagExpWithClosingIndex(xmlData, i + 1, closingChar);
if (!result)
return;
let tagExp = result.data;
const closeIndex = result.index;
const separatorIndex = tagExp.search(/\s/);
let tagName = tagExp;
let attrExpPresent = true;
if (separatorIndex !== -1) {
tagName = tagExp.substr(0, separatorIndex).replace(/\s\s*$/, "");
tagExp = tagExp.substr(separatorIndex + 1);
}
if (removeNSPrefix) {
const colonIndex = tagName.indexOf(":");
if (colonIndex !== -1) {
tagName = tagName.substr(colonIndex + 1);
attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
}
}
return {
tagName,
tagExp,
closeIndex,
attrExpPresent
};
}
function readStopNodeData(xmlData, tagName, i) {
const startIndex = i;
let openTagCount = 1;
for (; i < xmlData.length; i++) {
if (xmlData[i] === "<") {
if (xmlData[i + 1] === "/") {
const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
let closeTagName = xmlData.substring(i + 2, closeIndex).trim();
if (closeTagName === tagName) {
openTagCount--;
if (openTagCount === 0) {
return {
tagContent: xmlData.substring(startIndex, i),
i: closeIndex
};
}
}
i = closeIndex;
} else if (xmlData[i + 1] === "?") {
const closeIndex = findClosingIndex(xmlData, "?>", i + 1, "StopNode is not closed.");
i = closeIndex;
} else if (xmlData.substr(i + 1, 3) === "!--") {
const closeIndex = findClosingIndex(xmlData, "-->", i + 3, "StopNode is not closed.");
i = closeIndex;
} else if (xmlData.substr(i + 1, 2) === "![") {
const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
i = closeIndex;
} else {
const tagData = readTagExp(xmlData, i, ">");
if (tagData) {
const openTagName = tagData && tagData.tagName;
if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/") {
openTagCount++;
}
i = tagData.closeIndex;
}
}
}
}
}
function parseValue(val2, shouldParse, options) {
if (shouldParse && typeof val2 === "string") {
const newval = val2.trim();
if (newval === "true")
return true;
else if (newval === "false")
return false;
else
return toNumber(val2, options);
} else {
if (util.isExist(val2)) {
return val2;
} else {
return "";
}
}
}
module2.exports = OrderedObjParser;
}
});
// node_modules/fast-xml-parser/src/xmlparser/node2json.js
var require_node2json = __commonJS({
"node_modules/fast-xml-parser/src/xmlparser/node2json.js"(exports2) {
"use strict";
function prettify(node, options) {
return compress(node, options);
}
function compress(arr, options, jPath) {
let text;
const compressedObj = {};
for (let i = 0; i < arr.length; i++) {
const tagObj = arr[i];
const property = propName(tagObj);
let newJpath = "";
if (jPath === void 0)
newJpath = property;
else
newJpath = jPath + "." + property;
if (property === options.textNodeName) {
if (text === void 0)
text = tagObj[property];
else
text += "" + tagObj[property];
} else if (property === void 0) {
continue;
} else if (tagObj[property]) {
let val2 = compress(tagObj[property], options, newJpath);
const isLeaf = isLeafTag(val2, options);
if (tagObj[":@"]) {
assignAttributes(val2, tagObj[":@"], newJpath, options);
} else if (Object.keys(val2).length === 1 && val2[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode) {
val2 = val2[options.textNodeName];
} else if (Object.keys(val2).length === 0) {
if (options.alwaysCreateTextNode)
val2[options.textNodeName] = "";
else
val2 = "";
}
if (compressedObj[property] !== void 0 && compressedObj.hasOwnProperty(property)) {
if (!Array.isArray(compressedObj[property])) {
compressedObj[property] = [compressedObj[property]];
}
compressedObj[property].push(val2);
} else {
if (options.isArray(property, newJpath, isLeaf)) {
compressedObj[property] = [val2];
} else {
compressedObj[property] = val2;
}
}
}
}
if (typeof text === "string") {
if (text.length > 0)
compressedObj[options.textNodeName] = text;
} else if (text !== void 0)
compressedObj[options.textNodeName] = text;
return compressedObj;
}
function propName(obj) {
const keys = Object.keys(obj);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (key !== ":@")
return key;
}
}
function assignAttributes(obj, attrMap, jpath, options) {
if (attrMap) {
const keys = Object.keys(attrMap);
const len = keys.length;
for (let i = 0; i < len; i++) {
const atrrName = keys[i];
if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
obj[atrrName] = [attrMap[atrrName]];
} else {
obj[atrrName] = attrMap[atrrName];
}
}
}
}
function isLeafTag(obj, options) {
const { textNodeName } = options;
const propCount = Object.keys(obj).length;
if (propCount === 0) {
return true;
}
if (propCount === 1 && (obj[textNodeName] || typeof obj[textNodeName] === "boolean" || obj[textNodeName] === 0)) {
return true;
}
return false;
}
exports2.prettify = prettify;
}
});
// node_modules/fast-xml-parser/src/xmlparser/XMLParser.js
var require_XMLParser = __commonJS({
"node_modules/fast-xml-parser/src/xmlparser/XMLParser.js"(exports2, module2) {
var { buildOptions } = require_OptionsBuilder();
var OrderedObjParser = require_OrderedObjParser();
var { prettify } = require_node2json();
var validator = require_validator();
var XMLParser2 = class {
constructor(options) {
this.externalEntities = {};
this.options = buildOptions(options);
}
/**
* Parse XML dats to JS object
* @param {string|Buffer} xmlData
* @param {boolean|Object} validationOption
*/
parse(xmlData, validationOption) {
if (typeof xmlData === "string") {
} else if (xmlData.toString) {
xmlData = xmlData.toString();
} else {
throw new Error("XML data is accepted in String or Bytes[] form.");
}
if (validationOption) {
if (validationOption === true)
validationOption = {};
const result = validator.validate(xmlData, validationOption);
if (result !== true) {
throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`);
}
}
const orderedObjParser = new OrderedObjParser(this.options);
orderedObjParser.addExternalEntities(this.externalEntities);
const orderedResult = orderedObjParser.parseXml(xmlData);
if (this.options.preserveOrder || orderedResult === void 0)
return orderedResult;
else
return prettify(orderedResult, this.options);
}
/**
* Add Entity which is not by default supported by this library
* @param {string} key
* @param {string} value
*/
addEntity(key, value) {
if (value.indexOf("&") !== -1) {
throw new Error("Entity value can't have '&'");
} else if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) {
throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");
} else if (value === "&") {
throw new Error("An entity with value '&' is not permitted");
} else {
this.externalEntities[key] = value;
}
}
};
module2.exports = XMLParser2;
}
});
// node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js
var require_orderedJs2Xml = __commonJS({
"node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js"(exports2, module2) {
var EOL = "\n";
function toXml(jArray, options) {
let indentation = "";
if (options.format && options.indentBy.length > 0) {
indentation = EOL;
}
return arrToStr(jArray, options, "", indentation);
}
function arrToStr(arr, options, jPath, indentation) {
let xmlStr = "";
let isPreviousElementTag = false;
for (let i = 0; i < arr.length; i++) {
const tagObj = arr[i];
const tagName = propName(tagObj);
let newJPath = "";
if (jPath.length === 0)
newJPath = tagName;
else
newJPath = `${jPath}.${tagName}`;
if (tagName === options.textNodeName) {
let tagText = tagObj[tagName];
if (!isStopNode(newJPath, options)) {
tagText = options.tagValueProcessor(tagName, tagText);
tagText = replaceEntitiesValue(tagText, options);
}
if (isPreviousElementTag) {
xmlStr += indentation;
}
xmlStr += tagText;
isPreviousElementTag = false;
continue;
} else if (tagName === options.cdataPropName) {
if (isPreviousElementTag) {
xmlStr += indentation;
}
xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
isPreviousElementTag = false;
continue;
} else if (tagName === options.commentPropName) {
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
isPreviousElementTag = true;
continue;
} else if (tagName[0] === "?") {
const attStr2 = attr_to_str(tagObj[":@"], options);
const tempInd = tagName === "?xml" ? "" : indentation;
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : "";
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr2}?>`;
isPreviousElementTag = true;
continue;
}
let newIdentation = indentation;
if (newIdentation !== "") {
newIdentation += options.indentBy;
}
const attStr = attr_to_str(tagObj[":@"], options);
const tagStart = indentation + `<${tagName}${attStr}`;
const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);
if (options.unpairedTags.indexOf(tagName) !== -1) {
if (options.suppressUnpairedNode)
xmlStr += tagStart + ">";
else
xmlStr += tagStart + "/>";
} else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
xmlStr += tagStart + "/>";
} else if (tagValue && tagValue.endsWith(">")) {
xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
} else {
xmlStr += tagStart + ">";
if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) {
xmlStr += indentation + options.indentBy + tagValue + indentation;
} else {
xmlStr += tagValue;
}
xmlStr += `</${tagName}>`;
}
isPreviousElementTag = true;
}
return xmlStr;
}
function propName(obj) {
const keys = Object.keys(obj);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (key !== ":@")
return key;
}
}
function attr_to_str(attrMap, options) {
let attrStr = "";
if (attrMap && !options.ignoreAttributes) {
for (let attr in attrMap) {
let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
attrVal = replaceEntitiesValue(attrVal, options);
if (attrVal === true && options.suppressBooleanAttributes) {
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
} else {
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
}
}
}
return attrStr;
}
function isStopNode(jPath, options) {
jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
for (let index in options.stopNodes) {
if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName)
return true;
}
return false;
}
function replaceEntitiesValue(textValue, options) {
if (textValue && textValue.length > 0 && options.processEntities) {
for (let i = 0; i < options.entities.length; i++) {
const entity = options.entities[i];
textValue = textValue.replace(entity.regex, entity.val);
}
}
return textValue;
}
module2.exports = toXml;
}
});
// node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js
var require_json2xml = __commonJS({
"node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js"(exports2, module2) {
"use strict";
var buildFromOrderedJs = require_orderedJs2Xml();
var defaultOptions = {
attributeNamePrefix: "@_",
attributesGroupName: false,
textNodeName: "#text",
ignoreAttributes: true,
cdataPropName: false,
format: false,
indentBy: " ",
suppressEmptyNode: false,
suppressUnpairedNode: true,
suppressBooleanAttributes: true,
tagValueProcessor: function(key, a) {
return a;
},
attributeValueProcessor: function(attrName, a) {
return a;
},
preserveOrder: false,
commentPropName: false,
unpairedTags: [],
entities: [
{ regex: new RegExp("&", "g"), val: "&" },
//it must be on top
{ regex: new RegExp(">", "g"), val: ">" },
{ regex: new RegExp("<", "g"), val: "<" },
{ regex: new RegExp("'", "g"), val: "'" },
{ regex: new RegExp('"', "g"), val: """ }
],
processEntities: true,
stopNodes: [],
// transformTagName: false,
// transformAttributeName: false,
oneListGroup: false
};
function Builder(options) {
this.options = Object.assign({}, defaultOptions, options);
if (this.options.ignoreAttributes || this.options.attributesGroupName) {
this.isAttribute = function() {
return false;
};
} else {
this.attrPrefixLen = this.options.attributeNamePrefix.length;
this.isAttribute = isAttribute;
}
this.processTextOrObjNode = processTextOrObjNode;
if (this.options.format) {
this.indentate = indentate;
this.tagEndChar = ">\n";
this.newLine = "\n";
} else {
this.indentate = function() {
return "";
};
this.tagEndChar = ">";
this.newLine = "";
}
}
Builder.prototype.build = function(jObj) {
if (this.options.preserveOrder) {
return buildFromOrderedJs(jObj, this.options);
} else {
if (Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1) {
jObj = {
[this.options.arrayNodeName]: jObj
};
}
return this.j2x(jObj, 0).val;
}
};
Builder.prototype.j2x = function(jObj, level) {
let attrStr = "";
let val2 = "";
for (let key in jObj) {
if (typeof jObj[key] === "undefined") {
} else if (jObj[key] === null) {
if (key[0] === "?")
val2 += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
else
val2 += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
} else if (jObj[key] instanceof Date) {
val2 += this.buildTextValNode(jObj[key], key, "", level);
} else if (typeof jObj[key] !== "object") {
const attr = this.isAttribute(key);
if (attr) {
attrStr += this.buildAttrPairStr(attr, "" + jObj[key]);
} else {
if (key === this.options.textNodeName) {
let newval = this.options.tagValueProcessor(key, "" + jObj[key]);
val2 += this.replaceEntitiesValue(newval);
} else {
val2 += this.buildTextValNode(jObj[key], key, "", level);
}
}
} else if (Array.isArray(jObj[key])) {
const arrLen = jObj[key].length;
let listTagVal = "";
for (let j = 0; j < arrLen; j++) {
const item = jObj[key][j];
if (typeof item === "undefined") {
} else if (item === null) {
if (key[0] === "?")
val2 += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
else
val2 += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
} else if (typeof item === "object") {
if (this.options.oneListGroup) {
listTagVal += this.j2x(item, level + 1).val;
} else {
listTagVal += this.processTextOrObjNode(item, key, level);
}
} else {
listTagVal += this.buildTextValNode(item, key, "", level);
}
}
if (this.options.oneListGroup) {
listTagVal = this.buildObjectNode(listTagVal, key, "", level);
}
val2 += listTagVal;
} else {
if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
const Ks = Object.keys(jObj[key]);
const L = Ks.length;
for (let j = 0; j < L; j++) {
attrStr += this.buildAttrPairStr(Ks[j], "" + jObj[key][Ks[j]]);
}
} else {
val2 += this.processTextOrObjNode(jObj[key], key, level);
}
}
}
return { attrStr, val: val2 };
};
Builder.prototype.buildAttrPairStr = function(attrName, val2) {
val2 = this.options.attributeValueProcessor(attrName, "" + val2);
val2 = this.replaceEntitiesValue(val2);
if (this.options.suppressBooleanAttributes && val2 === "true") {
return " " + attrName;
} else
return " " + attrName + '="' + val2 + '"';
};
function processTextOrObjNode(object, key, level) {
const result = this.j2x(object, level + 1);
if (object[this.options.textNodeName] !== void 0 && Object.keys(object).length === 1) {
return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
} else {
return this.buildObjectNode(result.val, key, result.attrStr, level);
}
}
Builder.prototype.buildObjectNode = function(val2, key, attrStr, level) {
if (val2 === "") {
if (key[0] === "?")
return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
else {
return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
}
} else {
let tagEndExp = "</" + key + this.tagEndChar;
let piClosingChar = "";
if (key[0] === "?") {
piClosingChar = "?";
tagEndExp = "";
}
if (attrStr && val2.indexOf("<") === -1) {
return this.indentate(level) + "<" + key + attrStr + piClosingChar + ">" + val2 + tagEndExp;
} else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
return this.indentate(level) + `<!--${val2}-->` + this.newLine;
} else {
return this.indentate(level) + "<" + key + attrStr + piClosingChar + this.tagEndChar + val2 + this.indentate(level) + tagEndExp;
}
}
};
Builder.prototype.closeTag = function(key) {
let closeTag = "";
if (this.options.unpairedTags.indexOf(key) !== -1) {
if (!this.options.suppressUnpairedNode)
closeTag = "/";
} else if (this.options.suppressEmptyNode) {
closeTag = "/";
} else {
closeTag = `></${key}`;
}
return closeTag;
};
Builder.prototype.buildTextValNode = function(val2, key, attrStr, level) {
if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
return this.indentate(level) + `<![CDATA[${val2}]]>` + this.newLine;
} else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
return this.indentate(level) + `<!--${val2}-->` + this.newLine;
} else if (key[0] === "?") {
return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
} else {
let textValue = this.options.tagValueProcessor(key, val2);
textValue = this.replaceEntitiesValue(textValue);
if (textValue === "") {
return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
} else {
return this.indentate(level) + "<" + key + attrStr + ">" + textValue + "</" + key + this.tagEndChar;
}
}
};
Builder.prototype.replaceEntitiesValue = function(textValue) {
if (textValue && textValue.length > 0 && this.options.processEntities) {
for (let i = 0; i < this.options.entities.length; i++) {
const entity = this.options.entities[i];
textValue = textValue.replace(entity.regex, entity.val);
}
}
return textValue;
};
function indentate(level) {
return this.options.indentBy.repeat(level);
}
function isAttribute(name) {
if (name.startsWith(this.options.attributeNamePrefix)) {
return name.substr(this.attrPrefixLen);
} else {
return false;
}
}
module2.exports = Builder;
}
});
// node_modules/fast-xml-parser/src/fxp.js
var require_fxp = __commonJS({
"node_modules/fast-xml-parser/src/fxp.js"(exports2, module2) {
"use strict";
var validator = require_validator();
var XMLParser2 = require_XMLParser();
var XMLBuilder = require_json2xml();
module2.exports = {
XMLParser: XMLParser2,
XMLValidator: validator,
XMLBuilder
};
}
});
// src/utils/isCommentRenderer.ts
function isCommentRenderer(continuationItems) {
if (continuationItems.length > 0) {
if (continuationItems[0].hasOwnProperty("commentThreadRenderer")) {
return false;
}
if (continuationItems[0].hasOwnProperty("commentRenderer")) {
return true;
}
}
return false;
}
// src/utils/findElementByTrackingParams.ts
function findElementByTrackingParams(trackingParams, elementSelector) {
let returnElement = null;
const elems = document.querySelectorAll(elementSelector);
for (let i = 0; i < elems.length; i++) {
if (elems[i].trackedParams === trackingParams) {
returnElement = elems[i];
break;
}
}
return returnElement;
}
async function reSearchElement(trackingParams, selector) {
return await new Promise((resolve) => {
let isFinding = true;
const search = () => {
const el = findElementByTrackingParams(trackingParams, selector);
if (el !== null) {
resolve(el);
isFinding = false;
}
if (isFinding) {
setTimeout(() => {
search();
}, 100);
}
};
search();
});
}
function findElementAllByCommentId(commnetId, elementSelector) {
const returnElements = [];
const elems = document.querySelectorAll(elementSelector);
elems.forEach((elem) => {
if (elem.__data.data.commentId === commnetId) {
returnElements.push(elem);
}
});
return returnElements;
}
async function reSearchElementAllByCommentId(commnetId, selector) {
return await new Promise((resolve) => {
let isFinding = true;
const search = () => {
const el = findElementAllByCommentId(commnetId, selector);
if (el !== null) {
resolve(el);
isFinding = false;
}
if (isFinding) {
setTimeout(() => {
search();
}, 100);
}
};
search();
});
}
// src/utils/escapeString.ts
function escapeString(text) {
return text.replaceAll("<", "<").replaceAll(">", ">").replaceAll(`"`, `"`).replaceAll(`'`, `'`);
}
// src/utils/getUserName.ts
var import_fast_xml_parser = __toESM(require_fxp());
async function getUserName(id) {
const data = await fetch(
`https://www.youtube.com/feeds/videos.xml?channel_id=${id}`,
{
method: "GET",
cache: "default",
keepalive: false
}
).then(async (res) => await res.text()).then((text) => {
const parser = new import_fast_xml_parser.XMLParser();
const data2 = parser.parse(text);
return data2.feed.title;
});
return data;
}
// src/rewrites/rewriteOfCommentRenderer/nameRewriteOfCommentRenderer.ts
function nameRewriteOfCommentRenderer(commentRenderer, isNameContainerRender, userId) {
const commentRendererBody = commentRenderer.__shady_native_children[2];
let nameElem = commentRendererBody.querySelector(
"#main > #header > #header-author > h3 > a > span"
);
if (isNameContainerRender) {
nameElem = commentRendererBody.__shady_native_children[1].querySelector(
"#header > #header-author > #author-comment-badge > ytd-author-comment-badge-renderer > a > #channel-name > #container > #text-container > yt-formatted-string"
);
}
void getUserName(userId).then((name) => {
if (nameElem !== null) {
if (isNameContainerRender) {
nameElem.__shady_native_innerHTML = escapeString(name);
} else {
nameElem.textContent = escapeString(name);
}
}
});
}
// src/rewrites/comment.ts
function rewriteCommentNameFromContinuationItems(continuationItems) {
continuationItems.forEach((continuationItem) => {
const { commentThreadRenderer } = continuationItem;
if (commentThreadRenderer !== void 0) {
const { trackingParams } = commentThreadRenderer;
void getCommentElem(trackingParams).then((commentElem) => {
reWriteCommentElem(commentElem, commentThreadRenderer);
});
}
});
}
function reWriteCommentElem(commentElem, commentThreadRenderer) {
const commentRenderer = commentElem.__shady_native_children[0];
if (commentRenderer !== null && commentRenderer !== void 0) {
let isContainer = commentThreadRenderer.comment.commentRenderer.authorIsChannelOwner;
if (commentThreadRenderer.comment.commentRenderer.authorCommentBadge !== void 0) {
isContainer = true;
}
nameRewriteOfCommentRenderer(
commentRenderer,
isContainer,
commentThreadRenderer.comment.commentRenderer.authorEndpoint.browseEndpoint.browseId
);
}
}
async function getCommentElem(trackingParams) {
return await new Promise((resolve) => {
const commentElem = findElementByTrackingParams(
trackingParams,
"#comments > #sections > #contents > ytd-comment-thread-renderer"
);
if (commentElem !== null) {
resolve(commentElem);
} else {
void reSearchElement(trackingParams, "ytd-comment-thread-renderer").then(
(commentElem2) => {
resolve(commentElem2);
}
);
}
});
}
// src/rewrites/rewriteOfCommentRenderer/mentionRewriteOfCommentRenderer.ts
function mentionRewriteOfCommentRenderer(commentRenderer) {
const commentRendererBody = commentRenderer.__shady_native_children[2];
const main2 = commentRendererBody.__shady_native_children[1];
const aTags = main2.querySelectorAll(
"#comment-content > ytd-expander > #content > #content-text > a"
);
aTags.forEach((aTag) => {
if (aTag.textContent?.match("@.*") !== null) {
const href = aTag.getAttribute("href");
if (href !== null) {
void getUserName(href.split("/")[2]).then((name) => {
aTag.textContent = `@${escapeString(name)} `;
});
}
}
});
}
// src/rewrites/reply.ts
function rewriteReplytNameFromContinuationItems(continuationItems) {
continuationItems.forEach((continuationItem) => {
const { commentRenderer } = continuationItem;
if (commentRenderer !== void 0) {
void getReplyElem(commentRenderer.trackingParams).then((replyElem) => {
reWriteReplyElem(replyElem, commentRenderer);
});
}
});
}
function reWriteReplyElem(replyElem, rendererData) {
let isContainer = rendererData.authorIsChannelOwner;
if (rendererData.authorCommentBadge !== void 0) {
isContainer = true;
}
nameRewriteOfCommentRenderer(
replyElem,
isContainer,
rendererData.authorEndpoint.browseEndpoint.browseId
);
mentionRewriteOfCommentRenderer(replyElem);
}
async function getReplyElem(trackedParams) {
return await new Promise((resolve) => {
const selector = "#replies > ytd-comment-replies-renderer > #expander > #expander-contents > #contents > ytd-comment-renderer";
const commentRenderer = findElementByTrackingParams(
trackedParams,
selector
);
if (commentRenderer !== null) {
resolve(commentRenderer);
} else {
void reSearchElement(trackedParams, selector).then((commentRenderer2) => {
resolve(commentRenderer2);
});
}
});
}
function rewriteTeaserReplytNameFromContinuationItems(continuationItems) {
continuationItems.forEach((continuationItem) => {
const { commentRenderer } = continuationItem;
if (commentRenderer !== void 0) {
void reSearchElementAllByCommentId(
commentRenderer.commentId,
"ytd-comment-replies-renderer > #teaser-replies > ytd-comment-renderer"
).then((replyElems) => {
replyElems.forEach((replyElem) => {
reWriteReplyElem(replyElem, commentRenderer);
});
});
void reSearchElementAllByCommentId(
commentRenderer.commentId,
"ytd-comment-replies-renderer > #expander > #expander-contents > #contents > ytd-comment-renderer"
).then((replyElems) => {
replyElems.forEach((replyElem) => {
reWriteReplyElem(replyElem, commentRenderer);
});
});
}
});
}
// src/handlers/handleYtAppendContinuationItemsAction.ts
function handleYtAppendContinuationItemsAction(detail) {
const continuationItems = detail.args[0].appendContinuationItemsAction.continuationItems;
if (isCommentRenderer(continuationItems)) {
const replyDetail = detail;
setTimeout(() => {
rewriteReplytNameFromContinuationItems(
replyDetail.args[0].appendContinuationItemsAction.continuationItems
);
}, 1);
} else {
const commentDetail = detail;
setTimeout(() => {
rewriteCommentNameFromContinuationItems(
commentDetail.args[0].appendContinuationItemsAction.continuationItems
);
}, 10);
}
}
// src/handlers/handleYtCreateCommentAction.ts
function handleYtCreateCommentAction(detail) {
const createCommentDetail = detail;
const continuationItems = [
{
commentThreadRenderer: createCommentDetail.args[0].createCommentAction.contents.commentThreadRenderer
}
];
setTimeout(() => {
rewriteCommentNameFromContinuationItems(continuationItems);
}, 100);
}
// src/handlers/handleYtCreateCommentReplyAction.ts
function handleYtCreateCommentReplyAction(detail) {
const createReplyDetail = detail;
const continuationItems = [
{
commentRenderer: createReplyDetail.args[0].createCommentReplyAction.contents.commentRenderer
}
];
setTimeout(() => {
rewriteTeaserReplytNameFromContinuationItems(continuationItems);
}, 100);
}
// src/rewrites/highlightedReply.ts
function rewriteHighlightedReply(trackedParams, isContainer, userId) {
const elem = findElementByTrackingParams(
trackedParams,
"ytd-comment-renderer"
);
const rewriteHighlightedReplyElem = (elem2) => {
nameRewriteOfCommentRenderer(elem2, isContainer, userId);
};
if (elem === null) {
void reSearchElement(trackedParams, "ytd-comment-renderer").then((elem2) => {
rewriteHighlightedReplyElem(elem2);
});
} else {
rewriteHighlightedReplyElem(elem);
}
}
// src/handlers/handleYtGetMultiPageMenuAction.ts
function handleYtGetMultiPageMenuAction(detail) {
const getMultiPageMenuDetail = detail;
const continuationItems = getMultiPageMenuDetail.args[0].getMultiPageMenuAction.menu.multiPageMenuRenderer.sections[1].itemSectionRenderer?.contents;
const highLightedTeaserContents = getMultiPageMenuDetail.args[0]?.getMultiPageMenuAction?.menu?.multiPageMenuRenderer.sections[1].itemSectionRenderer?.contents[0]?.commentThreadRenderer.replies?.commentRepliesRenderer?.teaserContents;
if (continuationItems !== void 0) {
setTimeout(() => {
rewriteCommentNameFromContinuationItems(continuationItems);
if (highLightedTeaserContents !== void 0) {
const highLightedReplyRenderer = highLightedTeaserContents[0]?.commentRenderer;
let isContainer = highLightedReplyRenderer.authorIsChannelOwner;
if (highLightedReplyRenderer.authorCommentBadge !== void 0) {
isContainer = true;
}
rewriteHighlightedReply(
highLightedReplyRenderer.trackingParams,
isContainer,
highLightedReplyRenderer.authorEndpoint.browseEndpoint.browseId
);
}
}, 100);
}
}
// src/handlers/handleYtHistory.ts
function handleYtHistory(detail) {
const historyDetail = detail;
const continuationItems = historyDetail.args[1].historyEntry?.rootData.response.contents.twoColumnWatchNextResults?.results?.results?.contents[3]?.itemSectionRenderer?.contents;
if (continuationItems !== void 0) {
setTimeout(() => {
rewriteCommentNameFromContinuationItems(continuationItems);
}, 100);
}
}
// src/handlers/handleYtReloadContinuationItemsCommand.ts
function handleYtReloadContinuationItemsCommand(detail) {
const reloadDetail = detail;
const { slot } = reloadDetail.args[0].reloadContinuationItemsCommand;
if (slot === "RELOAD_CONTINUATION_SLOT_BODY") {
const continuationItems = reloadDetail.args[0].reloadContinuationItemsCommand.continuationItems;
setTimeout(() => {
rewriteCommentNameFromContinuationItems(continuationItems);
}, 100);
}
}
// src/index.ts
function main() {
const handleYtAction = (e) => {
const { actionName } = e.detail;
switch (actionName) {
case "yt-append-continuation-items-action":
handleYtAppendContinuationItemsAction(e.detail);
break;
case "yt-reload-continuation-items-command":
handleYtReloadContinuationItemsCommand(e.detail);
break;
case "yt-history-load":
handleYtHistory(e.detail);
break;
case "yt-get-multi-page-menu-action":
handleYtGetMultiPageMenuAction(e.detail);
break;
case "yt-create-comment-action":
handleYtCreateCommentAction(e.detail);
break;
case "yt-create-comment-reply-action":
handleYtCreateCommentReplyAction(e.detail);
break;
}
};
document.addEventListener("yt-action", handleYtAction);
document.addEventListener("yt-navigate-finish", ({ detail }) => {
document.removeEventListener("yt-action", handleYtAction);
document.addEventListener("yt-action", handleYtAction);
});
}
// node_modules/ts-extension-builder/tmp/entry.ts
var args = {};
if (typeof GM_info !== "undefined" && GM_info.script.grant !== void 0) {
GM_info.script.grant.forEach((propatyName) => {
let keyName = propatyName.split("GM_")[1];
if (keyName === "xmlhttpRequest") {
keyName = "xmlHttpRequest";
}
args[propatyName] = GM[keyName];
});
}
main(args);
}
const script = document.createElement("script");
script.innerHTML = `(${inject.toString()})()`
unsafeWindow.document.body.appendChild(script)