Skip to content

Commit bafed52

Browse files
author
Taois
committed
fix: 显按钮自动锁边
1 parent f7fd1aa commit bafed52

File tree

1 file changed

+88
-10
lines changed

1 file changed

+88
-10
lines changed

public/monkey/clipboard-sender.user.js

Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,18 +1315,66 @@
13151315
}
13161316

13171317
function toggleButtons() {
1318-
// 把除了本身(显按钮)之外的所有按钮切换可见性
13191318
const btn = buttonMap.get('toggle-buttons');
13201319
const nowHidden = Array.from(buttonMap.values()).some(b => b.style.visibility === 'hidden');
13211320
for (const [id, el] of buttonMap) {
13221321
if (id === 'toggle-buttons') continue;
13231322
el.style.visibility = nowHidden ? 'visible' : 'hidden';
13241323
}
1325-
if (btn) {
1326-
btn.textContent = nowHidden ? '隐按钮' : '显按钮';
1327-
btn.style.borderStyle = nowHidden ? 'inset' : 'outset';
1328-
}
13291324
store.set('buttons.hidden', nowHidden ? 0 : 1);
1325+
const hidden = store.get('buttons.hidden', 0) === 1;
1326+
const boxes = columns.columns;
1327+
const btnBox = btn ? btn.parentElement : null;
1328+
if (hidden) {
1329+
for (const [, box] of boxes) {
1330+
if (box !== btnBox) {
1331+
box.style.display = 'none';
1332+
}
1333+
}
1334+
if (btnBox) {
1335+
btnBox.style.position = 'fixed';
1336+
btnBox.style.top = CONFIG.buttonTop + 'px';
1337+
btnBox.style.left = '0px';
1338+
btnBox.style.width = '18px';
1339+
btnBox.style.zIndex = ZIndexManager.getNextZIndex();
1340+
}
1341+
if (btn) {
1342+
btn.textContent = '<<';
1343+
btn.style.borderStyle = 'inset';
1344+
btn.style.width = '18px';
1345+
btn.style.minWidth = '18px';
1346+
btn.style.padding = '0';
1347+
btn.style.visibility = 'visible';
1348+
}
1349+
} else {
1350+
for (const [, box] of boxes) {
1351+
box.style.display = '';
1352+
}
1353+
if (btnBox) {
1354+
let colIndex = 1;
1355+
for (const [idx, b] of boxes) {
1356+
if (b === btnBox) {
1357+
colIndex = idx;
1358+
break;
1359+
}
1360+
}
1361+
const offset = getLayoutOffset();
1362+
const left = CONFIG.baseLeft + offset + (colIndex - 1) * CONFIG.columnGap;
1363+
1364+
btnBox.style.position = 'fixed';
1365+
btnBox.style.left = left + 'px';
1366+
btnBox.style.top = CONFIG.buttonTop + 'px';
1367+
btnBox.style.width = CONFIG.columnWidth + 'px';
1368+
btnBox.style.zIndex = 2147483646;
1369+
}
1370+
if (btn) {
1371+
btn.textContent = '隐按钮';
1372+
btn.style.borderStyle = 'inset';
1373+
btn.style.width = '100%';
1374+
btn.style.minWidth = '';
1375+
btn.style.padding = '';
1376+
}
1377+
}
13301378
}
13311379

13321380
function switchTheme() {
@@ -4995,19 +5043,49 @@
49955043
const buttonsHidden = store.get('buttons.hidden', 0) === 1;
49965044
if (buttonsHidden) {
49975045
for (const [id, el] of buttonMap) {
4998-
if (id === 'toggle-buttons') {
4999-
el.textContent = '显按钮';
5000-
el.style.borderStyle = 'outset';
5001-
continue;
5002-
}
5046+
if (id === 'toggle-buttons') continue;
50035047
el.style.visibility = 'hidden';
50045048
}
5049+
const btn = buttonMap.get('toggle-buttons');
5050+
const btnBox = btn ? btn.parentElement : null;
5051+
for (const [, box] of columns.columns) {
5052+
if (box !== btnBox) {
5053+
box.style.display = 'none';
5054+
}
5055+
}
5056+
if (btnBox) {
5057+
btnBox.style.position = 'fixed';
5058+
btnBox.style.top = CONFIG.buttonTop + 'px';
5059+
btnBox.style.left = '0px';
5060+
btnBox.style.width = '18px';
5061+
btnBox.style.zIndex = ZIndexManager.getNextZIndex();
5062+
}
5063+
if (btn) {
5064+
btn.textContent = '<<';
5065+
btn.style.borderStyle = 'inset';
5066+
btn.style.width = '18px';
5067+
btn.style.minWidth = '18px';
5068+
btn.style.padding = '0';
5069+
btn.style.visibility = 'visible';
5070+
}
50055071
} else {
50065072
const btnToggle = buttonMap.get('toggle-buttons');
50075073
if (btnToggle) {
50085074
btnToggle.textContent = '隐按钮';
50095075
btnToggle.style.borderStyle = 'inset';
50105076
}
5077+
for (const [, box] of columns.columns) {
5078+
box.style.display = '';
5079+
}
5080+
const btn = buttonMap.get('toggle-buttons');
5081+
const btnBox = btn ? btn.parentElement : null;
5082+
if (btnBox) {
5083+
btnBox.style.position = '';
5084+
btnBox.style.left = '';
5085+
btnBox.style.top = '';
5086+
btnBox.style.width = CONFIG.columnWidth + 'px';
5087+
btnBox.style.zIndex = '';
5088+
}
50115089
}
50125090

50135091
// 给组内的 toggle 按钮同步初始样式(因为 gp.addButton 已处理,这里确保若你需要同步主按钮的样式也可)

0 commit comments

Comments
 (0)