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

Function execCommand

notes.js:2881–2921  ·  view source on GitHub ↗
(action, value)

Source from the content-addressed store, hash-verified

2879 }
2880
2881 function execCommand(action, value){
2882 if (action === 'fontSizePx') {
2883 // 限制字体大小最大为32px
2884 const sizeValue = parseInt(value);
2885 if (sizeValue > 32) {
2886 value = '32px';
2887 }
2888
2889 document.execCommand('fontSize', false, '7');
2890 const fontElements = document.getElementsByTagName('font');
2891 for (let i = 0; i < fontElements.length; i++) {
2892 if (fontElements[i].size === '7') {
2893 fontElements[i].removeAttribute('size');
2894 fontElements[i].style.fontSize = value;
2895 }
2896 }
2897 return;
2898 }
2899 if (action === 'insertHTML') {
2900 // 智能插入HTML内容,无论焦点是否在编辑器内都能正确插入
2901 insertHTMLAtCursor(value);
2902 // 如果插入的是图片容器,添加调整大小功能
2903 if (value.includes('nsn-resizable-img-container')) {
2904 requestAnimationFrame(() => {
2905 attachResizeListeners();
2906 });
2907 }
2908 return;
2909 }
2910 if (action === 'foreColor' || action === 'backColor') {
2911 // 确保编辑器获得焦点
2912 editor.focus();
2913 document.execCommand(action, false, value);
2914 return;
2915 }
2916 if (action === 'createLink' || action === 'insertImage') {
2917 document.execCommand(action, false, value);
2918 return;
2919 }
2920 document.execCommand(action, false, null);
2921 }
2922
2923 // 智能插入HTML内容的函数
2924 function insertHTMLAtCursor(html) {

Callers

nothing calls this directly

Calls 2

insertHTMLAtCursorFunction · 0.85
attachResizeListenersFunction · 0.85

Tested by

no test coverage detected