mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-18 02:14:32 +08:00
新建订阅支持粘贴导入
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { Modal, message, InputNumber, Form, Radio, Select, Input } from 'antd';
|
||||
import { request } from '@/utils/http';
|
||||
import config from '@/utils/config';
|
||||
@@ -183,6 +183,44 @@ const SubscriptionModal = ({
|
||||
);
|
||||
};
|
||||
|
||||
const onPaste = useCallback((e: any) => {
|
||||
const text = e.clipboardData.getData('text');
|
||||
if (!subscription && text.includes('ql ')) {
|
||||
const [
|
||||
,
|
||||
type,
|
||||
url,
|
||||
whitelist,
|
||||
blacklist,
|
||||
dependences,
|
||||
branch,
|
||||
extensions,
|
||||
] = text.split(' ').map((x) => x.trim());
|
||||
form.setFieldsValue({
|
||||
type:
|
||||
type === 'raw'
|
||||
? 'file'
|
||||
: url.startsWith('http')
|
||||
? 'public-repo'
|
||||
: 'private-repo',
|
||||
url,
|
||||
whitelist,
|
||||
blacklist,
|
||||
dependences,
|
||||
branch,
|
||||
extensions,
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
window.addEventListener('paste', onPaste);
|
||||
} else {
|
||||
window.removeEventListener('paste', onPaste);
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
useEffect(() => {
|
||||
form.setFieldsValue(subscription || {});
|
||||
setType((subscription && subscription.type) || 'public-repo');
|
||||
@@ -193,12 +231,39 @@ const SubscriptionModal = ({
|
||||
}
|
||||
}, [subscription, visible]);
|
||||
|
||||
const isFirefox = navigator.userAgent.includes('Firefox');
|
||||
const isSafari =
|
||||
navigator.userAgent.includes('Safari') &&
|
||||
!navigator.userAgent.includes('Chrome');
|
||||
const isQQBrowser = navigator.userAgent.includes('QQBrowser');
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={subscription ? '编辑订阅' : '新建订阅'}
|
||||
title={
|
||||
subscription ? (
|
||||
'编辑订阅'
|
||||
) : (
|
||||
<span>
|
||||
新建订阅
|
||||
<small
|
||||
style={{
|
||||
color: '#999',
|
||||
fontWeight: 400,
|
||||
fontSize: isFirefox ? 9 : 12,
|
||||
marginLeft: 2,
|
||||
zoom: isSafari ? 0.66 : 0.8,
|
||||
letterSpacing: isQQBrowser ? -2 : 0,
|
||||
}}
|
||||
>
|
||||
拷贝repo/raw命令,粘贴导入
|
||||
</small>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
visible={visible}
|
||||
forceRender
|
||||
centered
|
||||
maskClosable={false}
|
||||
onOk={() => {
|
||||
form
|
||||
.validateFields()
|
||||
|
||||
Reference in New Issue
Block a user