2023-09-20 21:08:02 -04:00
|
|
|
<!doctype html>
|
2023-09-16 09:46:59 -04:00
|
|
|
<html lang="zh-CN">
|
2023-09-20 21:08:02 -04:00
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
2023-09-16 09:46:59 -04:00
|
|
|
<title>sub2clash</title>
|
|
|
|
|
|
|
|
<!-- Bootstrap CSS -->
|
2023-09-20 21:08:02 -04:00
|
|
|
<link
|
|
|
|
crossorigin="anonymous"
|
|
|
|
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
|
|
|
|
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
|
|
|
|
rel="stylesheet"
|
|
|
|
/>
|
2023-09-16 09:46:59 -04:00
|
|
|
|
|
|
|
<!-- Bootstrap JS -->
|
2023-09-20 21:08:02 -04:00
|
|
|
<script
|
|
|
|
crossorigin="anonymous"
|
|
|
|
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
|
|
|
|
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
|
|
|
|
></script>
|
2023-09-16 09:46:59 -04:00
|
|
|
|
2023-09-17 03:52:37 -04:00
|
|
|
<!-- Axios -->
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
|
|
|
2023-09-16 09:46:59 -04:00
|
|
|
<style>
|
2023-09-20 21:08:02 -04:00
|
|
|
.container {
|
|
|
|
max-width: 800px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.btn-xs {
|
|
|
|
padding: 2px 2px; /* 调整内边距以减小按钮大小 */
|
|
|
|
font-size: 10px; /* 设置字体大小 */
|
|
|
|
line-height: 1.2; /* 调整行高 */
|
|
|
|
border-radius: 3px; /* 可选的边框半径调整 */
|
|
|
|
height: 25px;
|
|
|
|
width: 25px;
|
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
</style>
|
2023-09-20 21:08:02 -04:00
|
|
|
</head>
|
2023-09-16 09:46:59 -04:00
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
<body class="bg-light">
|
|
|
|
<div class="container mt-5">
|
|
|
|
<div class="mb-4">
|
2023-09-16 09:46:59 -04:00
|
|
|
<h2>sub2clash</h2>
|
2023-09-20 21:08:02 -04:00
|
|
|
<span class="text-muted fst-italic"
|
|
|
|
>通用订阅链接转 Clash(Meta) 配置工具
|
|
|
|
<a
|
|
|
|
href="https://github.com/nitezs/sub2clash#clash-meta"
|
|
|
|
target="_blank"
|
|
|
|
>使用文档</a
|
|
|
|
></span
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<form id="apiForm">
|
2023-09-16 09:46:59 -04:00
|
|
|
<!-- API Endpoint -->
|
|
|
|
<div class="form-group mb-3">
|
2023-09-20 21:08:02 -04:00
|
|
|
<label for="endpoint">客户端类型:</label>
|
|
|
|
<select class="form-control" id="endpoint" name="endpoint">
|
|
|
|
<option value="clash">Clash</option>
|
|
|
|
<option value="meta">Clash.Meta</option>
|
|
|
|
</select>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Subscription Link -->
|
|
|
|
<div class="form-group mb-3">
|
2023-09-20 21:08:02 -04:00
|
|
|
<label for="sub">订阅链接:</label>
|
|
|
|
<textarea
|
|
|
|
class="form-control"
|
|
|
|
id="sub"
|
|
|
|
name="sub"
|
|
|
|
placeholder="每行输入一个订阅链接"
|
|
|
|
rows="5"
|
|
|
|
></textarea>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Proxy Link -->
|
|
|
|
<div class="form-group mb-3">
|
2023-09-20 21:08:02 -04:00
|
|
|
<label for="proxy">节点分享链接:</label>
|
|
|
|
<textarea
|
|
|
|
class="form-control"
|
|
|
|
id="proxy"
|
|
|
|
name="proxy"
|
|
|
|
placeholder="每行输入一个节点分享链接"
|
|
|
|
rows="5"
|
|
|
|
></textarea>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Refresh -->
|
|
|
|
<div class="form-check mb-3">
|
2023-09-20 21:08:02 -04:00
|
|
|
<input
|
|
|
|
class="form-check-input"
|
|
|
|
id="refresh"
|
|
|
|
name="refresh"
|
|
|
|
type="checkbox"
|
|
|
|
/>
|
|
|
|
<label class="form-check-label" for="refresh">强制刷新配置</label>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Template -->
|
|
|
|
<div class="form-group mb-3">
|
2023-09-20 21:08:02 -04:00
|
|
|
<label for="template">模板链接或名称(可选):</label>
|
|
|
|
<input
|
|
|
|
class="form-control"
|
|
|
|
id="template"
|
|
|
|
name="template"
|
|
|
|
placeholder="输入外部模板链接或内部模板名称"
|
|
|
|
type="text"
|
|
|
|
/>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Rule Provider -->
|
|
|
|
<div class="form-group mb-3" id="ruleProviderGroup">
|
2023-09-20 21:08:02 -04:00
|
|
|
<label>Rule Provider:</label>
|
|
|
|
<button
|
|
|
|
class="btn btn-primary mb-1 btn-xs"
|
|
|
|
onclick="addRuleProvider()"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
+
|
|
|
|
</button>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Rule -->
|
|
|
|
<div class="form-group mb-3" id="ruleGroup">
|
2023-09-20 21:08:02 -04:00
|
|
|
<label>规则:</label>
|
|
|
|
<button
|
|
|
|
class="btn btn-primary mb-1 btn-xs"
|
|
|
|
onclick="addRule()"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
+
|
|
|
|
</button>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Auto Test -->
|
|
|
|
<div class="form-check mb-3">
|
2023-09-20 21:08:02 -04:00
|
|
|
<input
|
|
|
|
class="form-check-input"
|
|
|
|
id="autoTest"
|
|
|
|
name="autoTest"
|
|
|
|
type="checkbox"
|
|
|
|
/>
|
|
|
|
<label class="form-check-label" for="autoTest"
|
|
|
|
>国家策略组自动测速</label
|
|
|
|
>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Lazy -->
|
|
|
|
<div class="form-check mb-3">
|
2023-09-20 21:08:02 -04:00
|
|
|
<input
|
|
|
|
class="form-check-input"
|
|
|
|
id="lazy"
|
|
|
|
name="lazy"
|
|
|
|
type="checkbox"
|
|
|
|
/>
|
|
|
|
<label class="form-check-label" for="lazy">自动测速启用 lazy</label>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Sort -->
|
|
|
|
<div class="form-group mb-3">
|
2023-09-20 21:08:02 -04:00
|
|
|
<label for="sort">国家策略组排序策略:</label>
|
|
|
|
<select class="form-control" id="sort" name="sort">
|
|
|
|
<option value="nameasc">名称(升序)</option>
|
|
|
|
<option value="namedesc">名称(降序)</option>
|
|
|
|
<option value="sizeasc">节点数量(升序)</option>
|
|
|
|
<option value="sizedesc">节点数量(降序)</option>
|
|
|
|
</select>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
2023-09-22 11:43:26 -04:00
|
|
|
|
|
|
|
<!-- Remove -->
|
|
|
|
<div class="form-group mb-3">
|
|
|
|
<label for="remove">删除节点:</label>
|
|
|
|
<input
|
|
|
|
class="form-control"
|
|
|
|
type="text"
|
|
|
|
name="remove"
|
|
|
|
id="remove"
|
|
|
|
placeholder="正则表达式"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Rename -->
|
2023-09-22 12:58:57 -04:00
|
|
|
<div class="form-group mb-3" id="replaceGroup">
|
|
|
|
<label>节点名称替换:</label>
|
|
|
|
<button
|
|
|
|
class="btn btn-primary mb-1 btn-xs"
|
|
|
|
onclick="addReplace()"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
+
|
|
|
|
</button>
|
2023-09-22 11:43:26 -04:00
|
|
|
</div>
|
2023-09-20 21:08:02 -04:00
|
|
|
</form>
|
2023-09-16 09:46:59 -04:00
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
<!-- Display the API Link -->
|
|
|
|
<div class="form-group mb-5">
|
2023-09-17 03:52:37 -04:00
|
|
|
<label for="apiLink">配置链接:</label>
|
|
|
|
<div class="input-group mb-2">
|
2023-09-20 21:08:02 -04:00
|
|
|
<input class="form-control" id="apiLink" readonly type="text" />
|
|
|
|
<button class="btn btn-primary" onclick="generateURL()" type="button">
|
|
|
|
生成链接
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-primary"
|
|
|
|
onclick="copyToClipboard('apiLink',this)"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
复制链接
|
|
|
|
</button>
|
2023-09-17 03:52:37 -04:00
|
|
|
</div>
|
|
|
|
<div class="input-group">
|
2023-09-20 21:08:02 -04:00
|
|
|
<input class="form-control" id="apiShortLink" readonly type="text" />
|
2023-09-22 11:43:26 -04:00
|
|
|
<input
|
|
|
|
class="form-control"
|
|
|
|
id="password"
|
|
|
|
type="text"
|
|
|
|
placeholder="密码"
|
|
|
|
/>
|
2023-09-20 21:08:02 -04:00
|
|
|
<button
|
|
|
|
class="btn btn-primary"
|
|
|
|
onclick="generateShortLink()"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
生成短链
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn btn-primary"
|
|
|
|
onclick="copyToClipboard('apiShortLink',this)"
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
复制短链
|
|
|
|
</button>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
2023-09-20 21:08:02 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- footer-->
|
|
|
|
<footer>
|
|
|
|
<p class="text-center">
|
|
|
|
Powered by
|
|
|
|
<a class="link-primary" href="https://github.com/nitezs/sub2clash"
|
|
|
|
>sub2clash</a
|
|
|
|
>
|
|
|
|
</p>
|
|
|
|
<p class="text-center">Version {{.Version}}</p>
|
|
|
|
</footer>
|
2023-09-16 09:46:59 -04:00
|
|
|
</div>
|
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
<script>
|
|
|
|
async function copyToClipboard(elem, e) {
|
2023-09-17 03:52:37 -04:00
|
|
|
const apiLinkInput = document.querySelector(`#${elem}`).value;
|
2023-09-16 09:46:59 -04:00
|
|
|
try {
|
2023-09-20 21:08:02 -04:00
|
|
|
await navigator.clipboard.writeText(apiLinkInput);
|
|
|
|
let text = e.textContent;
|
|
|
|
e.addEventListener("mouseout", function () {
|
|
|
|
e.textContent = text;
|
|
|
|
});
|
|
|
|
e.textContent = "复制成功";
|
2023-09-16 09:46:59 -04:00
|
|
|
} catch (err) {
|
2023-09-20 21:08:02 -04:00
|
|
|
console.error("复制到剪贴板失败:", err);
|
2023-09-16 09:46:59 -04:00
|
|
|
}
|
2023-09-20 21:08:02 -04:00
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
function createRuleProvider() {
|
|
|
|
const div = document.createElement("div");
|
|
|
|
div.classList.add("input-group", "mb-2");
|
2023-09-16 09:46:59 -04:00
|
|
|
div.innerHTML = `
|
|
|
|
<input type="text" class="form-control" name="ruleProvider" placeholder="Behavior">
|
|
|
|
<input type="text" class="form-control" name="ruleProvider" placeholder="Url">
|
|
|
|
<input type="text" class="form-control" name="ruleProvider" placeholder="Group">
|
|
|
|
<input type="text" class="form-control" name="ruleProvider" placeholder="Prepend">
|
|
|
|
<input type="text" class="form-control" name="ruleProvider" placeholder="Name">
|
|
|
|
<button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
|
|
|
|
`;
|
|
|
|
return div;
|
2023-09-20 21:08:02 -04:00
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
|
2023-09-22 12:58:57 -04:00
|
|
|
function createReplace() {
|
|
|
|
const div = document.createElement("div");
|
|
|
|
div.classList.add("input-group", "mb-2");
|
|
|
|
div.innerHTML = `
|
|
|
|
<input type="text" class="form-control" name="replace" placeholder="原字符串(正则表达式)">
|
|
|
|
<input type="text" class="form-control" name="replace" placeholder="替换为(可为空)">
|
|
|
|
<button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
|
|
|
|
`;
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
function createRule() {
|
|
|
|
const div = document.createElement("div");
|
|
|
|
div.classList.add("input-group", "mb-2");
|
2023-09-16 09:46:59 -04:00
|
|
|
div.innerHTML = `
|
|
|
|
<input type="text" class="form-control" name="rule" placeholder="Rule">
|
|
|
|
<input type="text" class="form-control" name="rule" placeholder="Prepend">
|
|
|
|
<input type="text" class="form-control" name="rule" placeholder="Group">
|
|
|
|
<button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
|
|
|
|
`;
|
|
|
|
return div;
|
2023-09-20 21:08:02 -04:00
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
function addRuleProvider() {
|
2023-09-16 09:46:59 -04:00
|
|
|
const div = createRuleProvider();
|
2023-09-20 21:08:02 -04:00
|
|
|
document.getElementById("ruleProviderGroup").appendChild(div);
|
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
function addRule() {
|
2023-09-16 09:46:59 -04:00
|
|
|
const div = createRule();
|
2023-09-20 21:08:02 -04:00
|
|
|
document.getElementById("ruleGroup").appendChild(div);
|
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
|
2023-09-22 12:58:57 -04:00
|
|
|
function addReplace() {
|
|
|
|
const div = createReplace();
|
|
|
|
document.getElementById("replaceGroup").appendChild(div);
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
function removeElement(button) {
|
2023-09-16 09:46:59 -04:00
|
|
|
button.parentElement.remove();
|
2023-09-20 21:08:02 -04:00
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
function generateURI() {
|
2023-09-16 09:46:59 -04:00
|
|
|
const queryParams = [];
|
|
|
|
|
|
|
|
// 获取 API Endpoint
|
|
|
|
const endpoint = document.getElementById("endpoint").value;
|
|
|
|
|
|
|
|
// 获取并组合订阅链接
|
2023-09-20 21:08:02 -04:00
|
|
|
let subLines = document
|
|
|
|
.getElementById("sub")
|
|
|
|
.value.split("\n")
|
|
|
|
.filter((line) => line.trim() !== "");
|
|
|
|
let noSub = false;
|
2023-09-16 09:46:59 -04:00
|
|
|
// 去除 subLines 中空元素
|
|
|
|
subLines = subLines.map((item) => {
|
2023-09-20 21:08:02 -04:00
|
|
|
if (item !== "") {
|
|
|
|
return item;
|
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
});
|
|
|
|
if (subLines.length > 0) {
|
2023-09-20 21:08:02 -04:00
|
|
|
queryParams.push(`sub=${encodeURIComponent(subLines.join(","))}`);
|
2023-09-17 03:52:37 -04:00
|
|
|
} else {
|
2023-09-20 21:08:02 -04:00
|
|
|
noSub = true;
|
2023-09-16 09:46:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 获取并组合节点分享链接
|
2023-09-20 21:08:02 -04:00
|
|
|
let proxyLines = document
|
|
|
|
.getElementById("proxy")
|
|
|
|
.value.split("\n")
|
|
|
|
.filter((line) => line.trim() !== "");
|
|
|
|
let noProxy = false;
|
2023-09-16 09:46:59 -04:00
|
|
|
// 去除 proxyLines 中空元素
|
|
|
|
proxyLines = proxyLines.map((item) => {
|
2023-09-20 21:08:02 -04:00
|
|
|
if (item !== "") {
|
|
|
|
return item;
|
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
});
|
|
|
|
if (proxyLines.length > 0) {
|
2023-09-20 21:08:02 -04:00
|
|
|
queryParams.push(`proxy=${encodeURIComponent(proxyLines.join(","))}`);
|
2023-09-17 03:52:37 -04:00
|
|
|
} else {
|
2023-09-20 21:08:02 -04:00
|
|
|
noProxy = true;
|
2023-09-17 03:52:37 -04:00
|
|
|
}
|
|
|
|
if (noSub && noProxy) {
|
2023-09-20 21:08:02 -04:00
|
|
|
alert("订阅链接和节点分享链接不能同时为空!");
|
|
|
|
return "";
|
2023-09-16 09:46:59 -04:00
|
|
|
}
|
|
|
|
// 获取复选框的值
|
|
|
|
const refresh = document.getElementById("refresh").checked;
|
2023-09-20 21:08:02 -04:00
|
|
|
queryParams.push(`refresh=${refresh ? "true" : "false"}`);
|
2023-09-16 09:46:59 -04:00
|
|
|
const autoTest = document.getElementById("autoTest").checked;
|
2023-09-20 21:08:02 -04:00
|
|
|
queryParams.push(`autoTest=${autoTest ? "true" : "false"}`);
|
2023-09-16 09:46:59 -04:00
|
|
|
const lazy = document.getElementById("lazy").checked;
|
2023-09-20 21:08:02 -04:00
|
|
|
queryParams.push(`lazy=${lazy ? "true" : "false"}`);
|
2023-09-16 09:46:59 -04:00
|
|
|
|
|
|
|
// 获取模板链接或名称(如果存在)
|
|
|
|
const template = document.getElementById("template").value;
|
|
|
|
if (template.trim() !== "") {
|
2023-09-20 21:08:02 -04:00
|
|
|
queryParams.push(`template=${encodeURIComponent(template)}`);
|
2023-09-16 09:46:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 获取Rule Provider和规则
|
|
|
|
const ruleProviders = document.getElementsByName("ruleProvider");
|
|
|
|
const rules = document.getElementsByName("rule");
|
|
|
|
let providers = [];
|
|
|
|
for (let i = 0; i < ruleProviders.length / 5; i++) {
|
2023-09-20 21:08:02 -04:00
|
|
|
let baseIndex = i * 5;
|
|
|
|
let behavior = ruleProviders[baseIndex].value;
|
|
|
|
let url = ruleProviders[baseIndex + 1].value;
|
|
|
|
let group = ruleProviders[baseIndex + 2].value;
|
|
|
|
let prepend = ruleProviders[baseIndex + 3].value;
|
|
|
|
let name = ruleProviders[baseIndex + 4].value;
|
|
|
|
// 是否存在空值
|
|
|
|
if (
|
|
|
|
behavior.trim() === "" ||
|
|
|
|
url.trim() === "" ||
|
|
|
|
group.trim() === "" ||
|
|
|
|
prepend.trim() === "" ||
|
|
|
|
name.trim() === ""
|
|
|
|
) {
|
|
|
|
alert("Rule Provider 中存在空值,请检查后重试!");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
providers.push(`[${behavior},${url},${group},${prepend},${name}]`);
|
2023-09-16 09:46:59 -04:00
|
|
|
}
|
2023-09-20 21:08:02 -04:00
|
|
|
queryParams.push(
|
|
|
|
`ruleProvider=${encodeURIComponent(providers.join(","))}`,
|
|
|
|
);
|
2023-09-16 09:46:59 -04:00
|
|
|
|
|
|
|
let ruleList = [];
|
|
|
|
for (let i = 0; i < rules.length / 3; i++) {
|
2023-09-20 21:08:02 -04:00
|
|
|
if (rules[i * 3].value.trim() !== "") {
|
|
|
|
let rule = rules[i * 3].value;
|
|
|
|
let prepend = rules[i * 3 + 1].value;
|
|
|
|
let group = rules[i * 3 + 2].value;
|
|
|
|
// 是否存在空值
|
|
|
|
if (
|
|
|
|
rule.trim() === "" ||
|
|
|
|
prepend.trim() === "" ||
|
|
|
|
group.trim() === ""
|
|
|
|
) {
|
|
|
|
alert("Rule 中存在空值,请检查后重试!");
|
|
|
|
return "";
|
2023-09-16 09:46:59 -04:00
|
|
|
}
|
2023-09-20 21:08:02 -04:00
|
|
|
ruleList.push(`[${rule},${prepend},${group}]`);
|
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
}
|
2023-09-20 21:08:02 -04:00
|
|
|
queryParams.push(`rule=${encodeURIComponent(ruleList.join(","))}`);
|
2023-09-16 09:46:59 -04:00
|
|
|
|
|
|
|
// 获取排序策略
|
|
|
|
const sort = document.getElementById("sort").value;
|
|
|
|
queryParams.push(`sort=${sort}`);
|
2023-09-22 11:43:26 -04:00
|
|
|
|
|
|
|
// 获取删除节点的正则表达式
|
|
|
|
const remove = document.getElementById("remove").value;
|
|
|
|
if (remove.trim() !== "") {
|
|
|
|
queryParams.push(`remove=${encodeURIComponent(remove)}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取替换节点名称的正则表达式
|
2023-09-22 12:58:57 -04:00
|
|
|
let replaceList = [];
|
|
|
|
const replaces = document.getElementsByName("replace");
|
|
|
|
for (let i = 0; i < replaces.length / 2; i++) {
|
|
|
|
let replaceStr = `<${replaces[i * 2].value}>`;
|
|
|
|
let replaceTo = `<${replaces[i * 2 + 1].value}>`;
|
|
|
|
if (replaceStr.trim() === "") {
|
|
|
|
alert("重命名设置中存在空值,请检查后重试!");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
replaceList.push(`[${replaceStr},${replaceTo}]`);
|
2023-09-22 11:43:26 -04:00
|
|
|
}
|
2023-09-22 12:58:57 -04:00
|
|
|
queryParams.push(
|
|
|
|
`replace=${encodeURIComponent(replaceList.join(","))}`,
|
|
|
|
);
|
2023-09-22 11:43:26 -04:00
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
return `${endpoint}?${queryParams.join("&")}`;
|
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
function generateURL() {
|
2023-09-17 03:52:37 -04:00
|
|
|
const apiLink = document.getElementById("apiLink");
|
2023-09-20 21:08:02 -04:00
|
|
|
let uri = generateURI();
|
|
|
|
if (uri === "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
apiLink.value = `${window.location.origin}${window.location.pathname}${uri}`;
|
|
|
|
}
|
2023-09-16 09:46:59 -04:00
|
|
|
|
2023-09-20 21:08:02 -04:00
|
|
|
function generateShortLink() {
|
2023-09-17 03:52:37 -04:00
|
|
|
const apiShortLink = document.getElementById("apiShortLink");
|
2023-09-22 11:43:26 -04:00
|
|
|
const password = document.getElementById("password");
|
2023-09-20 21:08:02 -04:00
|
|
|
let uri = generateURI();
|
|
|
|
if (uri === "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
axios
|
|
|
|
.post(
|
|
|
|
"./short",
|
|
|
|
{
|
|
|
|
url: uri,
|
2023-09-22 11:43:26 -04:00
|
|
|
password: password.value.trim(),
|
2023-09-20 21:08:02 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.then((response) => {
|
2023-09-17 03:52:37 -04:00
|
|
|
apiShortLink.value = `${window.location.origin}${window.location.pathname}s/${response.data}`;
|
2023-09-20 21:08:02 -04:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2023-09-17 03:52:37 -04:00
|
|
|
console.log(error);
|
|
|
|
alert("生成短链失败,请重试!");
|
2023-09-20 21:08:02 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
2023-09-16 09:46:59 -04:00
|
|
|
</html>
|