Skip to content

Instantly share code, notes, and snippets.

@ruter
Last active May 28, 2025 06:29
Show Gist options
  • Save ruter/2a1203c15cf8fce53c6d050858eb2df6 to your computer and use it in GitHub Desktop.
Save ruter/2a1203c15cf8fce53c6d050858eb2df6 to your computer and use it in GitHub Desktop.
Qinglong API script template for QuantumultX.
/**
* @fileoverview Quantumult X script contains Qinglong API methods.
*
* @supported Quantumult X Tunnel (v1.0.25)
*/
const QL_URL = "https://example.com"
const QL_CLIENT_ID = ""
const QL_CLIENT_SECRET = ""
let data = {
token: "",
envs: {},
}
let headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 18_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0.1 Mobile/22A3370 Safari/604.1"
}
/**
* 获取 Token
*/
async function getToken() {
const payload = {
url: `${QL_URL}/open/auth/token?client_id=${QL_CLIENT_ID}&client_secret=${QL_CLIENT_SECRET}`,
method: "GET",
headers: headers,
body: "{}"
}
$task.fetch(payload).then(response => {
const result = JSON.parse(response.body);
data["token"] = result.data.token;
headers["Authorization"] = `Bearer ${result.data.token}`;
}, reason => {
$notify("青龙", "获取Token失败", reason.error);
$done();
});
}
/**
* 获取环境变量 ID
* @param {String} name
*/
async function searchEnv(name) {
const payload = {
url: `${QL_URL}/open/envs?searchValue=${name}`,
method: "GET",
headers: headers,
body: "{}"
}
$task.fetch(payload).then(response => {
const result = JSON.parse(response.body);
if (result.data.length) {
data.envs[name] = result.data[0].id;
}
}, reason => {
$notify("青龙", "获取环境变量失败", reason.error);
$done();
});
}
/**
* 更新环境变量
* @param {String} name
* @param {String} value
*/
async function updateEnv(name, value) {
const payload = {
url: `${QL_URL}/open/envs`,
method: "PUT",
headers: headers,
body: JSON.stringify({
id: data.envs[name],
name: name,
value: value
})
}
$task.fetch(payload).then(response => {
const result = JSON.parse(response.body);
if (result.code == 200) {
$notify("青龙", name, "环境变量更新成功");
}
}, reason => {
$notify("青龙", "更新环境变量失败", reason.error);
$done();
});
}
/**
* 创建环境变量
* @param {String} name
* @param {String} value
*/
async function createEnv(name, value) {
const payload = {
url: `${QL_URL}/open/envs`,
method: "POST",
headers: headers,
body: JSON.stringify([{
name: name,
value: value
}])
}
$task.fetch(payload).then(response => {
const result = JSON.parse(response.body);
if (result.code == 200) {
$notify("青龙", name, "环境变量创建成功");
}
}, reason => {
$notify("青龙", "创建环境变量失败", reason.error);
$done();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment