scratchfoundation / scratchx

Scratch Extension Site
https://github.com/llk/scratchx
190 stars 121 forks source link

How can i create new “http post” extension block #125

Closed hsiangko closed 1 year ago

hsiangko commented 7 years ago

I Write Extensions for ScratchX I use xmlhttprequest javascript But I try it….can not work… I use IE brower or chrome Brower But do not work… Can you help me…. Where is my mistake? Please …thank you….

(function(ext) {
    // Cleanup function when the extension is unloaded
    ext._shutdown = function() {};

    // Status reporting code
    // Use this to report missing hardware, plugin or unsupported browser
    ext._getStatus = function() {
        return {status: 2, msg: 'Ready'};
    };

    ext.power = function() {
        var data = new FormData();
        data.append("message","55555566666");

        var xhr = new XMLHttpRequest();
        xhr.open("POST", "https://notify-api.line.me/api/notify");
                     xhr.setRequestHeader("Authorization", "Bearer q6tXthLGMBz0Wgl2Qqz1uwf2CgNtSewqlYlEnnetmR9");
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xhr.send(data);
                return xhr.status;
    };

    // Block and block menu descriptions
    var descriptor = {
        blocks: [
            // Block type, block name, function name, param1 default value, param2 default value
            ['r', 'Send', 'power'],
        ]
    };

    // Register the extension
    ScratchExtensions.register('Sample extension6', descriptor, ext);
})({});