在web.whatsapp.com

时间:2019-04-09 11:01:18

标签: javascript file web upload whatsapp

我使用tampermonkey设置了本地测试环境,以编程方式(web.whatsapp.com)将文件(图像)发送到google chrome浏览器中的任何whatsapp联系人。我正在尝试使用javascript做到这一点,并到目前为止编写了这段代码:

(function() {
    'use strict';

    var file;
    var reader = new FileReader();
    reader.onload = function() {
        file = reader.result;
    }
    reader.readAsDataURL(new File(["abc"], "file.txt", {type:"text/plain"}));
    function getSomeFileObjFromSomewhere() {
        return file
    }

    setTimeout(function() {
        var x = document.getElementsByClassName("_2JThb")[0]; // dropable area
        console.log(x);
        x.dispatchEvent(new Event('drop', {
            dataTransfer: { files: [ file ] },
            preventDefault: function () {}
        }));
    }, 20000); // invoke after 20sec to choose contact
})();

在上面的示例中,应准备好文件“ file.txt”以便在web.whatsapp.com中进行发送-但这到目前为止还行不通。

正确的方法是什么?

非常感谢!

0 个答案:

没有答案
相关问题