Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mondrahunthelper
// ==UserScript==
// @name mondrahunthelper
// @description Selects latest redundant normal/bronze cards for treasure hunt.
// @match http://w001.monsterdragon.jp/treasure_hunt/c*
// @author satyr
// @version 0.4
// ==/UserScript==
var form, bttn, div, action, __i, __ref, __len;
if (location.pathname === '/treasure_hunt/confirm') {
form = document.forms.treasure_card_do;
bttn = button('Auto', function(){
var frame;
self.name = 'confirm';
frame = document.createElement('iframe');
frame.style.cssText = 'position:fixed; width:1px; height:1px';
form.target = frame.name = 'cards';
form.appendChild(frame);
form.action = 'card?auto';
form.submit();
form.action = 'card';
});
bttn.style.cssText = 'position:absolute; top:0; left:0';
form.appendChild(bttn);
return;
}
if (location.search === '?auto') {
document.forms[0].target = 'confirm';
Auto();
return;
}
div = document.createElement('div');
div.style.cssText = 'position:absolute; right:0';
for (__i = 0, __len = (__ref = [Auto, Reset]).length; __i < __len; ++__i) {
action = __ref[__i];
div.appendChild(button(action.name, action));
}
document.querySelector('.ui-monster-deck-header').appendChild(div);
function Auto(){
var dic, lis, li, name, cards, card, entries, __i, __len, __res, __ref;
dic = Object.create(null);
lis = document.querySelectorAll('.ui-monster-card-li');
for (__i = 0, __len = lis.length; __i < __len; ++__i) {
li = lis[__i];
name = li.getAttribute('monster-name-sort');
if ((name === 'ゴブリン' || name === 'トンベリ') || 2 < li.getAttribute('monster-rare')) {
continue;
}
(dic[name] || (dic[name] = [])).push(li);
}
__res = [];
for (name in dic) {
cards = dic[name];
if (3 < cards.length) {
for (__i = 0, __len = (__ref = cards.sort(byId).slice(3)).length; __i < __len; ++__i) {
card = __ref[__i];
if (+card.getAttribute('enable-flg')) {
__res.push(card);
}
}
}
}
entries = __res;
Reset();
if (entries[3]) {
entries.sort(byId).splice(3);
}
entries.forEach(click);
document.getElementById('monster-card-select-submit').click();
}
function Reset(){
var node, __i, __ref, __len, __ref1;
for (__i = 0, __len = (__ref = document.querySelectorAll('.monster-guard-select')).length; __i < __len; ++__i) {
node = __ref[__i];
if ((__ref1 = node.style.display) === '' || __ref1 === 'block') {
click(node);
}
}
}
function click(node){
var ev;
if (!node) {
return;
}
ev = document.createEvent('MouseEvents');
ev.initEvent('mousedown', true, true);
node.dispatchEvent(ev);
}
function button(title, action){
var b;
b = document.createElement('button');
b.textContent = title;
b.accessKey = title[0];
b.addEventListener('click', function(it){
it.preventDefault();
action();
});
return b;
}
function byId(a, b){
return a.getAttribute('card-id') - b.getAttribute('card-id');
}
`// ==UserScript==
// @name mondrahunthelper
// @description Selects latest redundant normal/bronze cards for treasure hunt.
// @match http://w001.monsterdragon.jp/treasure_hunt/c*
// @author satyr
// @version 0.4
// ==/UserScript==`
if location.pathname is \/treasure_hunt/confirm
form = document.forms.treasure_card_do
bttn = button \Auto !->
self.name = \confirm
frame = document.createElement \iframe
frame.style.cssText = 'position:fixed; width:1px; height:1px'
form.target = frame.name = \cards
form.appendChild frame
form.action = \card?auto
form.submit!
form.action = \card
bttn.style.cssText = 'position:absolute; top:0; left:0'
form.appendChild bttn
return
if location.search is \?auto
document.forms.0.target = \confirm
Auto!
return
div = document.createElement \div
div.style.cssText = 'position:absolute; right:0'
for action of [Auto, Reset]
div.appendChild button action.name, action
document.querySelector \.ui-monster-deck-header .appendChild div
!function Auto
dic = Object.create null
lis = document.querySelectorAll \.ui-monster-card-li
for li of lis
name = li.getAttribute \monster-name-sort
continue if name of <[ゴブリン トンベリ]>
or 2 < li.getAttribute \monster-rare
dic@@[name]push li
entries =
for name, cards in dic
if 3 < cards.length
for card of cards.sort byId .slice 3
card if +card.getAttribute \enable-flg
Reset!
entries.sort byId .splice 3 if entries.3
entries.forEach click
document.getElementById \monster-card-select-submit .click!
!function Reset
for node of document.querySelectorAll \.monster-guard-select
click node if node.style.display of ['' \block]
!function click node
return unless node
ev = document.createEvent \MouseEvents
ev.initEvent \mousedown true true
node.dispatchEvent ev
function button title, action
b = document.createElement \button
b <<< textContent: title, accessKey: title.0
b.addEventListener \click !->
it.preventDefault!
action!
b
function byId a, b
a.getAttribute(\card-id) - b.getAttribute(\card-id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.