Last active
May 16, 2017 02:54
-
-
Save satour/19d6caaf2688eadafd5c2a97f519d1f5 to your computer and use it in GitHub Desktop.
v1.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html lang="ja"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width,initial-scale=1"> | |
| <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.css"> | |
| <style> | |
| input[disabled] { | |
| background-color: #EFEFEF; | |
| border-color: #EFEFEF; | |
| } | |
| #download-button { | |
| background-color: #91B122; | |
| border-color: #91B122; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <h2>Milkcocoa Data Download</h2> | |
| <form id="mlkcca"> | |
| <label for="appid">app id</label> | |
| <input type="text" id="appid" size="16" maxlength="12" autofocus><span id="appid_message"></span> | |
| <label for="datastore">datastore</label> | |
| <input type="text" id="datastore" size="40" maxlength="255"><span id="datastore_message"></span> | |
| <label for="authentication">Authentication</label> | |
| <select id="authentication" onChange="switch_option()"> | |
| <option value="appid">app id のみ</option> | |
| <option value="apikey">API Key 認証</option> | |
| </select> | |
| <span id="auth-field"> | |
| <label for="apikey">API KEY</label> | |
| <input type="text" id="apikey" size="16" maxlength="16" disabled="true" > | |
| <label for="secretkey">SECRET KEY</label> | |
| <input type="text" id="secretkey" size="40" maxlength="40" disabled="true" > | |
| </span> | |
| <label for="datastore">format</label> | |
| <input type="radio" name="format" value="json" checked="checked"> | |
| <span class="label-body">JSON</span> | |
| </label> | |
| <label for="download-button"></label> | |
| <a href="#"><input class="button-primary" | |
| id="download-button" | |
| type="button" | |
| value="ダウンロード" | |
| onclick="validate_form();"></a> | |
| </form> | |
| </body> | |
| </html> | |
| <script src="https://cdn.mlkcca.com/v0.6.0/milkcocoa.js"></script> | |
| <script> | |
| function validate_form(){ | |
| var input = document.forms["mlkcca"]; | |
| if ((input.appid.value === "") | (input.datastore.value === "")){ | |
| alert("app id と datastore を入力してください") | |
| } else { | |
| if(input.format.value === "json"){ milk_mc(input) } | |
| } | |
| } | |
| function milk_mc(input){ | |
| var appid = input.appid.value; | |
| var datastore = input.datastore.value; | |
| var authentication = input.authentication.value; | |
| if (authentication == "appid"){ | |
| var mc = new MilkCocoa( appid + '.mlkcca.com'); | |
| } else { | |
| var mc = MilkCocoa.connectWithApiKey( appid + '.mlkcca.com', input.apikey.value , input.secretkey.value ); | |
| } | |
| var ds = mc.dataStore(datastore); | |
| ds.stream().next(function(err, data) { | |
| var blob = new Blob([ JSON.stringify(data) ], { "type" : "text/plain" }); | |
| var a = document.createElement('a'); | |
| var name = datastore + '.txt'; | |
| a.download = name; | |
| a.target = '_blank'; | |
| if (window.navigator.msSaveBlob) { | |
| // for IE | |
| window.navigator.msSaveBlob(blob, name) | |
| } | |
| else if (window.URL && window.URL.createObjectURL) { | |
| // for Firefox | |
| a.href = window.URL.createObjectURL(blob); | |
| document.body.appendChild(a); | |
| a.click(); | |
| document.body.removeChild(a); | |
| } | |
| else if (window.webkitURL && window.webkitURL.createObject) { | |
| // for Chrome | |
| a.href = window.webkitURL.createObjectURL(blob); | |
| a.click(); | |
| } | |
| else { | |
| // for Safari | |
| window.open('data:' + mimeType + ';base64,' + window.Base64.encode(content), '_blank'); | |
| } | |
| }) | |
| mc.logout(); | |
| } | |
| </script> | |
| <script> | |
| function switch_option(){ | |
| var method = document.forms["mlkcca"].authentication.value; | |
| if ( method === "appid" ){ | |
| document.forms["mlkcca"].apikey.value = ""; | |
| document.forms["mlkcca"].secretkey.value = ""; | |
| document.forms["mlkcca"].apikey.disabled = true; | |
| document.forms["mlkcca"].secretkey.disabled = true; | |
| } else { | |
| document.forms["mlkcca"].apikey.disabled = false; | |
| document.forms["mlkcca"].secretkey.disabled = false; | |
| } | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment