Skip to content

Instantly share code, notes, and snippets.

@satyr
Created February 23, 2012 16:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satyr/1893538 to your computer and use it in GitHub Desktop.
Save satyr/1893538 to your computer and use it in GitHub Desktop.
mondrasummonshistorycsv
// ==UserScript==
// @name mondrasummonshistorycsv
// @description Collects "Gacha" history as CSV.
// @namespace http://satyr.github.com
// @author satyr
// @match http://w001.monsterdragon.jp/summons/history
// @run-at document-end
// ==/UserScript==
var base, btn;
base = document.getElementById('monster-base-table');
(function(){
this.textContent = 'CSV';
this.accessKey = 'C';
this.addEventListener('click', go, false);
}.call(btn = base.parentNode.appendChild(document.createElement('button'))));
function go(){
var csvs, max, info, div, done, page;
csvs = [toCSV(base)];
max = +/\d+$/.exec(document.querySelector('#monster-pager > li:last-child > a'));
info = btn.parentNode.appendChild(document.createElement('b'));
div = document.createElement('div');
done = 1;
for (page = 2; page <= max; ++page) {
(_fn.call(new XMLHttpRequest, page));
}
function _fn(page){
this.open('GET', location + "?page=" + page, true);
this.onload = function(){
csvs[page - 1] = toCSV((div.innerHTML = /<table[^>]+"monster-base-table">[^]+?<\/table>/.exec(this.responseText), div));
info.textContent = " " + ++done + "/" + max;
if (done < max) {
return;
}
(function(){
this.value = csvs.join('\n');
this.setAttribute('cols', 80);
this.setAttribute('rows', 10);
this.style.display = 'block';
btn.parentNode.appendChild(this);
this.focus();
}.call(document.createElement('textarea')));
};
this.send();
}
}
function toCSV(table){
return [].map.call(table.getElementsByTagName('tr'), function(it){
return [].map.call(it.getElementsByTagName('td'), function(it){
return it.textContent;
}).join(',');
}).join('\n').trim();
}
`// ==UserScript==
// @name mondrasummonshistorycsv
// @description Collects "Gacha" history as CSV.
// @namespace http://satyr.github.com
// @author satyr
// @match http://w001.monsterdragon.jp/summons/history
// @run-at document-end
// ==/UserScript==`
base = document.getElementById \monster-base-table
with btn = base.parentNode.appendChild document.createElement \button
@textContent = \CSV
@accessKey = \C
@addEventListener \click, go, false
!function go
csvs = [toCSV base]
max = +/\d+$/exec do
document.querySelector '#monster-pager > li:last-child > a'
info = btn.parentNode.appendChild document.createElement \b
div = document.createElement \div
done = 1
for page from 2 to max
with new XMLHttpRequest
@open \GET "#location?page=#page" true
@onload = !->
csvs[page-1] = toCSV div <<< innerHTML:
//<table[^>]+"monster-base-table">[^]+?</table>//exec @responseText
info.textContent = " #{++done}/#max"
return if done < max
with document.createElement \textarea
@value = csvs.join \\n
@setAttribute \cols 80
@setAttribute \rows 10
@style.display = \block
btn.parentNode.appendChild this
@focus!
@send!
function toCSV table
[]map.call table.getElementsByTagName(\tr), ->
[]map.call it.getElementsByTagName(\td), (-> it.textContent) .join \,
.join \\n .trim!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment