简体   繁体   English

逆向工程一个 Firefox 扩展

[英]Reverse engineering a Firefox extension

I'm a young developer and am just trying my hand at JavaScript for the first time this week after coming from a background in Java.我是一名年轻的开发人员,在 Java 的背景下,本周第一次尝试 JavaScript。 I found a nice add-on for Firefox that allows users to copy links from selected text.我为 Firefox 找到了一个不错的插件,它允许用户从选定的文本中复制链接。 Its relatively small but I'd like to try configure it so it runs from a button rather than a (rightclick/select event)它相对较小,但我想尝试配置它,使其从按钮而不是(右键单击/选择事件)运行

DISCLAIMER: The extension in question is open source and licensed under GNU General Public License, version 2.0免责声明:有问题的扩展是开源的,并根据 GNU 通用公共许可证 2.0 版获得许可

I'm not reverse engineering anyone's hard work, I'm just trying to figure out what makes add-ons tick and how to apply its workings to something that's not an add-on.我不是对任何人的辛勤工作进行逆向工程,我只是想弄清楚是什么让附加组件生效,以及如何将其工作应用于非附加组件。

The source is available here: https://addons.mozilla.org/en-US/firefox/files/browse/77730/ (it's quite small, just one jar so don't be afraid to read)源码在这里: https://addons.mozilla.org/en-US/firefox/files/browse/77730/ (很小,只有一个jar所以不要害怕阅读)

Back to the point: it's a neat little add-on that allows users to select multiple links in a web page and copy/paste the links selected by right clicking the text and selecting copy selected links.回到正题:它是一个简洁的小插件,允许用户在 web 页面中添加多个链接,然后通过右键单击文本并选择复制选定链接来复制/粘贴选定的链接。

So the 2 parts of my question:所以我的问题的两个部分:

  1. How do I run this type of add-on from a button instead of a right click?如何从按钮而不是右键单击运行这种类型的加载项? (I'm assuming it has something to do with the EOL function) (我假设它与 EOL 功能有关)

  2. Is there anything I need to be aware of when converting add-ons other than cross browser compatibility?除了跨浏览器兼容性之外,在转换附加组件时还有什么需要注意的吗? Should I be contacting the author for help or would that offend?我应该联系作者寻求帮助还是会冒犯?

Any and all help appreciated!任何和所有的帮助表示赞赏!

* * * *

I'm pretty sure I'm passing 'true' to welcome for no reason.我很确定我会无缘无故地通过“真实”来欢迎。 Also pretty sure turning this into an internal type script My small attempt at taking the source and making something out of it:也很确定把它变成一个内部类型脚本我在获取源代码并从中做出一些东西的小尝试:

HTML: HTML:

<input type="button" id="grablinkstest" value="CopyLinks" onclick="welcome(true);"/>

JAVASCRIPT: JAVASCRIPT:

function welcome() {
    alert("welcome command works");
    var focusedWindow = document.commandDispatcher.focusedWindow;
    var focusedDoc = document.commandDispatcher.focusedWindow.document;
    var argc = gCopyLinks.GetLinks.arguments.length;
    var argv = gCopyLinks.GetLinks.arguments;
    var reMask;

    var selLinks = [];
    for( i = 0; i < focusedDoc.links.length; i++) {
        if((!bSelected || focusedWindow.getSelection().containsNode(focusedDoc.links[i], true)) && (argc <= 1 || focusedDoc.links[i].href.match(reMask))) {
            selLinks[j] = focusedDoc.links[i].href;
            j++;
        }
    }

}

How do I run this type of add-on from a button instead of a right click?如何从按钮而不是右键单击运行这种类型的加载项? (I'm assuming it has something to do with the EOL function) (我假设它与 EOL 功能有关)

No, it has nothing to do with the EOL function - this function merely determines the end-of-line character sequence for the operating system used.不,它与EOL function 无关 - 此 function 仅确定所用操作系统的行尾字符序列。 Extension's overlay calls gCopyLinks.OnCommand('all') if its menu item is clicked, I guess you want to add a button doing the same.扩展的覆盖调用gCopyLinks.OnCommand('all')如果它的菜单项被点击,我猜你想添加一个按钮做同样的事情。 See https://developer.mozilla.org/en/XUL_School/Adding_Toolbars_and_Toolbar_Buttons on adding toolbar buttons in extensions.请参阅https://developer.mozilla.org/en/XUL_School/Adding_Toolbars_and_Toolbar_Buttons在扩展中添加工具栏按钮。

Is there anything I need to be aware of when converting add-ons other than cross browser compatibility?除了跨浏览器兼容性之外,在转换附加组件时还有什么需要注意的吗?

Yes.是的。 Extensions have special privileges that web content doesn't have.扩展程序具有 web 内容所没有的特权。 In particular, there is currently no API allowing web applications to copy data to the clipboard.特别是,目前没有 API 允许 web 应用程序将数据复制到剪贴板。 However, one is proposed and being worked on .但是,有人提出正在研究中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM