Skip to content

Instantly share code, notes, and snippets.

@kui
Created October 11, 2012 04:40
Show Gist options
  • Save kui/3870208 to your computer and use it in GitHub Desktop.
Save kui/3870208 to your computer and use it in GitHub Desktop.
自動ガンバル
// 自動ガンバルスクリプト
// * Google Chrome のコンソールに貼りつけて使う
// * ボス戦はページ遷移してしまうのでスクリプトが無効化される
(function(){
var MAX_INTERVAL = 180*2*3; // sec
var MIN_INTERVAL = 5; // sec
var fightInterval = MAX_INTERVAL;
var click = (function(){
var ev = document.createEvent('MouseEvents');
ev.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false,
false, false, 0, null);
return function(element) {
element.dispatchEvent(ev);
};
})();
// 自動ガンバル
var fight = function(){
click($('btnFight'));
var interval = 1000 * (1 + Math.random() * fightInterval);
setTimeout(fight, interval);
if(fightInterval > MIN_INTERVAL) {
fightInterval = fightInterval / 2; // インターバルが半分づつになる
}
};
fight();
// 体力切れウィンドウを閉じる
setInterval(function(){
var isTouchalbe = function(el) {
var r = el.getClientRects()[0];
if (!r) { return false; }
var touchedEl = document.elementFromPoint((r.left+r.right)/2, (r.top+r.bottom)/2);
return touchedEl && (touchedEl === el || el.contains(touchedEl));
};
var el = $('pcloseBtn');
if(isTouchalbe(el)) {
fightInterval = MAX_INTERVAL; // 閉じる時は、インターバルを元に戻す
click(el);
}
}, 900);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment