setTimeout(() => {
if(!window.siyuan?.mobile) return;
const targetButton = document.querySelector('#editor .protyle-breadcrumb [data-type="exit-focus"]');
if (!targetButton) return;
targetButton.insertAdjacentHTML('afterend', `<a class="block__icon fn__flex-center ariaLabel" aria-label="链接2" data-type="link2" href="siyuan://blocks/20250627184916-xhmqiqj"><svg><use xlink:href="#iconOpenWindow"></use></svg></a>`);
const link2 = targetButton.nextElementSibling;
targetButton.insertAdjacentHTML('afterend', `<a class="block__icon fn__flex-center ariaLabel" aria-label="链接" data-type="link" href="siyuan://blocks/20250627184916-xhmqiqj"><svg><use xlink:href="#iconOpenWindow"></use></svg></a>`);
const link = targetButton.nextElementSibling;
targetButton.insertAdjacentHTML('afterend', `<button class="block__icon fn__flex-center ariaLabel" aria-label="大纲" data-type="outline"><svg><use xlink:href="#iconAlignCenter"></use></svg></button>`);
const outline = targetButton.nextElementSibling;
targetButton.insertAdjacentHTML('afterend', `<button class="block__icon fn__flex-center ariaLabel" aria-label="文档树" data-type="docTree"><svg><use xlink:href="#iconFiles"></use></svg></button>`);
const tree = targetButton.nextElementSibling;
link.addEventListener('click', ()=>{
// 在这里修改你的块id 👇👇👇
openBlock('20250519181309-2n6qhdj');
});
link2.addEventListener('click', ()=>{
// 在这里修改你的块id 👇👇👇
openBlock('20250807172700-e1jsytg');
});
tree.addEventListener('click', ()=>{
click('#toolbarFile');
click('[data-type="sidebar-file-tab"]');
});
outline.addEventListener('click', ()=>{
click('#toolbarFile');
click('[data-type="sidebar-outline-tab"]');
});
function click(el) {
if(typeof el === 'string') el = document.querySelector(el);
el.dispatchEvent(new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
}));
}
function openBlock(id) {
const wysiwyg = document.querySelector('#editor .protyle-wysiwyg');
if(!wysiwyg) return;
const html = `<span class="protyle-custom open-block-link" data-type="a" data-href="siyuan://blocks/${id}" style="display:none;"></span>`;
wysiwyg.insertAdjacentHTML('beforeend', html);
const link = wysiwyg.querySelector('.open-block-link');
link.click();
link.remove();
}
}, 2000);
相关帖子
-
wilsons •付费者 捐赠者
- 其他回帖
-
-
你不都实现了吗?无非多加一个复制到剪切板而已,把 openBlock()换成 copyPlainText()即可。
要想兼容性好,可以使用下面的代码
async function copyPlainText (text) { text = text.replace(new RegExp("\u200b", "g"), ""); // `复制纯文本` 时移除所有零宽空格 https://github.com/siyuan-note/siyuan/issues/6674 await writeText(text); } // see https://github.com/siyuan-note/siyuan/blob/5f0f4e3ba6aabd5af26f9879695e5b9b796b5fb9/app/src/protyle/util/compatibility.ts#L129C14-L129C24 function writeText(text) { let range; if (getSelection().rangeCount > 0) { range = getSelection().getRangeAt(0).cloneRange(); } try { // navigator.clipboard.writeText 抛出异常不进入 catch,这里需要先处理移动端复制 if (isInAndroid()) { window.JSAndroid.writeClipboard(text); return; } if (isInHarmony()) { window.JSHarmony.writeClipboard(text); return; } if (isInIOS()) { window.webkit.messageHandlers.setClipboard.postMessage(text); return; } navigator.clipboard.writeText(text); } catch (e) { if (isInIOS()) { window.webkit.messageHandlers.setClipboard.postMessage(text); } else if (isInAndroid()) { window.JSAndroid.writeClipboard(text); } else if (isInHarmony()) { window.JSHarmony.writeClipboard(text); } else { const textElement = document.createElement("textarea"); textElement.value = text; textElement.style.position = "fixed"; //avoid scrolling to bottom document.body.appendChild(textElement); textElement.focus(); textElement.select(); document.execCommand("copy"); document.body.removeChild(textElement); if (range) { focusByRange(range); } } } function isInAndroid() { return window.siyuan.config.system.container === "android" && window.JSAndroid; } function isInIOS() { return window.siyuan.config.system.container === "ios" && window.webkit?.messageHandlers; } function isInHarmony() { return window.siyuan.config.system.container === "harmony" && window.JSHarmony; } }调用方式,比如复制块超级链接
await copyPlainText(`siyuan://blocks/20250807172700-e1jsytg`);
复制为 Markdown 链接
await copyPlainText(`[你的块内容](siyuan://blocks/20250807172700-e1jsytg)`);
1 回复 - 查看全部回帖



