Skip to content

Commit

Permalink
[bot-gang] 抗争参戦ロジック
Browse files Browse the repository at this point in the history
  • Loading branch information
mkiken committed Nov 4, 2018
1 parent c0c7b20 commit b4d2cc4
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
41 changes: 41 additions & 0 deletions bot-gang/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,31 @@ const SEQUENCES = [
resetStep: true,
}
},
// 抗争参戦を試みる
{
description: 'go active arena',
methodName: 'goActiveArena',
wait: 2,
fail: {
resetStep: true,
},
beforeFilter: function () {
return isArena;
}
},
// 抗争ページに行く
{
description: 'go arena',
methodName: 'goArena',
wait: 2,
fail: {
resetStep: true,
},
beforeFilter: function () {
return isArena;
}
},

];

const OPTION_METHODS = {
Expand Down Expand Up @@ -555,6 +580,14 @@ const OPTION_METHODS = {
let response = {msg: `setIsHaken done.: {${JSON.stringify(request)}}`};
sendResponse(response);

return true;
},
setIsArena: function (request, sender, sendResponse) {
isArena = request.isEnabled;

let response = {msg: `setIsArena done.: {${JSON.stringify(request)}}`};
sendResponse(response);

return true;
}
};
Expand All @@ -566,6 +599,7 @@ const STORAGE_KEYS = {
towerEvent: 'towerEvent',
MafiaEvent: 'MafiaEvent',
isHaken: 'isHaken',
isArena: 'isArena',
};

var isRunning = false;
Expand All @@ -574,6 +608,7 @@ var isIdolEvent = false;
var isTowerEvent = false;
var isMafiaEvent = false;
var isHaken = false;
var isArena = false;


function stop() {
Expand Down Expand Up @@ -613,6 +648,7 @@ function execSequence(index, tabId) {
if (typeof sequence.beforeFilter !== 'undefined') {
// スキップ
if ( ! sequence.beforeFilter()) {
info("skip this step by before filter.");
execSequence(index + 1, tabId);
return;
}
Expand Down Expand Up @@ -643,13 +679,15 @@ function execSequence(index, tabId) {
if (nextAction) {
// 処理をスキップ
if (typeof nextAction.skipSteps != 'undefined') {
info("skip steps [" + nextAction.skipSteps + "].");
nextIndex += nextAction.skipSteps;
}
// 処理をはじめに戻す
if (
typeof nextAction.resetStep != 'undefined'
&& nextAction.resetStep
) {
info("reset steps.");
nextIndex = 0;
}
}
Expand Down Expand Up @@ -709,6 +747,9 @@ window.onload = function () {
chrome.storage.sync.get(STORAGE_KEYS.isHaken, function(data) {
isHaken = data[STORAGE_KEYS.isHaken] ? true : false;
});
chrome.storage.sync.get(STORAGE_KEYS.isArena, function(data) {
isArena = data[STORAGE_KEYS.isArena] ? true : false;
});

// はじめは無効にする
chrome.storage.sync.set({[STORAGE_KEYS.isEnabled]: false}, function() {
Expand Down
6 changes: 6 additions & 0 deletions bot-gang/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ const METHODS = {
towerBattleExec: function (responseCallback) {
clickElement('div a[href*="' + convertUrl('tower/battle_exec') + '"]', responseCallback);
},
goActiveArena: function (responseCallback) {
clickElement('div.active a[href*="' + convertUrl('arena') + '"]', responseCallback);
},
goArena: function (responseCallback) {
clickElement('div a[href*="' + convertUrl('arena/battle') + '"]', responseCallback);
},
};

function clickNews(href, callback)
Expand Down
1 change: 1 addition & 0 deletions bot-gang/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<form>
<ul>
<li><input type="checkbox" id="isEnabled"><label for="isEnabled">Enable</label></li>
<li><input type="checkbox" id="isArena"><label for="isArena">抗争</label></li>
<li><input type="checkbox" id="isHaken"><label for="isHaken">覇権クエスト</label></li>
<li><input type="checkbox" id="raidGacha"><label for="isHaken">レイドガチャ
</label></li>
Expand Down
33 changes: 33 additions & 0 deletions bot-gang/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,39 @@ const OPTION_SETTINGS = {
this.dom.addEventListener('click', this.onClick);
}
},

// 抗争関連の処理
isArena: {
domId: 'isArena',
storageKey: 'isArena',
dom: null,
setDom: function () {
this.dom = document.getElementById(this.domId);
},
setOption: function () {
let that = this;
chrome.storage.sync.get(that.storageKey, function(data) {
that.dom.checked = data[that.storageKey] ? true : false;
});
},
onClick: function () {
let isChecked = this.checked;
chrome.storage.sync.set({[OPTION_SETTINGS.isArena.storageKey]: isChecked}, function() {
console.log("is_checked is " + isChecked);
chrome.runtime.sendMessage({
methodName: 'setIsArena',
isEnabled: isChecked,
},
function(response) {
console.log(response);
});
});
},
setEventListener: function () {
console.log(this);
this.dom.addEventListener('click', this.onClick);
}
},
};

window.onload = function () {
Expand Down

0 comments on commit b4d2cc4

Please sign in to comment.