修改Google文档中的链接气泡(通过Google Apps脚本)

发布于 2025-01-21 16:21:06 字数 1303 浏览 0 评论 0原文

在我的Google文档加载项(用Google Apps脚本编写)中,我想在文档中的某些部分添加自定义链接(这很容易执行),我希望这些链接具有不同的内容”链接气泡“(类似小型工具提示的弹出窗口)将光标放入这样的文本中时。也就是说:默认链接气泡版本显示了修改/删除链接的链接和选项。我只想有一个自定义名称,没有任何选择来修改/删除链接。

我认为这是通过记录的选项是不可能的,到目前为止,我只能想到两个解决方法。首先是将书签符号用于链接,以便我可以真正给它任何自定义文本(例如“ #我自己的链接bubble text”)。但是,这仍然允许修改/删除链接。

另一个选择是操纵HTML DOM,因此是一个更通用的解决方案(但这也可以解决我的问题)。 在这里。但是,这是可能的,因为至少 zotero 已经实现了这一点。 They successfully access and modify various HTML elements of the Google Doc editor, including the

例如,在以下代码中,如果我在附加脚本(客户端代码)中使用它,则body {背景:red; }使我的侧栏红色的正文,但.kix-appView-editor {background:green! }没有区别。但是,这不是代码中的错误,因为如果我使用Google文档编辑器打开了控制台中的相同行,则编辑器的背景会更改为Green。 (我也尝试了其他各种操作,但是所有这些都相同。)因此,Google似乎以某种方式阻止了从Google Apps脚本中使用的这种刺激性解决方案 - 但是,Zotero如何如何摆脱它?

const addCSS = css => document.head.appendChild(document.createElement("style")).innerHTML = css;
addCSS(
    `
    body { background:red; }
    .kix-appview-editor { background:green !important; }
    `
); 

无论如何,我欢迎任何解决链接泡沫修改问题的想法(有或没有操纵)。

In my add-in for Google Docs (written in Google Apps Script), I want to add custom links to certain parts of the text in the document (which is easy to do), and I'd like these to have a different "link bubble" (the small temporary tooltip-like pop-up window) when the cursor is placed into such a text. That is: the default link bubble version shows the link and options to modify/remove the link. I want to have just a custom name and no option to modify/remove link.

I do not think this is possible via documented options, and so far I can only think of two workarounds. The first is to use bookmark notation for the link so that I can give it really any custom text (such as "# My own link bubble text"). However, this still allows modification/removal of the link.

The other option is to manipulate the HTML DOM, hence a much more generic solution (but which would solve my issue too). This has been asked here, and so far the answer is that it's not possible. However, it must be possible because at the very least Zotero has implemented this. They successfully access and modify various HTML elements of the Google Doc editor, including the link bubble. However, I do not understand how they can do this. I can easily modify the DOM of my add-in's sidebar, but not the editor's.

For example, in the following code, if I use it in my add-on script (client side code), body { background:red; } makes the body of my sidebar red, but .kix-appview-editor { background:green !important; } makes no difference. However, this is not a mistake in the code, because if I enter the very same lines in the console with the Google Docs editor open, the editor's background changes to green. (I've tried various other manipulations as well, but all had this same result.) So it would seem that Google somehow prevents this sort of hacky solution working from Google Apps Script – but then, again, how did Zotero get away with it?

const addCSS = css => document.head.appendChild(document.createElement("style")).innerHTML = css;
addCSS(
    `
    body { background:red; }
    .kix-appview-editor { background:green !important; }
    `
); 

In any case, I'd welcome any ideas for solving the link bubble modification question (with or without DOM manipulation).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2025-01-28 16:21:06

您无法从应用程序脚本中修改文档编辑器DOM。

您可以通过创建 browserextension 。这就是Zotero's

但是,正如Zotero代码注释中指出的那样,您必须注意,如果Google更改编辑器DOM,则浏览器扩展可能会破裂。

You can't modify the Docs editor DOM from within Apps Script.

You could do so by creating a browser extension. That's what Zotero's connector is. A browser extension has access to the entire DOM on the page, not just the sidebar DOM as you do from Apps Script.

However, as noted in the Zotero code comments, you have to be mindful that if Google changes the editor DOM, your browser extension may break.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文