mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
ui: remove babel
This commit is contained in:
1 parent
ff943b620e
commit
c7c70a6abb
23 files changed
+466
-606
No files matched your search
@@ -2,42 +2,42 @@ import { AutoloadPage } from 'vj/misc/Page';
|
||||
import request from 'vj/utils/request';
|
||||
|
||||
export default new AutoloadPage('media', async () => {
|
||||
async function parseMedia($dom = $(document.body)) {
|
||||
const items = [];
|
||||
const resolvers = [];
|
||||
const users = $dom.find('div[data-user]');
|
||||
const resolve = (ele, item) => {
|
||||
items.push(item);
|
||||
resolvers.push((html) => html && $(ele).replaceWith($(html)));
|
||||
};
|
||||
users.get().forEach((ele) => resolve(ele, { type: 'user', id: +$(ele).text() }));
|
||||
$dom.find('.typo').get().forEach((el) => {
|
||||
$(el).find('a[href]').get().forEach((ele) => {
|
||||
if ($(ele).parent().hasClass('user-profile-link')) return;
|
||||
let target = $(ele).attr('href');
|
||||
let { domainId } = UiContext;
|
||||
if (target.startsWith(UiContext.url_prefix)) {
|
||||
target.replace(UiContext.url_prefix, '');
|
||||
if (!target.startsWith('/')) target = `/${target}`;
|
||||
}
|
||||
if (!target.startsWith('/') || target.startsWith('//')) return;
|
||||
if (target.startsWith('/d/')) {
|
||||
const [, , domain, ...extra] = target.split('/');
|
||||
domainId = domain;
|
||||
target = `/${extra.join('/')}`;
|
||||
}
|
||||
const [, category, data, extra] = target.split('/');
|
||||
if (!data) return;
|
||||
if (category === 'user' && Number.isInteger(+data) && !extra) resolve(ele, { type: 'user', id: +data });
|
||||
if (category === 'p' && !extra) resolve(ele, { type: 'problem', id: data, domainId });
|
||||
if (category === 'contest' && !extra) resolve(ele, { type: 'contest', id: data, domainId });
|
||||
});
|
||||
});
|
||||
if (!items.length) return;
|
||||
const res = await request.post(`/d/${UiContext.domainId}/media`, { items });
|
||||
for (let i = 0; i < res.length; i++) resolvers[i](res[i]);
|
||||
}
|
||||
async function parseMedia($dom = $(document.body)) {
|
||||
const items = [];
|
||||
const resolvers = [];
|
||||
const users = $dom.find('div[data-user]');
|
||||
const resolve = (ele, item) => {
|
||||
items.push(item);
|
||||
resolvers.push((html) => html && $(ele).replaceWith($(html)));
|
||||
};
|
||||
users.get().forEach((ele) => resolve(ele, { type: 'user', id: +$(ele).text() }));
|
||||
$dom.find('.typo').get().forEach((el) => {
|
||||
$(el).find('a[href]').get().forEach((ele) => {
|
||||
if ($(ele).parent().hasClass('user-profile-link')) return;
|
||||
let target = $(ele).attr('href');
|
||||
let { domainId } = UiContext;
|
||||
if (target.startsWith(UiContext.url_prefix)) {
|
||||
target.replace(UiContext.url_prefix, '');
|
||||
if (!target.startsWith('/')) target = `/${target}`;
|
||||
}
|
||||
if (!target.startsWith('/') || target.startsWith('//')) return;
|
||||
if (target.startsWith('/d/')) {
|
||||
const [, , domain, ...extra] = target.split('/');
|
||||
domainId = domain;
|
||||
target = `/${extra.join('/')}`;
|
||||
}
|
||||
const [, category, data, extra] = target.split('/');
|
||||
if (!data) return;
|
||||
if (category === 'user' && Number.isInteger(+data) && !extra) resolve(ele, { type: 'user', id: +data });
|
||||
if (category === 'p' && !extra) resolve(ele, { type: 'problem', id: data, domainId });
|
||||
if (category === 'contest' && !extra) resolve(ele, { type: 'contest', id: data, domainId });
|
||||
});
|
||||
});
|
||||
if (!items.length) return;
|
||||
const res = await request.post(`/d/${UiContext.domainId}/media`, { items });
|
||||
for (let i = 0; i < res.length; i++) resolvers[i](res[i]);
|
||||
}
|
||||
|
||||
await parseMedia();
|
||||
$(document).on('vjContentNew', (e) => parseMedia($(e.target)));
|
||||
await parseMedia();
|
||||
$(document).on('vjContentNew', (e) => parseMedia($(e.target)));
|
||||
});
|
||||
Reference in new issue
Block a user