Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
72 lines (72 loc) · 3.58 KB
/
Copy pathindex.html
File metadata and controls
72 lines (72 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>发布到小红书</title>
<style>
body { font-family: -apple-system, sans-serif; padding: 24px; line-height: 1.6; text-align: center; }
button.btn { display: block; margin: 40px auto 0; padding: 22px 20px; border: none; cursor: pointer;
background: #ff2442; color: #fff; border-radius: 14px;
font-size: 24px; font-weight: 600; width: 100%; max-width: 320px; }
.hint { color: #888; margin-top: 20px; font-size: 14px; }
.err { color: #c00; margin-top: 20px; font-size: 15px; display: none; }
</style>
</head>
<body>
<h2>发布到小红书</h2>
<button class="btn" id="go">📲 下载视频并发布</button>
<div class="hint" id="hint">正在准备快捷指令…</div>
<div class="err" id="err"></div>
<script>
(function () {
// data = JSON 串 {"drive_id":"...","title":"...","shortcut_name":"..."},来自 Telegram 按钮 URL 的 ?data=
var data = new URLSearchParams(location.search).get('data') || '';
var hint = document.getElementById('hint');
var err = document.getElementById('err');
var payload;
try {
payload = JSON.parse(data);
} catch (e) {
err.textContent = '发布参数无效,请返回 Telegram 重新打开。';
err.style.display = 'block';
return;
}
var shortcutName = String(payload.shortcut_name || '').trim();
if (!/^[\u4e00-\u9fffA-Za-z0-9 _-]{1,32}$/.test(shortcutName)) {
err.textContent = '快捷指令名称无效,请返回 Telegram 重新打开。';
err.style.display = 'block';
return;
}
hint.textContent = '正在自动拉起「' + shortcutName + '」…(若停在此页,点上面按钮)';
var name = encodeURIComponent(shortcutName);
// 自动路径:把 data 直接塞进 shortcuts:// 的 text=,加载即跳转,无需手势、无需写剪贴板。
// 快捷指令 Get dictionary from Shortcut Input 会把这段文本解析成字典。
var textTarget = 'shortcuts://run-shortcut?name=' + name + '&input=text&text=' + encodeURIComponent(data);
// 兜底路径:真实点击时写剪贴板 + input=clipboard(已验证可靠)。
var clipTarget = 'shortcuts://run-shortcut?name=' + name + '&input=clipboard';
// 尝试关闭本页(Telegram 内置浏览器 tab)——尽力而为,浏览器可能不允许
function dismiss() {
try { window.close(); } catch (e) {}
try { window.open('', '_self'); window.close(); } catch (e) {}
}
// 加载即自动拉起(Telegram 内置浏览器允许加载时跳自定义协议)
location.href = textTarget;
// 拉起后、以及用户从快捷指令/小红书切回本页时,尝试把本页关掉,免得挡住复制按钮
setTimeout(dismiss, 600);
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'visible') dismiss();
});
window.addEventListener('pageshow', dismiss);
// 若没被自动拉起,用户点按钮:走可靠的剪贴板路径
document.getElementById('go').addEventListener('click', function () {
navigator.clipboard.writeText(data).then(function () { location.href = clipTarget; })
.catch(function () {
err.textContent = '写剪贴板失败。请点右上角「···」→「用 Safari 打开」后重试。';
err.style.display = 'block';
});
});
})();
</script>
</body>
</html>