Skip to content

Commit 52b203a

Browse files
author
Taois
committed
feat: 网页脚本优化
1 parent ef86d67 commit 52b203a

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

public/monkey/clipboard-sender.user.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,20 @@
12561256

12571257
function show(title, html) {
12581258
ensure();
1259+
// 如果只传了一个参数,且是字符串,那么它应该是内容,标题默认为"通知"
1260+
if (html === undefined && typeof title === 'string') {
1261+
html = title;
1262+
title = '通知';
1263+
}
1264+
12591265
titleEl.textContent = title || '通知';
1260-
if (typeof html === 'string') content.innerHTML = html; else {
1266+
1267+
if (html === undefined || html === null) {
1268+
content.innerHTML = '';
1269+
} else if (typeof html === 'string') {
1270+
// 处理换行符,将其转换为 <br>
1271+
content.innerHTML = html.replace(/\n/g, '<br>');
1272+
} else {
12611273
content.innerHTML = '';
12621274
content.append(html);
12631275
}
@@ -4661,7 +4673,7 @@
46614673
overlay.addEventListener('mousedown', handleClick);
46624674

46634675
document.body.appendChild(overlay);
4664-
Toast.show('请点击屏幕任意位置获取坐标\n右键取消', 'info');
4676+
Toast.show('提示', '请点击屏幕任意位置获取坐标\n右键取消');
46654677
}
46664678

46674679
function stop() {
@@ -4676,7 +4688,7 @@
46764688
function cancel(e) {
46774689
e.preventDefault();
46784690
stop();
4679-
Toast.show('已取消坐标拾取');
4691+
Toast.show('提示', '已取消坐标拾取');
46804692
}
46814693

46824694
function handleClick(e) {
@@ -4697,7 +4709,7 @@
46974709
});
46984710
}
46994711

4700-
Toast.show(`坐标: ${x}, ${y}\n已复制代码: ${code}`, 'success');
4712+
Toast.show('拾取成功', `坐标: ${x}, ${y}\n已复制代码: ${code}`);
47014713
console.log(`[CoordinatePicker] Picked: ${x}, ${y}`);
47024714

47034715
stop();
@@ -4740,7 +4752,7 @@
47404752
overlay.addEventListener('mousemove', handleMouseMove);
47414753

47424754
document.body.appendChild(overlay);
4743-
Toast.show('请点击选择输入框或其他元素\n移动鼠标预览,右键取消', 'info');
4755+
Toast.show('提示', '请点击选择输入框或其他元素\n移动鼠标预览,右键取消');
47444756
}
47454757

47464758
function stop() {
@@ -4761,7 +4773,7 @@
47614773
function cancel(e) {
47624774
e.preventDefault();
47634775
stop();
4764-
Toast.show('已取消元素拾取', 'info');
4776+
Toast.show('提示', '已取消元素拾取');
47654777
}
47664778

47674779
function handleMouseMove(e) {
@@ -4812,16 +4824,16 @@
48124824
const success = copyWithGreasemonkey(code);
48134825

48144826
if (success) {
4815-
Toast.show(`已拾取元素: ${selector}\n代码已复制: ${code}`, 'success');
4827+
Toast.show('拾取成功', `已拾取元素: ${selector}\n代码已复制: ${code}`);
48164828
} else {
4817-
Toast.show(`拾取成功: ${selector}\n复制失败,请手动复制控制台输出`, 'warning');
4829+
Toast.show('拾取成功', `拾取成功: ${selector}\n复制失败,请手动复制控制台输出`);
48184830
}
48194831

48204832
console.log(`[ElementPicker] Picked:`, highlightedElement);
48214833
console.log(`[ElementPicker] Selector: ${selector}`);
48224834
console.log(`[ElementPicker] Code: ${code}`);
48234835
} else {
4824-
Toast.show('未选中任何元素', 'warning');
4836+
Toast.show('提示', '未选中任何元素');
48254837
}
48264838

48274839
stop();

0 commit comments

Comments
 (0)