SHA256
23 lines
925 B
JavaScript
23 lines
925 B
JavaScript
// Текст сервера недоверенный: никакого HTML, только текст и HTTPS-ссылки.
|
|
export function appendAboutText(container, text) {
|
|
const value = String(text);
|
|
let offset = 0;
|
|
for (const match of value.matchAll(/https:\/\/[^\s<>"']+/gu)) {
|
|
container.append(document.createTextNode(value.slice(offset, match.index)));
|
|
try {
|
|
const url = new URL(match[0]);
|
|
if (url.protocol !== 'https:' || url.username || url.password) throw new Error('Invalid URL');
|
|
const link = document.createElement('a');
|
|
link.href = url.href;
|
|
link.textContent = match[0];
|
|
link.target = '_blank';
|
|
link.rel = 'noopener noreferrer';
|
|
container.append(link);
|
|
} catch {
|
|
container.append(document.createTextNode(match[0]));
|
|
}
|
|
offset = match.index + match[0].length;
|
|
}
|
|
container.append(document.createTextNode(value.slice(offset)));
|
|
}
|