一些避免覆盖UI的方法(可能类似于firefox中的附加组件)

发布于 2024-12-10 12:44:20 字数 1157 浏览 2 评论 0原文

我一直在开发一个嵌入式小部件(html、css、js),它每 x 秒接收一些文本,并根据正在安装的第 3 方附加组件解释该文本。它与 Firefox 附加系统类似,只是更加简化。 让我举一个例子来说明我想要实现的目标。 我为小部件提供了嵌入代码,以便人们可以将其放在自己的网站上,类似于 Twitter 更新小部件。我还提供了一个小的 api(在 javascript 中),以便人们可以创建一些扩展(附加组件)。例如,如果在每 x 秒加载的文本中出现一个 YouTube 链接,则插件可以将其替换为嵌入的视频,而不是显示该链接。另一个例子是笑脸:例如用图像替换 :)。这个清单还可以继续列下去,但我想你已经明白了。

问题是当 2 个或更多附加组件尝试替换相同的内容时。

例如,假设小部件加载以下文本:http://www.youtube.com/watch? v=video_id ,一个插件尝试用视频替换文本,另一个插件尝试用相关图像缩略图替换文本。

如何解决两个附加组件之间的干扰。我也很感兴趣 Firefox 如何在其附加系统上处理这种情况。我读过他们的一些关于 XUL 覆盖的文档,但我没有找到任何关于这种情况的信息。在他们的文档页面上: https://developer.mozilla.org/en/XUL_Overlays 他们说XUL 覆盖可用于:

  • 为其他组件添加 UI,如上面的示例中所述
  • 覆盖 XUL 文件的一小部分,而不必
  • 重新提供整个 UI 重用 UI 的特定部分

我更感兴趣的是最后2,在上面解释的情况下,但没有任何运气。我也在谷歌上搜索过,但没有找到任何东西。

到目前为止,我能想到的唯一解决方案是建立一种机制,可以发现 2 个或更多附加组件是否覆盖相同的 UI,并通知用户(想要在其网站上安装小部件的用户)禁用其中一个附加组件。如果这是唯一的解决方案,我也对您关于如何实现这一目标的想法感兴趣。

注意:插件不一定是由将小部件放在其网站上的人完成的。它将是一个类似于 Firefox 附加组件的系统,用户可以选择要安装的附加组件,然后只需将代码复制粘贴到他的网站中。

I've been working on a embedded widget(html,css,js) that receives some text every x seconds and interpret that text depending on what 3rd party add-ons are being installed. It is something similar with firefox add-ons system only much simplified.
Let me give you an example of what I'm trying to achieve.
I provide an embedded code for a widget, so that people can put it on their sites, similar with twitter updates widget. I also provide a small api(in javascript) so that people can create some extensions(add-ons). For example if in the text that is loaded every x seconds appears a youtube link , instead of showing the link, the addon can replace it with the embedded video. Another example are smileys: replace :) for example with an image. The list can go on, but I think you got the picture.

The problem is that when 2 or more add-ons try to replace the same content.

For example let say the widget loads the following text: http://www.youtube.com/watch?v=video_id and one add-on tries to replace the text with the video and the other add-on tries to replace it with the related image thumb.

How can I solve the interference between 2 add-ons. I'm also interested how firefox deals with this situation on their add-ons system. I've read some of their documentation about XUL overlays but I didn't find anything about this situation. On their documentation page: https://developer.mozilla.org/en/XUL_Overlays they said the XUL overlays can be used for:

  • adding UI for additional components, as described in the example
  • above overriding small pieces of a XUL file without having to
  • resupply the whole UI reusing particular pieces of the UI

I'm interested more in the last 2, in the situation explained above, but without any luck. I've also searched on google, but didn't find anything.

So far the only solution I can think of is to make a mechanism that can find if 2 or more add-ons overwrite the same UI and notify the user(the one that wants to install the widget on his site) to disable one of the add-ons. If this is the only solution, I'm also interested in your ideas on how to achieve this.

NOTE: The add-ons are not necessary done by the person who put the widget on his site. It will will a system similar to firefox add-ons where the user choose what addons to install and then just copy -paste the code into his site.

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

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

发布评论

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

评论(1

寻找我们的幸福 2024-12-17 12:44:20

我不确定这是否是您正在寻找的,但我可以想到这样的解决方案:

1)为要替换的每种类型的内容创建某种标识符。例如

  • YOUTUBE_LINK
  • SOME_SMILEY
  • SOME_OTHER_SMILEY

2) 当应用程序启动时,附加组件会注册到每种类型的替换中。因此,存在全局可用的集合/数组/任何集合类型,并注册了附加组件来处理不同类型的文本。
更具体地说,有一个映射(关联数组),用 Java 表示法进行映射:

InputText => Set

例如,基于字符串和数组(这是在每个插件动态添加之后;顺序无关紧要)

listeners["YOUTUBE_LINK"] = ["addon1", "addon7"];
listeners["SOME_SMILEY"] = ["addon2", "addon7", "addon9"]

3) 插件具有 ID,表示它们处理输入的“优先级” ,或者它是以某种方式可配置的(全局每个应用程序,或每个插件,它们应该在不同类型的内容上运行的顺序)。

例如
应用程序配置中的某些内容:

order["YOUTUBE_LINK"] = ["addon7", "addon3", "addon5", "addon1"]

这意味着,如果安装了 addon7,则使用它来处理 youtube 链接;如果没有,则使用addon3;如果没有 addon3,则使用 addon5 等等...

问题是,如果您不知道正在开发的所有可能的插件,则无法像这样使用它。
您可以做的是,等待所有插件加载,然后向用户显示信息:
“addon1”和“addon7”想要处理 Youtube 链接,您想选择哪一个? (单击某项,然后存储设置,或让用户将其写在脚本中)。

这是一种愚蠢的方式(但也许不是那么多,如果插件的行为严格相同),每个插件内部都可以有一些 ID,并且根据哪个插件的 ID 最高,它执行操作。

关于 Firefox,如果有两个相互竞争的插件试图完成类似的工作,通常会导致不兼容......当然,这取决于插件的努力是否可以结合起来。但基本上,你必须以某种方式保证事物的顺序,否则它可能会变得随机,这绝对不是好方法。

I'm not sure if this is what you're looking for, but I can think of the solution like that:

1) Create some kind of identifiers for each type of contents that are being replaced. E.g.

  • YOUTUBE_LINK
  • SOME_SMILEY
  • SOME_OTHER_SMILEY

2) When the application starts, add-ons register to each type of replacement. So there is globally available set/array/whatever collection type, having registered add-ons to handling different types of texts.
More specifically, there is a map (associative array), that maps, in Java notation:

InputText => Set<AddOn>

For instance, basing on strings and arrays (this is after adding it dynamically by each addon; order doesn't matter)

listeners["YOUTUBE_LINK"] = ["addon1", "addon7"];
listeners["SOME_SMILEY"] = ["addon2", "addon7", "addon9"]

3) The addons either have IDs that mean their "priority" of handling the inputs, or it is somehow configurable (either per-application globally, or per-addon, the order in which they should run over different kinds of contents).

E.g.
Something in the configuration of the app:

order["YOUTUBE_LINK"] = ["addon7", "addon3", "addon5", "addon1"]

which means, if addon7 is installed, then use it to process youtube links; if no, use addon3; if no addon3, use addon5 and so on...

The problem is that if you don't know about all possible addons being developed, you can't use it like that.
What you can do is, wait for all addons to load, and then display information to the user:
"addon1" and "addon7" want to process Youtube links, which one do you want to do this? (click something, and then store the setting, or make user write it down in the script).

The foolish way (but maybe not so much, if the behaviors of addons are strictly the same), that each addon can have some ID inside of it, and depending on which one has the highest ID, it performs the action.

About Firefox, if there are two competing addons trying to do similar jobs, it often ends up in incompatibility... Depending of course if the efforts of the addons can or can not be combined. But basically, you have to assure some way of the order of the things, otherwise it can end up random, which is definitely not the good way.

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