|
1315 | 1315 | } |
1316 | 1316 |
|
1317 | 1317 | function toggleButtons() { |
1318 | | - // 把除了本身(显按钮)之外的所有按钮切换可见性 |
1319 | 1318 | const btn = buttonMap.get('toggle-buttons'); |
1320 | 1319 | const nowHidden = Array.from(buttonMap.values()).some(b => b.style.visibility === 'hidden'); |
1321 | 1320 | for (const [id, el] of buttonMap) { |
1322 | 1321 | if (id === 'toggle-buttons') continue; |
1323 | 1322 | el.style.visibility = nowHidden ? 'visible' : 'hidden'; |
1324 | 1323 | } |
1325 | | - if (btn) { |
1326 | | - btn.textContent = nowHidden ? '隐按钮' : '显按钮'; |
1327 | | - btn.style.borderStyle = nowHidden ? 'inset' : 'outset'; |
1328 | | - } |
1329 | 1324 | 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 | + } |
1330 | 1378 | } |
1331 | 1379 |
|
1332 | 1380 | function switchTheme() { |
|
4995 | 5043 | const buttonsHidden = store.get('buttons.hidden', 0) === 1; |
4996 | 5044 | if (buttonsHidden) { |
4997 | 5045 | 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; |
5003 | 5047 | el.style.visibility = 'hidden'; |
5004 | 5048 | } |
| 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 | + } |
5005 | 5071 | } else { |
5006 | 5072 | const btnToggle = buttonMap.get('toggle-buttons'); |
5007 | 5073 | if (btnToggle) { |
5008 | 5074 | btnToggle.textContent = '隐按钮'; |
5009 | 5075 | btnToggle.style.borderStyle = 'inset'; |
5010 | 5076 | } |
| 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 | + } |
5011 | 5089 | } |
5012 | 5090 |
|
5013 | 5091 | // 给组内的 toggle 按钮同步初始样式(因为 gp.addButton 已处理,这里确保若你需要同步主按钮的样式也可) |
|
0 commit comments