| 12345678910111213141516171819202122 |
- function trainingMediaMirrorUrl(value) {
- if (typeof value !== 'string') return value;
- const match = /^(?:https?:\/\/a018\.2018\.z01\.com|\/\/a018\.2018\.z01\.com)?(\/UploadFiles\/.+)$/i.exec(value.trim());
- if (!match) return value;
- const path = match[1];
- const mirrored = TRAINING_MEDIA_MIRRORS.get(path);
- return mirrored ? 'https://h5.xiaoshu.pro' + mirrored : value;
- }
- function trainingMediaMirrorHtml(html) {
- if (typeof html !== 'string') return html;
- return html.replace(/<(img|video|audio|source|track|a)\b(?:[^"'<>]|"[^"]*"|'[^']*')*>/gi, (tag, element) => {
- return tag.replace(/(\s+)([^\s=<>]+)(\s*=\s*)("[^"]*"|'[^']*'|[^\s"'=<>`]+)/g, (attribute, space, name, equals, raw) => {
- const key = name.toLowerCase();
- if (key !== 'src' && key !== 'poster' && !(element.toLowerCase() === 'a' && key === 'href')) return attribute;
- const quote = raw[0] === '"' || raw[0] === "'" ? raw[0] : '';
- const value = quote ? raw.slice(1, -1) : raw;
- const target = trainingMediaMirrorUrl(value);
- return target === value ? attribute : space + name + equals + quote + target + quote;
- });
- });
- }
|