Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mondradeckfromurl
// ==UserScript==
// @name mondradeckfromurl
// @description Imports deck URL into the deck editor.
// @match http://w001.monsterdragon.jp/deck/edit/index?*
// @author satyr
// @version 0.2
// ==/UserScript==
var buttons, wrap, name, action;
buttons = {
'Import URL': function(){
var url, ids, that, id, li, __i, __len;
url = prompt('URL', [localStorage.getItem('prevURL')]);
ids = url != null ? url.match(/\b\d{5}\b/g) : void 8;
if (!ids) {
return;
}
localStorage.setItem('prevURL', url);
if (that = /#(.+)/.exec(url)) {
document.getElementById('monster-deck-name-input').value = that[1];
}
unselectAll();
for (__i = 0, __len = ids.length; __i < __len; ++__i) {
id = ids[__i];
if (li = document.querySelector(".ui-monster-card-li[deck-flg='0'][monster-id='" + id + "']")) {
click(li);
li.style.display = 'inline-block';
}
}
},
'Unselect All': unselectAll
};
wrap = document.querySelector('.ui-moster-cardDetail-skill-wrap').appendChild(document.createElement('div'));
wrap.style.cssText = 'position:absolute; bottom:0; left:0';
for (name in buttons) {
action = buttons[name];
(__fn.call(wrap.appendChild(document.createElement('button')), name, action));
}
function unselectAll(){
var li, __i, __ref, __len;
for (__i = 0, __len = (__ref = document.querySelectorAll('.ui-monster-card-li[deck-flg="1"]')).length; __i < __len; ++__i) {
li = __ref[__i];
click(li);
}
}
function click(node){
var ev;
if (!node) {
return;
}
ev = document.createEvent('MouseEvents');
ev.initEvent('mousedown', true, true);
node.dispatchEvent(ev);
}
function __fn(name, action){
this.textContent = name;
this.accessKey = name[1];
this.addEventListener('click', function(it){
it.preventDefault();
action();
});
}
`// ==UserScript==
// @name mondradeckfromurl
// @description Imports deck URL into the deck editor.
// @match http://w001.monsterdragon.jp/deck/edit/index?*
// @author satyr
// @version 0.2
// ==/UserScript==`
buttons =
'Import URL': !->
url = prompt \URL [localStorage.getItem \prevURL]
ids = url?match /\b\d{5}\b/g
return unless ids
localStorage.setItem \prevURL url
if /#(.+)/exec url
document.getElementById(\monster-deck-name-input)value = that.1
unselectAll!
for id of ids
if li = document.querySelector \
".ui-monster-card-li[deck-flg='0'][monster-id='#id']"
click li
li.style.display = \inline-block
'Unselect All': unselectAll
wrap = document.querySelector \.ui-moster-cardDetail-skill-wrap
.appendChild document.createElement \div
wrap.style.cssText = 'position:absolute; bottom:0; left:0'
for name, action in buttons
with wrap.appendChild document.createElement \button
@textContent = name
@accessKey = name.1
@addEventListener \click !->
it.preventDefault!
action!
!function unselectAll
for li of document.querySelectorAll '.ui-monster-card-li[deck-flg="1"]'
click li
!function click node
return unless node
ev = document.createEvent \MouseEvents
ev.initEvent \mousedown true true
node.dispatchEvent ev
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.