Skip to content

Instantly share code, notes, and snippets.

@5zen
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5zen/bfa756b02331c675e5c8 to your computer and use it in GitHub Desktop.
Save 5zen/bfa756b02331c675e5c8 to your computer and use it in GitHub Desktop.
自動スキル発動 Ver.1.03 即時完了スキル一覧の更新
// ==UserScript==
// @id mcaxis_auto_heel
// @name mcaxis_auto_heel
// @description 自動スキル発動
// @version 1.02
// @namespace https://github.com/5zen
// @include http://*.bmcaxis.jp/card/deck.php*
// @include http://*.bmcaxis.jp/card/domestic_setting.php*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @icon https://raw.github.com/5zen/mc_beyond/master/icon.png
// @homepage https://github.com/5zen
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @grant GM_deleteValue
// @grant GM_log
// @grant GM_registerMenuCommand
// @version 2014.06.13
// ==/UserScript==
// 2014.06.13 1.00 ブラ三のツールから移植
// 2014.06.17 1.01 トレードツールが入っていた場合の処理を追加
// 1.02 確認ダイアログの表示を修正
// 2015.02.04 1.03 即時完了スキル一覧の更新
/*!
* jQuery Cookie Plugin
* https://github.com/carhartl/jquery-cookie
*
* Copyright 2011, Klaus Hartl
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://www.opensource.org/licenses/mit-license.php
* http://www.opensource.org/licenses/GPL-2.0
*/
(function($) {
$.cookie = function(key, value, options) {
// key and possibly options given, get cookie...
options = value || {};
var decode = options.raw ? function(s) { return s; } : decodeURIComponent;
var pairs = document.cookie.split('; ');
for(var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
if(decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined
}
return null;
};
})(jQuery);
jQuery.noConflict();
j$ = jQuery;
( function(){
var version = "1.00";
// 即時完結スキル一覧
var AH_list = ["ゼナのおにぎり","移動工廠","スター慰問","慰問袋","士気高揚","大祖国戦争の歌姫","癒される夜","明石の神技","シャルの応援","白衣の天使","復活の翼","要塞修復","現存艦隊主義","女王の微笑み","少陸軍省の看護","応急処置","迅速展開","慰問公演"];
///////////////////////////////////////////////
//Chrome用GM_関数
// @copyright 2009, James Campos
// @license cc-by-3.0; http://creativecommons.org/licenses/by/3.0/
if ((typeof GM_getValue == 'undefined') || (GM_getValue('a', 'b') == undefined)) {
GM_addStyle = function(css) {
var style = document.createElement('style');
style.textContent = css;
document.getElementsByTagName('head')[0].appendChild(style);
};
GM_deleteValue = function(name) {
localStorage.removeItem(name);
};
GM_getValue = function(name, defaultValue) {
var value = localStorage.getItem(name);
if (!value)
return defaultValue;
var type = value[0];
value = value.substring(1);
switch (type) {
case 'b':
return value == 'true';
case 'n':
return Number(value);
default:
return value;
}
};
GM_log = function(message) {
if (window.opera) {
opera.postError(message);
return;
}
console.log(message);
};
GM_registerMenuCommand = function(name, funk) {
//todo
};
GM_setValue = function(name, value) {
value = (typeof value)[0] + value;
localStorage.setItem(name, value);
};
}
///////////////////////////////////////////////
var himitsu_flg = 0; //秘密のフラグ
var host = location.hostname;
var path = location.pathname;
var d = document;
var $ = function(id) { return d.getElementById(id); };
var $x = function(xp,dc) { return d.evaluate(xp, dc||d, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; };
var $a = function(xp,dc) { var r = d.evaluate(xp, dc||d, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); var a=[]; for(var i=0; i<r.snapshotLength; i++){ a.push(r.snapshotItem(i)); } return a; };
var $e = function(e,t,f) { if (!e) return; e.addEventListener(t, f, false); };
var MCAXIS_AUTO_HEAL_FLG = 'mcaxis_auto_heal_flg' + host;
var MCAXIS_AUTO_HEAL_B_ID = 'mcaxis_auto_heal_b_id' + host;
var MCAXIS_AUTO_HEAL_S_NO = 'mcaxis_auto_heal_s_no' + host;
var MCAXIS_AUTO_HEAL_V_ID = 'mcaxis_auto_heal_v_id' + host;
var auto_heal_flg = 1;
// GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
if(path.indexOf("/card/deck.php") != -1) AH_STEP1();
// スキル使用連続処理部分
if(GM_getValue(MCAXIS_AUTO_HEAL_FLG)) auto_heal_flg = GM_getValue(MCAXIS_AUTO_HEAL_FLG);
if(GM_getValue(MCAXIS_AUTO_HEAL_B_ID)) var b_id = GM_getValue(MCAXIS_AUTO_HEAL_B_ID);
if(GM_getValue(MCAXIS_AUTO_HEAL_V_ID)) var v_id = GM_getValue(MCAXIS_AUTO_HEAL_V_ID);
if(auto_heal_flg == 2){var tID = setTimeout(function(){AH_STEP2()},500);};
if(auto_heal_flg == 3){var tID = setTimeout(function(){AH_STEP3()},500);};
if(auto_heal_flg == 4){var tID = setTimeout(function(){AH_STEP4()},500);};
if(auto_heal_flg == 5){var tID = setTimeout(function(){AH_STEP5()},500);};
if(auto_heal_flg == 6){var tID = setTimeout(function(){AH_STEP6()},500);};
if(auto_heal_flg == 7){var tID = setTimeout(function(){AH_STEP7()},500);};
if(auto_heal_flg == 8){var tID = setTimeout(function(){AH_STEP8()},500);};
if(auto_heal_flg > 30){var tID = setTimeout(function(){AH_STEP31()},500);};
if(auto_heal_flg >= 2 && path.indexOf("/card/")!=-1){
var prtElm = document.getElementById("gray02Wrapper");
var chdElm = document.getElementsByTagName("h2").item(0);
var newElm = document.createElement("div");
if( auto_heal_flg > 30){
newElm.innerHTML = " 自動スキル動作中  STEP " + (auto_heal_flg/10) + " / 8";
}else{
newElm.innerHTML = " 自動スキル動作中  STEP " + auto_heal_flg + " / 8";
}
newElm.style.backgroundColor ="red";
newElm.id = "ah_text";
prtElm.insertBefore(newElm, chdElm);
}
if(path.indexOf("/card/domestic_setting.php")!=-1 && document.body.innerHTML.indexOf("設定されているユニットを解除する")!=-1){
var id = document.evaluate('//form[@method="get"]/input[@name="id"]/@value',document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.textContent;
var btn = document.createElement("input");
btn.value = "設定されているユニットをデッキから下ろす";
btn.type = "button";
btn.addEventListener("click",function(){AH_STEP9(id)},false);
document.getElementsByTagName("form").item(1).appendChild(btn);
}
function AH_STEP1(){
console.log("== Start AH_STEP1() ==");
var page_type = document.getElementsByName("show_deck_card_count").item(0);
page_type = page_type.options[page_type.selectedIndex].value;
if( page_type != 1 ){
var s_list = document.evaluate('//*[@class=\"statusParameter2\"]',document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var b_list = document.getElementsByClassName("setPlace")
var b_id = [];
for( var i = 0; i < s_list.snapshotLength; i++ ){
if( b_list.item(i).innerHTML.indexOf("セット先") != -1 ){
b_id[i] = b_list.item(i).childNodes.item(1).id;
for( var j = 3; j < 6; j++ ){
var sk_flg = document.evaluate('//*[@class="statusParameter2"]//tr['+j+']',document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var sk_num = document.evaluate('//*[@class="statusParameter2"]//tr['+j+']/th',document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var sk_name = document.evaluate('//*[@class="statusParameter2"]//tr['+j+']/td',document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if(sk_name.snapshotItem(i).innerHTML.length != 0){
var skill_list = document.evaluate('//*[@class="cardStatusDetail label-setting-mode"]//*[@class="cardWrapper2col"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(i).innerHTML;
// 2014.06.17 トレードツールが入っていた場合の処理を追加
if (sk_name.snapshotItem(i).innerHTML.match("<a")) {
sk_name.snapshotItem(i).innerHTML.match(/[^>]+.([^<]+)</);
var regexp = "防:" + RegExp.$1;
} else {
var regexp = "防:" + sk_name.snapshotItem(i).innerHTML;
}
if(skill_list.match(regexp) && sk_flg.snapshotItem(i).className != "used"){
var btn = document.createElement("a");
btn.id = "AH_btn_" + i + "_" + "j";
btn.innerHTML = "[使用]";
for(var k = 0; k < AH_list.length; k++){
if(sk_name.snapshotItem(i).innerHTML.indexOf( AH_list[k] ) != -1) btn.style.color = "red";
}
btn.href = "javascript:void(0)"
if (sk_name.snapshotItem(i).innerHTML.match("<a")) {
sk_name.snapshotItem(i).innerHTML.match(/[^>]+.([^<]+)</);
btn.addEventListener("click",AH_setDeck(b_id[i],j-3,RegExp.$1),false)
} else {
btn.addEventListener("click",AH_setDeck(b_id[i],j-3,sk_name.snapshotItem(i).innerHTML),false)
}
sk_num.snapshotItem(i).appendChild(btn);
}
}
}
}
}
}
}
function AH_setDeck(n,i,a){
return function() {
if(window.confirm("スキル:"+a+"を使用します。よろしいですか?")){
var v_id = document.getElementById(n).value;
var regexp = /selected_village_([0-9]*)/;
n.match(regexp);
var b_id = parseInt(RegExp.$1);
GM_setValue(MCAXIS_AUTO_HEAL_B_ID, b_id);
GM_setValue(MCAXIS_AUTO_HEAL_S_NO, i);
GM_setValue(MCAXIS_AUTO_HEAL_V_ID, v_id);
auto_heal_flg = 3;
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
var deckset = AH_setDeck0(b_id,v_id);
// location.href = "http://"+host+"/village_change.php?village_id="+v_id+"&from=menu&page=/card/domestic_setting.php" ;
}
}
}
function AH_setDeck0(n,m){
var ssid = j$.cookie('SSID');
var data = "mode=set&target_card="+n+"&wild_card_flg=&inc_point=&btn_change_flg=&p=1&l=&ssid="+ssid+"&selected_village["+n+"]="+m;
GM_xmlhttpRequest({
method:"POST",
url:"http://" + host + "/card/deck.php",
headers:{"Content-type":"application/x-www-form-urlencoded"},
data: data,
onload:function(x){
// console.log(x.responseText);
location.href = "http://"+host+"/village_change.php?village_id="+m+"&from=menu&page=/card/domestic_setting.php" ;
}
});
return;
}
// STEP.2
function AH_STEP2(){
auto_heal_flg = 3;
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
location.href = "http://"+host+"/village_change.php?village_id="+v_id+"&from=menu&page=/card/domestic_setting.php" ;
}
// STEP.3
function AH_STEP3(){
if( path.indexOf("domestic_setting.php") != -1){
if(document.body.innerHTML.indexOf("設定されているユニットを解除する")!=-1){
auto_heal_flg = 8;
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
location.href = "http://"+host+"/card/deck.php";
}else{
var chkbox = document.evaluate('//*[@id="card_radio_'+b_id+'"]',document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if( chkbox.snapshotLength > 0 ){
chkbox.snapshotItem(0).checked = true;
auto_heal_flg = 4;
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
document.getElementsByName("input_domestic").item(0).submit();
}else{
auto_heal_flg = 31;
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
var AH_st3t = setTimeout(function(){location.reload()},2000);
}
}
}else{
location.href = "http://"+host+"/village_change.php?village_id="+v_id+"&from=menu&page=/card/domestic_setting.php" ;
}
}
// STEP.31
function AH_STEP31(){
if( path.indexOf("domestic_setting.php") != -1){
var chkbox = document.evaluate('//*[@id="card_radio_'+b_id+'"]',document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if( chkbox.snapshotLength > 0 ){
chkbox.snapshotItem(0).checked = true;
auto_heal_flg = 4;
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
document.getElementsByName("input_domestic").item(0).submit();
}else if( auto_heal_flg < 36 ){
auto_heal_flg += 1;
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
var AH_st3t = setTimeout(function(){location.reload()},2000);
}else{
auto_heal_flg = 1;
document.getElementById("ah_text").innerHTML = " 自動スキル: <b>ユニットがセットできなかったため動作を停止しました</b>"
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
GM_setValue(MCAXIS_AUTO_HEAL_B_ID, 0);
GM_setValue(MCAXIS_AUTO_HEAL_S_NO, 0);
GM_setValue(MCAXIS_AUTO_HEAL_V_ID, 0);
}
}else{
location.href = "http://"+host+"/village_change.php?village_id="+v_id+"&from=menu&page=/card/domestic_setting.php" ;
}
}
// STEP.4
function AH_STEP4(){
//auto_heal_flg = 5;
//GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
var b_tbl = document.evaluate('//*[@class="general"]',document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for(var i = 0; i < b_tbl.snapshotLength; i++){
if( b_tbl.snapshotItem(i).innerHTML.indexOf("内政中") == -1 ){
continue;
}else{
var s_no = GM_getValue(MCAXIS_AUTO_HEAL_S_NO) + 3;
var target = '//*[@class="general"]['+(i+1)+']//tr[2]/td';
var skl_num = document.evaluate(target,document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for(var k = 0; k < AH_list.length; k++){
if(skl_num.snapshotItem(s_no).innerHTML.indexOf( AH_list[k] ) != -1){
auto_heal_flg = 5;
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
break;
}else{
auto_heal_flg = 1;
}
}
if(auto_heal_flg == 1){
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
GM_setValue(MCAXIS_AUTO_HEAL_B_ID, 0);
GM_setValue(MCAXIS_AUTO_HEAL_S_NO, 0);
GM_setValue(MCAXIS_AUTO_HEAL_V_ID, 0);
}
location.href = skl_num.snapshotItem(s_no).childNodes.item(0).href;
}
}
}
// STEP.5
function AH_STEP5(){
auto_heal_flg = 6;
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
document.getElementsByTagName("form").item(1).submit();
}
// STEP.6
function AH_STEP6(){
console.log("=== AH_STEP6 ===");
//auto_heal_flg = 7;
//GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
auto_heal_flg = 1;
var ssid = j$.cookie('SSID');
var data = "mode=unset&target_card="+b_id+"&wild_card_flg=&inc_point=&btn_change_flg=&l=&ssid="+ssid;
GM_xmlhttpRequest({
method:"POST",
url:"http://" + host + "/card/deck.php",
headers:{"Content-type":"application/x-www-form-urlencoded"},
data: data,
onload:function(x){
// console.log(x.responseText);
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
GM_setValue(MCAXIS_AUTO_HEAL_B_ID, 0);
GM_setValue(MCAXIS_AUTO_HEAL_S_NO, 0);
GM_setValue(MCAXIS_AUTO_HEAL_V_ID, 0);
location.href = "http://"+host+"/card/deck.php";
}
});
}
// STEP.7
function AH_STEP7(){
auto_heal_flg = 1;
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
GM_setValue(MCAXIS_AUTO_HEAL_B_ID, 0);
GM_setValue(MCAXIS_AUTO_HEAL_S_NO, 0);
GM_setValue(MCAXIS_AUTO_HEAL_V_ID, 0);
document.getElementById("target_card").value = b_id;
document.getElementById("mode").value='unset';
document.getElementById("deck_file").submit();
}
// STEP.8
function AH_STEP8(){
auto_heal_flg = 1;
document.getElementById("ah_text").innerHTML = " 自動スキル: <b>内政ユニットがセットされていたため動作を停止しました</b>"
GM_setValue(MCAXIS_AUTO_HEAL_FLG, auto_heal_flg);
GM_setValue(MCAXIS_AUTO_HEAL_B_ID, 0);
GM_setValue(MCAXIS_AUTO_HEAL_S_NO, 0);
GM_setValue(MCAXIS_AUTO_HEAL_V_ID, 0);
}
// STEP.9
function AH_STEP9(b_id){
if(window.confirm("内政ユニットをデッキから下ろします。よろしいですか?")){
GM_setValue(MCAXIS_AUTO_HEAL_B_ID, b_id);
AH_STEP5();
}
}
}) ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment