function activate() { // let protyle_wysiwyg = document.querySelectorAll('div.layout__wnd--active div.protyle:not(.fn__none) div.protyle-wysiwyg'); // let protyle_wysiwyg = document.querySelectorAll( // "div.protyle:not(.fn__none) div.protyle-wysiwyg" // ); let protyle_wysiwyg = document.querySelectorAll( "div.protyle div.protyle-wysiwyg" ); // let protyle_wysiwyg = document.querySelectorAll( // ".protyle" // ); if (protyle_wysiwyg.length > 0) { for (let editor of protyle_wysiwyg) { editor.onkeyup = (e, t) => { editor.style.marginBottom = window.screen.availHeight/2 + "px"; let block = null; // 当前页面 let page = editor.parentElement; // let page = document.activeElement.parentElement; if (document.activeElement.nodeName == "TABLE") { // 表格获取焦点 block = window.getSelection().focusNode.parentElement; while (block != null && block.nodeName != "TD") block = block.parentElement; } else { block = window.getSelection().focusNode.parentElement; // 当前光标 while (block != null && block.dataset.nodeId == null) block = block.parentElement; } if (block == null || page == null) return; let block_height = block.clientHeight; // 当前块的高度 let block_bottom = block.getBoundingClientRect().bottom; // 当前块的底部 let page_height = page.clientHeight; // 当前页面的高度 let page_bottom = page.getBoundingClientRect().bottom; // 当前页面的底部 // console.log(block_height, block_bottom, page_height, page_bottom); page.style.scrollBehavior = "smooth"; page.scrollBy( 0, -(page_bottom - page_height / 2 - (block_bottom - block_height / 2)) ); }; } } } function deactivate() { let protyle_wysiwyg = document.querySelectorAll( "div.protyle:not(.fn__none) div.protyle-wysiwyg" ); if (protyle_wysiwyg.length > 0) { for (let editor of protyle_wysiwyg) { editor.onkeyup = (e, t) => {}; } } } var sync = document.getElementById("barSync"); sync.insertAdjacentHTML( "afterend", '<div id="type"class="toolbar__item b3-tooltips b3-tooltips__se"></div>' ); var typ = document.getElementById("type"); typ.style.width = "auto"; var unenbleIcon = '<svg t="1647999956702" class="icon" style="display: block;"viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1685" width="20" height="32"><path d="M886.3 917.9H133.4c-18.5 0-35.9-8.2-47.7-22.4S69 862.6 72.5 844.4L122 581.1c5.5-29.3 31.1-50.6 60.9-50.6h654.7c29.9 0 55.5 21.4 61 50.8l48.6 263.2c3.4 18.2-1.5 36.8-13.3 51-11.8 14.3-29.1 22.4-47.6 22.4zM182.9 553c-19 0-35.4 13.6-38.9 32.2L94.5 848.6c-2.2 11.6 0.9 23.5 8.4 32.6 7.5 9.1 18.6 14.3 30.4 14.3h752.9c11.8 0 22.8-5.2 30.4-14.3 7.5-9.1 10.6-20.9 8.5-32.6l-48.6-263.2c-3.5-18.8-19.9-32.4-39-32.4H182.9z" fill="#bfbfbf" p-id="1686"></path><path d="M747 658.7H509.8c-6.2 0-11.2-5-11.2-11.2s5-11.2 11.2-11.2H747c6.2 0 11.2 5 11.2 11.2s-5 11.2-11.2 11.2zM812.6 801.9H207.1c-6.2 0-11.2-5-11.2-11.2s5-11.2 11.2-11.2h605.5c6.2 0 11.2 5 11.2 11.2s-5 11.2-11.2 11.2zM724.5 553H295.1V77.8h429.5V553z m-407-22.4H702V100.2H317.5v430.4z" fill="#bfbfbf" p-id="1687"></path><path d="M309.9 658.8H265c-6.2 0-11.2-5.1-11.2-11.2 0-6.2 5.1-11.2 11.2-11.2h44.9c6.2 0 11.2 5.1 11.2 11.2s-5 11.2-11.2 11.2zM437.9 658.8H393c-6.2 0-11.2-5.1-11.2-11.2 0-6.2 5.1-11.2 11.2-11.2h44.9c6.2 0 11.2 5.1 11.2 11.2 0.1 6.1-5 11.2-11.2 11.2z" fill="#bfbfbf" p-id="1688"></path></svg>'; var enbleIcon = '<svg t="1647999956702" style="display: block;"class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1685" width="20" height="32"><path d="M886.3 917.9H133.4c-18.5 0-35.9-8.2-47.7-22.4S69 862.6 72.5 844.4L122 581.1c5.5-29.3 31.1-50.6 60.9-50.6h654.7c29.9 0 55.5 21.4 61 50.8l48.6 263.2c3.4 18.2-1.5 36.8-13.3 51-11.8 14.3-29.1 22.4-47.6 22.4zM182.9 553c-19 0-35.4 13.6-38.9 32.2L94.5 848.6c-2.2 11.6 0.9 23.5 8.4 32.6 7.5 9.1 18.6 14.3 30.4 14.3h752.9c11.8 0 22.8-5.2 30.4-14.3 7.5-9.1 10.6-20.9 8.5-32.6l-48.6-263.2c-3.5-18.8-19.9-32.4-39-32.4H182.9z" fill="#1f2339" p-id="1686"></path><path d="M747 658.7H509.8c-6.2 0-11.2-5-11.2-11.2s5-11.2 11.2-11.2H747c6.2 0 11.2 5 11.2 11.2s-5 11.2-11.2 11.2zM812.6 801.9H207.1c-6.2 0-11.2-5-11.2-11.2s5-11.2 11.2-11.2h605.5c6.2 0 11.2 5 11.2 11.2s-5 11.2-11.2 11.2zM724.5 553H295.1V77.8h429.5V553z m-407-22.4H702V100.2H317.5v430.4z" fill="#1f2339" p-id="1687"></path><path d="M309.9 658.8H265c-6.2 0-11.2-5.1-11.2-11.2 0-6.2 5.1-11.2 11.2-11.2h44.9c6.2 0 11.2 5.1 11.2 11.2s-5 11.2-11.2 11.2zM437.9 658.8H393c-6.2 0-11.2-5.1-11.2-11.2 0-6.2 5.1-11.2 11.2-11.2h44.9c6.2 0 11.2 5.1 11.2 11.2 0.1 6.1-5 11.2-11.2 11.2z" fill="#1f2339" p-id="1688"></path></svg>'; if (localStorage.getItem("typrt") == null) { localStorage.setItem("typrt", "false"); } if (localStorage.getItem("typrt") == "false") { typ.innerHTML = unenbleIcon; } else if (localStorage.getItem("typrt") == "true") { typ.innerHTML = enbleIcon; document.body.onclick = activate; } typ.onclick = (e) => { // var typ = document.getElementById("type"); // console.log(typ); if (localStorage.getItem("typrt") == "false") { localStorage.setItem("typrt", "true"); typ.innerHTML = enbleIcon; document.body.onclick = activate; } else if (localStorage.getItem("typrt") == "true") { localStorage.setItem("typrt", "false"); typ.innerHTML = unenbleIcon; document.body.onclick = null; deactivate(); } };
加到 theme.js 文件后面,按钮亮起即为开启,再点一次就是关闭.
利用 localStorage 存储当前模式是否开启不知道是不是有副作用.
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于