Created
April 11, 2019 10:12
-
-
Save goofmint/f1cb21623f4e6e760e3e39a79745d566 to your computer and use it in GitHub Desktop.
This file contains 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
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */ | |
var saveAs=saveAs||function(e){"use strict";if(typeof e==="undefined"||typeof navigator!=="undefined"&&/MSIE [1-9]\./.test(navigator.userAgent)){return}var t=e.document,n=function(){return e.URL||e.webkitURL||e},r=t.createElementNS("http://www.w3.org/1999/xhtml","a"),o="download"in r,i=function(e){var t=new MouseEvent("click");e.dispatchEvent(t)},a=/constructor/i.test(e.HTMLElement),f=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},u="application/octet-stream",s=1e3*40,d=function(e){var t=function(){if(typeof e==="string"){n().revokeObjectURL(e)}else{e.remove()}};setTimeout(t,s)},c=function(e,t,n){t=[].concat(t);var r=t.length;while(r--){var o=e["on"+t[r]];if(typeof o==="function"){try{o.call(e,n||e)}catch(i){f(i)}}}},l=function(e){if(/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)){return new Blob([String.fromCharCode(65279),e],{type:e.type})}return e},p=function(t,f,s){if(!s){t=l(t)}var p=this,v=t.type,w=v===u,m,y=function(){c(p,"writestart progress write writeend".split(" "))},h=function(){if(w&&a&&e.FileReader){var r=new FileReader;r.onloadend=function(){var t=r.result;e.location.href="data:attachment/file"+t.slice(t.search(/[,;]/));p.readyState=p.DONE;y()};r.readAsDataURL(t);p.readyState=p.INIT;return}if(!m){m=n().createObjectURL(t)}if(w){e.location.href=m}else{var o=e.open(m,"_blank");if(!o){e.location.href=m}}p.readyState=p.DONE;y();d(m)};p.readyState=p.INIT;if(o){m=n().createObjectURL(t);setTimeout(function(){r.href=m;r.download=f;i(r);y();d(m);p.readyState=p.DONE});return}h()},v=p.prototype,w=function(e,t,n){return new p(e,t||e.name||"download",n)};if(typeof navigator!=="undefined"&&navigator.msSaveOrOpenBlob){return function(e,t,n){t=t||e.name||"download";if(!n){e=l(e)}return navigator.msSaveOrOpenBlob(e,t)}}v.abort=function(){};v.readyState=v.INIT=0;v.WRITING=1;v.DONE=2;v.error=v.onwritestart=v.onprogress=v.onwrite=v.onabort=v.onerror=v.onwriteend=null;return w}(typeof self!=="undefined"&&self||typeof window!=="undefined"&&window||this.content);if(typeof module!=="undefined"&&module.exports){module.exports.saveAs=saveAs}else if(typeof define!=="undefined"&&define!==null&&define.amd!==null){define([],function(){return saveAs})} | |
function getCookie(name){ | |
var r = null; | |
var c = name + '='; | |
var allcookies = document.cookie; | |
var position = allcookies.indexOf( c ); | |
if( position != -1 ){ | |
var startIndex = position + c.length; | |
var endIndex = allcookies.indexOf( ';', startIndex ); | |
if( endIndex == -1 ){ | |
endIndex = allcookies.length; | |
} | |
r = decodeURIComponent(allcookies.substring( startIndex, endIndex ) ); | |
} | |
return r; | |
} | |
var session = JSON.parse(getCookie("session")).sessionToken; | |
var application = location.href.replace(/.*applications\/(.*?)\/.*/g, "$1"); | |
var classname = $("li.item-class-name").text().replace(/ |\r|\n/g, ''); | |
if (!classname && $('.account .title strong').text() === 'ロール') { | |
classname = 'user'; | |
} | |
if (!classname && $('.filestore .title strong').text() === '一覧') { | |
classname = 'file'; | |
} | |
if (!classname && $('.pushinfo .title strong').text() === '一覧') { | |
classname = 'push'; | |
} | |
if (['installation', 'role', 'user', 'file', 'push'].indexOf(classname) > -1) { | |
if (['installation', 'file', 'role', 'user'].indexOf(classname) > -1) classname = classname + 's'; | |
var url = "https://console.mbaas.api.nifcloud.com/2013-09-01/applications/"+application+"/"+classname; | |
} else { | |
var url = "https://console.mbaas.api.nifcloud.com/2013-09-01/applications/"+application+"/classes/"+classname; | |
} | |
var total = $(".paging-set .item-paging .item-view").text().trim().replace(/^([0-9]+).*/, "$1"); | |
var limit = 100; | |
var order = $(".white.right.arrow-down").parent().parent().text().replace(/ |\r|\n*/g, ''); | |
if (order == "") { | |
order = $(".white.right.arrow-up").parent().parent().text().replace(/ |\r|\n*/g, ''); | |
if (order === '') { | |
order = '-createDate'; | |
} | |
}else{ | |
order = "-" + order; | |
} | |
var skip = 0; | |
var results = []; | |
var total_pages = Math.ceil(total / limit); | |
var finish = {}; | |
var results = []; | |
function getData(i) { | |
finish[i] = false; | |
var skip = i * limit; | |
$.ajax({ | |
url: url + "?limit="+limit+"&order="+order+"&skip="+skip+"&where=%7B%7D", | |
headers: {"X-NCMB-Devs-Session-Token": session}, | |
type: "GET" | |
}).then(function(ary){ | |
for (k in ary.results) { | |
delete ary.results[k]['objectId']; | |
ary.results[k].createDate = { | |
'__type': 'Date', | |
'iso': ary.results[k].createDate | |
} | |
ary.results[k].updateDate = { | |
'__type': 'Date', | |
'iso': ary.results[k].updateDate | |
} | |
results.push(ary.results[k]) | |
} | |
finish[i] = true; | |
for (var j = 0; j < total_pages; j++) { | |
if (finish[j] == false) { | |
return true; | |
} | |
} | |
var blob = new Blob([ JSON.stringify({results: results}) ], { "type" : "application/json" }); | |
saveAs(blob, classname + ".json"); | |
}); | |
} | |
for (var i = 0; i < total_pages; i++) { | |
getData(i); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment