MCPcopy Create free account
hub / github.com/dajie111/nodeseek-userscript / buildToolbar

Function buildToolbar

notes.js:388–1182  ·  view source on GitHub ↗
(cmd)

Source from the content-addressed store, hash-verified

386 }
387
388 function buildToolbar(cmd) {
389 const bar = createElement('div', { className: 'nsn-toolbar' });
390
391 // 选区管理变量
392 let savedRange = null;
393
394 // 保存选区的函数
395 function saveSelection() {
396 const selection = window.getSelection();
397 if (selection && selection.rangeCount > 0) {
398 savedRange = selection.getRangeAt(0).cloneRange();
399 }
400 }
401
402 // 恢复选区的函数
403 function restoreSelection() {
404 if (savedRange) {
405 const selection = window.getSelection();
406 selection.removeAllRanges();
407 selection.addRange(savedRange);
408 }
409 }
410
411 // 为工具栏添加mousedown事件监听器
412 bar.addEventListener('mousedown', (e) => {
413 // 检测是否点击了颜色容器
414 if (e.target.closest('.nsn-color-container')) {
415 e.preventDefault();
416 saveSelection();
417 }
418 });
419
420 const addBtn = (txt, title, onclick) => {
421 const b = createElement('button', { className: 'nsn-btn', title }, [txt]);
422 b.addEventListener('click', onclick);
423 bar.appendChild(b);
424 };
425
426 // 字号
427 const sizeSel = createElement('select', { className: 'nsn-select' });
428 ;['12px','14px','16px','18px','24px','32px'].forEach((s)=>{
429 const opt = createElement('option', { value: s }, [s]);
430 if (s === '14px') opt.selected = true;
431 sizeSel.appendChild(opt);
432 });
433 sizeSel.addEventListener('change', () => {
434 cmd('fontSizePx', sizeSel.value);
435 });
436 bar.appendChild(sizeSel);
437
438 addBtn('B', '加粗', () => cmd('bold'));
439 addBtn('I', '斜体', () => cmd('italic'));
440 addBtn('U', '下划线', () => cmd('underline'));
441
442 // 字体颜色选择器容器
443 const fontColorContainer = createElement('div', { className: 'nsn-color-container' });
444 const fontColorPicker = createElement('input', {
445 type: 'color',

Callers 1

buildDialogFunction · 0.85

Calls 13

createElementFunction · 0.85
saveSelectionFunction · 0.85
addBtnFunction · 0.85
restoreSelectionFunction · 0.85
saveColorHistoryFunction · 0.85
updateColorHistoryFunction · 0.85
toggleHistoryPanelFunction · 0.85
hideAllHistoryPanelsFunction · 0.85
escapeHtmlFunction · 0.85
attachResizeListenersFunction · 0.85
showTableConfigDialogFunction · 0.85

Tested by

no test coverage detected