如何为 Safari 开发插件?
我希望每当我在 Safari 中加载页面时都会执行一些个人开发的 JavaScript 代码。 Safari 的 addblock 似乎就是这样做的。 有人知道怎么做吗?
Safari 不可扩展。 它没有插件框架。 不过,尽管苹果的 Webkit 和 Safari 开发者不鼓励用户使用它们,称其为“二进制黑客”,但仍有 adblock 和许多其他插件可供使用。 似乎其中一些插件使用了 InputManager,但它在任何地方都没有记录,至少没有说明人们如何使用它在 Safari 中加载脚本。 我想我将不得不进行反向工程来了解 addblock 是如何做到这一点的,但在我这样做之前,我想我应该在这里问一下。 有人知道吗?
I want some personally developed JavaScript code to execute whenever I load a page in Safari. Seems like addblock for Safari does this. Anyone know how to do this?
Safari is not extensible. There's no addon framework for it. But yet there's adblock and verious other addons available for it, although Apple's Webkit and Safari developers discourage users from using them, calling them 'binary hacks'. Seems though some of these addons use InputManager, which isn't documented at all anywhere, at least for not for how people are using it to load scripts in Safari. I guess I'm going to have to backwards engineer to see how addblock does it, but before I do, I thought I'd ask around here. Anyone know?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
输入管理器是将任意代码注入另一个应用程序运行时的常用(滥用)方法。 一旦到达那里,您必须对应用程序本身进行足够的逆向工程,以找出如何获得您想要的行为; 通常这涉及方法混合以替换您正在破解的应用程序的部分。 它没有被记录,因为没有 API 来记录,但你可以了解各个部分(一般如何编写输入管理器、Objective C 中的方法混合如何工作、如何使用类转储等工具),然后将其全部包含在内一起。
不过,您所描述的内容听起来像 Greasemonkey,并且至少已经有一两个黑客可以在 Safari 中启用类似 Greasemonkey 的行为。 我建议先看看其中一个是否满足您的需求。
Input managers are a commonly (ab)used way of injecting arbitrary code into another application's runtime. Once you are there, you have to reverse-engineer enough of the application itself to figure out how to get the behavior you want; usually that involves method swizzling to replace parts of the application you are hacking. It's not documented because there's no API to document, but you can learn about the individual pieces (how to write an input manager in general, how method swizzling in Objective C works, how to use tools like class-dump) and then put it all together.
What you are describing sounds like Greasemonkey though, and there are least one or two hacks already out there to enable Greasemonkey-like behavior in Safari. I'd suggest seeing if one of them meets your needs first.