kharus / kharus hunt macro

// ==UserScript==
// @name        kharus hunt macro
// @namespace   kharus macro
// @match       https://kharus.com/*
// @match       http://kharus.com/*
// @updateURL   https://openuserjs.org/meta/kharus/kharus_hunt_macro.meta.js
// @version     2016.06.08
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// @grant       은새
// ==/UserScript==
//카루스 개인정보 관리에 들어가면 카루스 매크로 설정 가능 & 뉴비 지원용 단순 레어맵 전투 매크로 & 타버전은 직접 문의 요망
var $j = jQuery.noConflict(true);
String.prototype.startsWith = function (prefix) {
  return this.indexOf(prefix) === 0;
}
String.prototype.endsWith = function (suffix) {
  return this.match(suffix + '$') == suffix;
}
if(localStorage.getItem("kharus.genHunt") == null) {
    localStorage.setItem("kharus.genHunt","");
}
if(localStorage.getItem("kharus.raremap") == null) {
    localStorage.setItem("kharus.raremap","");
}
if(localStorage.getItem("kharus.huntarea") == null) {
    localStorage.setItem("kharus.huntarea","");
}
if( location.href.indexOf("member/info") > -1 ) {
(function () {
    function loadScript(url, callback) {
        var script = document.createElement("script")
        script.type = "text/javascript";
        if (script.readyState) { //IE
            script.onreadystatechange = function () {
                if (script.readyState == "loaded" || script.readyState == "complete") {
                    script.onreadystatechange = null;
                    callback();
                }
            };
        } else { //Others
            script.onload = function () {
                callback();
            };
        }
        script.src = url;
        document.getElementsByTagName("head")[0].appendChild(script);
    }
 
	    loadScript("https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", function () {
	        //jQuery loaded
	        console.log('jquery loaded');
	        

			    var scripttxt = "" +
			        "function isNumberKey(evt) \n" +
			        "{ \n" +
			        "    var charCode = (evt.which) ? evt.which : event.keyCode; \n" +
			        "    if (charCode > 31 && (charCode < 48 || charCode > 57)) { \n" +
			        "        return false; \n" +
			        "    } \n" +
			        "    return true; \n" +
			        "} \n" +
              "function storeSet() { \n" +
			        "    localStorage.setItem('kharus.genHunt',(autotool.genHunt.checked?'on':'')); \n" +
			        "    localStorage.setItem('kharus.raremap',(autotool.raremap.checked?'on':'')); \n" +
			        "    localStorage.setItem('kharus.huntarea',autotool.huntarea.options[autotool.huntarea.selectedIndex].value); \n" +
			        "    alert('설정 저장 완료'); \n" +
			        "} ";
			    var bodytxt = "" +
			        "<form name='autotool'>" +
			        "<table border=0 width='100%'>" +
			        "<tr><th width='30%'>일반 전투</th><td width='70%'>허가<input type='checkbox' name='genHunt' " + (localStorage.getItem("kharus.genHunt")=='on'?'checked':'') + "></td></tr>" +
			        "<tr><th>레어맵 전투</th><td width='70%'>허가<input type='checkbox' name='raremap' " + (localStorage.getItem("kharus.raremap")=='on'?'checked':'') + "></td></tr>" +
			        "<tr><th>사냥터</th><td><select name='huntarea'>" +
              "<option value='1' " + (localStorage.getItem("kharus.huntarea")=="1"?"selected":"") + ">평야</option>" + 
			        "<option value='2' " + (localStorage.getItem("kharus.huntarea")=="2"?"selected":"") + ">늪지대</option>" + 
			        "<option value='3' " + (localStorage.getItem("kharus.huntarea")=="3"?"selected":"") + ">숲</option>" +
			        "<option value='4' " + (localStorage.getItem("kharus.huntarea")=="4"?"selected":"") + ">탑</option>" +
			        "</select></td></tr>" +
			        "</table>" +
			        "<div align='center'><input type='button' value='설정 저장' href='javascript:void(0);' onclick='storeSet();'></div>" +
			        "</form>";
			    document.body.innerHTML = bodytxt;
			    var script = document.createElement('script');
			    script.textContent = scripttxt;
			    document.body.appendChild(script);
			    return;
	    });
})();
}
var clickon = '';
function checkCountDownH() {
  var mycountry = $('span[class="country-name"]:eq(0)').text();
  if (location.href.indexOf('/battle/field') > - 1 && mycountry != '국가') {
    if (clickon == 'on' && parseInt($('span[id="remain_time"]').text()) > 6){
      clickon = '';
    }
    if (localStorage.getItem('kharus.genHunt') == 'on') {
      if (localStorage.getItem('kharus.raremap') == 'on' && $('button[class="areago btn btn-primary"]').length > 0) {
        if (parseInt($('span[id="remain_time"]').text()) > 2 && parseInt($('span[id="remain_time"]').text()) < 5) {
          $('input[name=\'auto_combat\']').prop('checked', false);
        } 
        else if (parseInt($('span[id="remain_time"]').text()) == 0 && $('button[class="areago btn btn-primary"]').length > 0) {
          if ($('button[class="areago btn btn-primary"]').text().indexOf('재보의 동굴') > - 1 && $('button[class="areago btn btn-primary"]').length > 1) {
            $('button[class="areago btn btn-primary"]:eq(1)') [0].click();
            stopstop;
          } 
          else {
            $('button[class="areago btn btn-primary"]:eq(0)') [0].click();
            stopstop;
          }
        }
      }
      if (clickon == '' && parseInt($('span[id="remain_time"]').text()) == 0 && $('input[name=\'auto_combat\']').prop('checked') == false && $('button[class="areago btn btn-primary"]').length < 1) {
        $('input[name=\'auto_combat\']').prop('checked', true);
        switch (parseInt(localStorage.getItem('kharus.huntarea'))) {
          case 1:
            $('button:contains("평야")') [0].click();
            clickon = 'on';
            break;
          case 2:
            $('button:contains("늪지대")') [0].click();
            clickon = 'on';
            break;
          case 3:
            $('button:contains("숲")') [0].click();
            clickon = 'on';
            break;
          case 4:
            $('button:contains("탑")') [0].click();
            clickon = 'on';
            break;
        }
      }
    }
  }
  setTimeout(checkCountDownH, 900);
}
checkCountDownH();