如何制作Greasemonkey脚本来自动下载文件? [英] How can I make a Greasemonkey script to auto-download a file?

查看:140
本文介绍了如何制作Greasemonkey脚本来自动下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我转到页面,它有1个zip文件,但我不知道名字,除了 .zip



我希望Greasemonkey自动下载此zip文件,也许使用flashgot或其他东西?



所以我需要它在页面加载时激活,然后查找 * .zip ,并自动将其添加到下载。



任何想法?

解决方案

Greasemonkey本身不能自动将zip文件或其他任何东西保存到本地文件系统。

这是设计上的;允许用户/页面JavaScript保存文件是一个经过验证的安全灾难。



您的选择:


  1. 让Greasemonkey选择正确的链接并打开文件保存对话框(保存搜索工作并单击一下)。

  2. 让GM将zip文件中继到你的自己的服务器。然后,您的服务器应用程序可以自动保存文件。

    请注意,服务器可能是您自己的机器,运行类似将文件发送到您的Web应用程序 - 您必须编写。然后,Web应用程序可以自动将文件保存到服务器。您可以将本地计算机设置为服务器。



    有关此方法的更多帮助, 阅读此 ,然后提出新问题。






    选项3,编写自己的FF扩展(附加组件):



    如果您决定采用Firefox附加路由,请参阅MDN:正在下载文件



    有关此方法的更多帮助,请 阅读此 ,然后询问一个新问题。


    I go to the page, it has 1 zip file, but I don't know the name, other than its a .zip.

    I want Greasemonkey to download this zip automatically, maybe using flashgot or something?

    So I need it to activate on page load, then look for *.zip, and add that to downloads automatically.

    Any ideas?

    解决方案

    Greasemonkey, by itself, cannot automatically save zip-files, or anything else, to the local file system.
    This is by design; allowing user/page JavaScript to save files is a proven security disaster.

    Your options:

    1. Have Greasemonkey select the right link and open the File-Save dialog (saving you the search effort and 1 click).
    2. Have GM relay the zip file to your own server. Your server application can then automatically save the file.
      Note that the "server" could be your own machine running something like XAMPP.
    3. Write your own Firefox Add-on.


    Option 1, GM only:

    What GM can do is pop open the File-Save dialog for the correct file:

    User interaction will still be required, if only one click.

    For example, suppose the page contains this link:

    <a href="http://Suspicious.com/TotallyOwnYourBankAndCreditCardAccounts.zip">
        Click me, sucka!
    </a>
    

    Then this code will open the File-Save dialog for it:

    var clickEvent      = document.createEvent ('MouseEvents');
    var firstZipFile    = document.querySelector ("a[href*='.zip']");
    
    clickEvent.initEvent ('click', true, true);
    firstZipFile.dispatchEvent (clickEvent);
    


    Option 2, GM and your own server application:

    Greasemonkey can use GM_xmlhttpRequest() to send files to your web application -- which you will have to write. The web app can then save the file to the server automatically. You can set up your local machine to be the server.

    For more help on this approach, read this and then ask a new question.


    Option 3, write your own FF extension (add-on):

    If you decide to take the Firefox add-on route, see "MDN: Downloading files".

    For more help on this approach, read this and then ask a new question.

    这篇关于如何制作Greasemonkey脚本来自动下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆