HWM_map_patrol

HWM_map_patrol (2018.11.10)

目前为 2018-11-18 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name HWM_map_patrol
  3. // @version 0.30.1.1
  4. // @description HWM_map_patrol (2018.11.10)
  5. // @include http://178.248.235.15/war.php*
  6. // @include http://178.248.235.15/map.php*
  7. // @include http://178.248.235.15/move_sector.php*
  8. // @include http://*.heroeswm.*/war.php*
  9. // @include http://*.heroeswm.*/map.php*
  10. // @include http://*.heroeswm.*/move_sector.php*
  11. // @include https://178.248.235.15/war.php*
  12. // @include https://178.248.235.15/map.php*
  13. // @include https://178.248.235.15/move_sector.php*
  14. // @include https://*.heroeswm.*/war.php*
  15. // @include https://*.heroeswm.*/map.php*
  16. // @include https://*.heroeswm.*/move_sector.php*
  17. // @grant GM_getValue
  18. // @grant GM_setValue
  19. // @icon https://app.box.com/representation/file_version_34029013909/image_2048/1.png?shared_name=hz97b2qwo2ycc5ospb7ccffn13w3ehc4
  20. // @namespace https://greasyfork.org/users/14188
  21. // ==/UserScript==
  22.  
  23. // ========================================================
  24. (function () {
  25. var version = "0.30";
  26. var url_cur = location.href ;
  27. var url_base = 'https://'+location.hostname+'/';
  28. var url_1 = "www.heroeswm.ru";
  29. var url_2 = "178.248.235.15";
  30. var url_3 = "qrator.heroeswm.ru";
  31. var patrolMaxDelaySec = 12; // max delay in seconds
  32. // ==================================================================
  33. if (url_cur.indexOf("war.php") != -1) {
  34. var sound_enable = GM_getValue("sound_enbl",true);
  35. if (sound_enable && (document.URL.toString().indexOf('lt=-1') == -1)) {
  36. if (document.body.innerHTML.indexOf("btype|26") != -1) new Audio("http://www.soundjay.com/button/sounds/beep-09.mp3").play();
  37. }
  38. return;
  39. }
  40. // ==================================================================
  41. var sectors = []; // map sectors
  42. sectors.push( [0,0,"E"] ); //0
  43. sectors.push( [50,50,"Empire Capital"] ); //1
  44. sectors.push( [51,50,"East River"] ); //2
  45. sectors.push( [50,49,"Tiger Lake"] ); //3
  46. sectors.push( [51,49,"Rogue Wood"] ); //4
  47. sectors.push( [50,51,"Wolf Dale"] ); //5
  48. sectors.push( [50,48,"Peaceful Camp"] ); //6
  49. sectors.push( [49,51,"Lizard Lowland"] ); //7
  50. sectors.push( [49,50,"Green Wood"] ); //8
  51. sectors.push( [49,48,"Eagle Nest"] ); //9
  52. sectors.push( [50,52,"Portal Ruins"] ); //10
  53. sectors.push( [51,51,"Dragon Caves"] ); //11
  54. sectors.push( [49,49,"Shining Spring"] ); //12
  55. sectors.push( [48,49,"Sunny Sity"] ); //13
  56. sectors.push( [52,50,"Magma Mines"] ); //14
  57. sectors.push( [52,49,"Bear' Mountain"] ); //15
  58. sectors.push( [52,48,"Fairy Trees"] ); //16
  59. sectors.push( [53,50,"Harbour City"] ); //17
  60. sectors.push( [53,49,"Mithril Coast"] ); //18
  61. sectors.push( [51,52,"GreatWall"] ); //19
  62. sectors.push( [51,53,"Titan's Valley"] ); //20
  63. sectors.push( [52,53,"Fishing Village"] ); //21
  64. sectors.push( [52,54,"Kingdom Capital"] ); //22
  65. sectors.push( [48,48,"Ungovernable Steppe"] ); //23
  66. sectors.push( [51,48,"Crystal Garden"] ); //24
  67. sectors.push( [53,52,"East Island"] ); //25
  68. sectors.push( [49,52,"Wilderness"] ); //26
  69. sectors.push( [48,50,"Sublime Arbor"] ); //27
  70. // ==================================================================
  71. var available_directions = [0]; //
  72. available_directions.push( [10,3,2,4,5,7,11,8,12,22] ); //1
  73. available_directions.push( [6,16,21,3,1,4,14,15,11,5,22,8,23] );//2
  74. available_directions.push( [1,2,4,8,12,9,6,24] ); //3
  75. available_directions.push( [11,15,2,1,3,6,24] ); //4
  76. available_directions.push( [1,2,11,10,7,8,26] ); //5
  77. available_directions.push( [2,16,21,4,3,12,9,24,22] ); //6
  78. available_directions.push( [8,1,5,10,26] ); //7
  79. available_directions.push( [2,13,12,3,1,5,7] ); //8
  80. available_directions.push( [13,12,3,6,23] ); //9
  81. available_directions.push( [1,7,5,11,19,26] ); //10
  82. available_directions.push( [4,19,10,5,1,2,14] ); //11
  83. available_directions.push( [9,6,3,1,8,13,23] ); //12
  84. available_directions.push( [9,12,8,23] ); //13
  85. available_directions.push( [2,11,15,17] ); //14
  86. available_directions.push( [16,18,17,14,2,4,24] ); //15
  87. available_directions.push( [2,6,21,15,17] ); //16
  88. available_directions.push( [14,18,15] ); //17
  89. available_directions.push( [17,16,15] ); //18
  90. available_directions.push( [10,11,21,22] ); //19
  91. available_directions.push( [19,21,22] ); //20
  92. available_directions.push( [2,6,16,19,20,22] ); //21
  93. available_directions.push( [2,6,1,20,21,23] ); //22
  94. available_directions.push( [9,12,13,22,2] ); //23
  95. available_directions.push( [3,4,6,15] ); //24
  96. available_directions.push( [] ); //25
  97. available_directions.push( [5,7,10] ); //26
  98. available_directions.push( [7,8,12,13] ); //27
  99. // ==================================================================
  100. if(url_cur.indexOf(url_1) != -1) { var sect1 = GM_getValue( "sector1_1" , 1);}
  101. if(url_cur.indexOf(url_2) != -1) { var sect1 = GM_getValue( "sector1_2" , 1);}
  102. if(url_cur.indexOf(url_3) != -1) { var sect1 = GM_getValue( "sector1_3" , 1);}
  103. if(url_cur.indexOf(url_1) != -1) { var sect2 = GM_getValue( "sector2_1" , 1);}
  104. if(url_cur.indexOf(url_2) != -1) { var sect2 = GM_getValue( "sector2_2" , 1);}
  105. if(url_cur.indexOf(url_3) != -1) { var sect2 = GM_getValue( "sector2_3" , 1);}
  106. if(url_cur.indexOf(url_1) != -1) { var doPatrol = GM_getValue( "hwm_map_patrol_1" , false);}
  107. if(url_cur.indexOf(url_2) != -1) { var doPatrol = GM_getValue( "hwm_map_patrol_2" , false);}
  108. if(url_cur.indexOf(url_3) != -1) { var doPatrol = GM_getValue( "hwm_map_patrol_3" , false);}
  109.  
  110. var ems = document.evaluate("//embed[@name='map']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ).snapshotItem(0) ;
  111. var pl = 0;
  112. //==================================================================
  113. var curSector = Number(getCurSector() );
  114. var myDelta = getDelta();
  115. var in_move=true;
  116.  
  117. var eco=document.getElementsByTagName('a');
  118. for(var i=eco.length-1;i>0;i--)
  119. {
  120. if(eco[i].href.indexOf('ecostat.php')>-1)
  121. {
  122. in_move=false;
  123. var d_init = document.createElement( 'div' );
  124. var dd_init = document.createElement( 'div' );
  125. var ddh_init = document.createElement( 'div' );
  126. d_init.id = "hwmMapPatrol_menu";
  127. dd_init.id = "hwmMapPatrol_directions";
  128. d_init.style.display = "none";
  129. dd_init.style.display = "none";
  130. eco[i].parentNode.appendChild( d_init ) ;
  131. eco[i].parentNode.appendChild( dd_init ) ;
  132. eco[i].parentNode.appendChild( ddh_init ) ;
  133. //®бв ­®ўЄ ЇаЁ ®е®вҐ
  134. ddh_init.innerHTML= '<br><label style="cursor: pointer;" for="check_hunt"><input type="checkbox" id="check_hunt"> \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0440\u0438 \u043e\u0445\u043e\u0442\u0435</label>'+
  135. '<br><label style="cursor: pointer;" for="sound_enbl"><input type="checkbox" id="sound_enbl"> \u0417\u0432\u0443\u043a \u043f\u0440\u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u0438 \u0432 \u0437\u0430\u0441\u0430\u0434\u0443 \u0432\u043e\u0440\u0430\u002e</label>';
  136. d_init.innerHTML = '<br><div id="begin_1" style="border:2px solid #999; background-color:#f5f3ea; width:320; cursor: pointer" >'+
  137. '<table width="300" border="0" cellpadding=5" cellspacing="0" background="none">'+
  138. '<tr>'+
  139. '<td style="font-weight:bold; font-size:18px; vertical-align:center" align="center"><b>\u041D\u0430\u0447\u0430\u0442\u044C \u043F\u0430\u0442\u0440\u0443\u043B\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435</b></td></tr>'+
  140. '</table>'+
  141. '</div>';
  142. dd_init.innerHTML='<br><div id="begin_2" style="border:2px solid #999; background-color:#f5f3ea; width:320" ><b>\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u044B\u0435 \u043D\u0430\u043F\u0440\u0430\u0432\u043B\u0435\u043D\u0438\u044F:</b><span style="vertical-align: top; float: right; cursor: pointer" id="close_menu_panel"><b>X</b></span><br></div>'
  143. generate_direction();
  144. document.getElementById('begin_1').addEventListener( "click",function(){d_init.style.display='none';dd_init.style.display='block';} , false );
  145. document.getElementById('close_menu_panel').addEventListener( "click", function(){d_init.style.display='block';dd_init.style.display='none';} , false );
  146. document.getElementById('check_hunt').checked = ( GM_getValue( "check_hunt" ) == 1 ) ? 'checked' : '' ;
  147. document.getElementById('check_hunt').addEventListener( "click", setCheckHunt , false );
  148. document.getElementById('sound_enbl').checked = ( GM_getValue( "sound_enbl" ) == 1 ) ? 'checked' : '' ;
  149. document.getElementById('sound_enbl').addEventListener( "click", setSound_enbl , false );
  150. pl =( (GM_getValue( "check_hunt" ) == 1) ? (ems.getAttribute( 'FlashVars' ).split('=')[1].split(':')[11]!=''?1:0):0);
  151. break;
  152. }
  153. }
  154. init_patrol_button();
  155. checkPatrol();
  156.  
  157.  
  158. // ====================================================================================
  159.  
  160.  
  161. function planMyPatrol(){
  162. var dt = 10000; //Math.floor(Math.random() * patrolMaxDelaySec * 1000); // random delay
  163. if(curSector==sect1){
  164. setTimeout(function(){ go2loc(sect2); }, dt);
  165. }else if(curSector==sect2){
  166. setTimeout(function(){ go2loc(sect1); }, dt);
  167. }else{ alert("planMyPatrol, Strange ERROR"); }
  168. }
  169.  
  170. function checkPatrol(){
  171. if(doPatrol && curSector!=sect1 && curSector!=sect2){
  172. doPatrol = false;
  173. if(url_cur.indexOf(url_1) != -1) {GM_setValue( "hwm_map_patrol_1" , doPatrol );}
  174. if(url_cur.indexOf(url_2) != -1) {GM_setValue( "hwm_map_patrol_2" , doPatrol );}
  175. if(url_cur.indexOf(url_3) != -1) {GM_setValue( "hwm_map_patrol_3" , doPatrol );}
  176. return;
  177. }
  178. //
  179. if(!myDelta && doPatrol){
  180. planMyPatrol();
  181. }
  182. //
  183. if(doPatrol){
  184. showPanel();
  185. }else{
  186. hidePanel();
  187. }
  188. //
  189. }
  190.  
  191. function menuSetPatrol(e){ // callback for menu command
  192. doPatrol = !doPatrol;
  193. var wrong_sector_alert = "\u0412\u043D\u0438\u043C\u0430\u043D\u0438\u0435!\n\u0427\u0442\u043E\u0431\u044B \u043D\u0430\u0447\u0430\u0442\u044C \u043F\u0430\u0442\u0440\u0443\u043B\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435\n"+sectors[sect1][2]+" <-> "+sectors[sect2][2]+",\n\u043D\u0443\u0436\u043D\u043E \u043D\u0430\u0445\u043E\u0434\u0438\u0442\u044C\u0441\u044F \u0432 \u043E\u0434\u043D\u043E\u043C \u0438\u0437 \u044D\u0442\u0438\u0445 \u0440\u0430\u0439\u043E\u043D\u043E\u0432";
  194. //
  195. if(doPatrol && curSector!=p1 && curSector!=p2){
  196. alert(wrong_sector_alert);
  197. doPatrol = false;
  198. }
  199. if(url_cur.indexOf(url_1) != -1) {GM_setValue( "hwm_map_patrol_1" , doPatrol );}
  200. if(url_cur.indexOf(url_2) != -1) {GM_setValue( "hwm_map_patrol_2" , doPatrol );}
  201. if(url_cur.indexOf(url_3) != -1) {GM_setValue( "hwm_map_patrol_3" , doPatrol );}
  202. //
  203. checkPatrol();
  204. //
  205. }
  206.  
  207. function go2loc(n){
  208. if(!pl)
  209. window.location.href = url_base + "move_sector.php?id=" + n ;
  210. }
  211. //
  212. function getDelta(){
  213. var all_scripts = document.getElementsByTagName('script');
  214. var myDelta = "";
  215. if(all_scripts.length && all_scripts[0].innerHTML.indexOf("Delta=")!=-1 ){
  216. myDelta = all_scripts[0].innerHTML.split("\n")[1].replace(/.*Delta=(\d+).*/, "$1");
  217. }
  218. return myDelta;
  219. }
  220. //
  221. function getCurSector(){
  222. var sect = "0";
  223. var ems = document.querySelector("object > param[value*='map.swf']");
  224. if ( ems ) ems = ems.parentNode.querySelector("param[name='FlashVars']");
  225. // alert('!'+ems.parentNode.tagName+' '+ems.tagName+' '+ems.getAttribute('name'));
  226. el = ems.getAttribute('value');
  227. //alert(el);
  228. sect = el.split('=')[1].split(':')[0] ;
  229. if (sect.indexOf('*') != -1) { var tt = sect.split('*'); sect = tt[tt.length-1];}
  230. //alert(sect);
  231. return sect;
  232. }
  233. //
  234. function showPanel(){
  235. //alert("showPanel");
  236. var cancelLink = '<a href="javascript:void(0);" id="mapPatrol_cancel" style="color:#c33; font-size:14;">\u041E\u0442\u043C\u0435\u043D\u0438\u0442\u044C</a>';
  237. var panelText = "\u0412\u043D\u0438\u043C\u0430\u043D\u0438\u0435!<br>\u0418\u0434\u0435\u0442 \u043F\u0430\u0442\u0440\u0443\u043B\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435<br>"+sectors[sect1][2]+" <-> "+sectors[sect2][2]+"<br>"+cancelLink;
  238. //
  239. var d = document.createElement( 'div' );
  240. d.id = "hwmMapPatrol_div";
  241. d.style.display = "block";
  242. d.innerHTML = '<div style="border:2px solid #999; background-color:#f5f3ea; width:320; height:100; '+
  243. 'position:absolute; top:250px; left:200px;" >'+
  244. '<table width="300" border="0" cellpadding=5" cellspacing="0" background="none">'+
  245. '<tr><td><img src="i/forum/14_1.png" border=0 width=50 height=50 alt=""></td>'+
  246. '<td style="font-weight:bold; font-size:14;" align="center">'+panelText+'</td></tr>'+
  247. '</table>'+
  248. '</div>';
  249. document.body.appendChild( d ) ;
  250. document.getElementById('mapPatrol_cancel').addEventListener( "click", clickMapPatrolCancel , false );
  251. //
  252. }
  253.  
  254. function init_patrol_button(){
  255. if(!doPatrol&&!in_move)
  256. {
  257. d_init.style.display = "block";
  258. dd_init.style.display = "none";
  259. } else if(!in_move){
  260. d_init.style.display = "none";
  261. dd_init.style.display = "none";
  262. }
  263. }
  264.  
  265. function generate_direction(){
  266. var sect;
  267. d_init.style.display = "none";
  268. dd_init.style.display = "block";
  269. for(var t=0;t<available_directions[curSector].length;t++){
  270. var dd = document.createElement( 'div' );
  271. dd.id = "direct_"+t;
  272. dd.setAttribute("style","border:2px solid #999; background-color:#e5e3da; width:300; margin: 4px; padding: 2px; cursor: pointer; text-align: left");
  273. sect = available_directions[curSector][t];
  274. if ((sect == 2) || (sect == 6) || (sect == 16) || (sect == 21)) {
  275. dd.innerHTML='<b>'+sectors[curSector][2]+'&nbsp <->&nbsp;'+'<font style="color:#EE0000;">'+sectors[available_directions[curSector][t]][2]+'</font></b>';
  276. } else {
  277. dd.innerHTML='<b>'+sectors[curSector][2]+'&nbsp <->&nbsp;'+'<font style="color:#0070FF;">'+sectors[available_directions[curSector][t]][2]+'</font></b>';
  278. }
  279. dd.addEventListener('click',function(){begin_patrol(this.id)},false);
  280. document.getElementById('begin_2').appendChild( dd ) ;
  281. }
  282. }
  283.  
  284. function begin_patrol(m){
  285. d_init.innerHTML='';
  286. if(url_cur.indexOf(url_1) != -1) {GM_setValue("sector1_1" , available_directions[curSector][m.split('_')[1]]);}
  287. if(url_cur.indexOf(url_2) != -1) {GM_setValue("sector1_2" , available_directions[curSector][m.split('_')[1]]);}
  288. if(url_cur.indexOf(url_3) != -1) {GM_setValue("sector1_3" , available_directions[curSector][m.split('_')[1]]);}
  289. if(url_cur.indexOf(url_1) != -1) {GM_setValue("sector2_1" , curSector);}
  290. if(url_cur.indexOf(url_2) != -1) {GM_setValue("sector2_2" , curSector);}
  291. if(url_cur.indexOf(url_3) != -1) {GM_setValue("sector2_3" , curSector);}
  292. if(url_cur.indexOf(url_1) != -1) {GM_setValue("hwm_map_patrol_1" , true);}
  293. if(url_cur.indexOf(url_2) != -1) {GM_setValue("hwm_map_patrol_2" , true);}
  294. if(url_cur.indexOf(url_3) != -1) {GM_setValue("hwm_map_patrol_3" , true);}
  295. checkPatrol();
  296. location.href=location.href;
  297. }
  298.  
  299. function hidePanel(){
  300. var d = document.getElementById('hwmMapPatrol_div');
  301. if(d){
  302. d.style.display = "none";
  303. document.body.removeChild( d ) ;
  304. }
  305. }
  306.  
  307. function clickMapPatrolCancel(){
  308. doPatrol = false;
  309. if(url_cur.indexOf(url_1) != -1) {GM_setValue("sector1_1" , 0);}
  310. if(url_cur.indexOf(url_2) != -1) {GM_setValue("sector1_2" , 0);}
  311. if(url_cur.indexOf(url_3) != -1) {GM_setValue("sector1_3" , 0);}
  312. if(url_cur.indexOf(url_1) != -1) {GM_setValue("sector2_1" , 0);}
  313. if(url_cur.indexOf(url_2) != -1) {GM_setValue("sector2_2" , 0);}
  314. if(url_cur.indexOf(url_3) != -1) {GM_setValue("sector2_3" , 0);}
  315. if(url_cur.indexOf(url_1) != -1) {GM_setValue("hwm_map_patrol_1" , doPatrol);}
  316. if(url_cur.indexOf(url_2) != -1) {GM_setValue("hwm_map_patrol_2" , doPatrol);}
  317. if(url_cur.indexOf(url_3) != -1) {GM_setValue("hwm_map_patrol_3" , doPatrol);}
  318. hidePanel();
  319. checkPatrol();
  320. location.href=location.href;
  321. }
  322.  
  323. function setCheckHunt(){
  324. if( GM_getValue( "check_hunt" ) == 1 )
  325. {
  326. GM_setValue( "check_hunt" , 0 );
  327. pl=0;
  328. } else
  329. {
  330. GM_setValue( "check_hunt" , 1 );
  331. pl = ems.getAttribute( 'FlashVars' ).split('=')[1].split(':')[11]!=''?1:0;
  332.  
  333. }
  334. }
  335. // ========================================================
  336. function setSound_enbl(){
  337. if( GM_getValue( "sound_enbl" ) == 1 ) {
  338. GM_setValue( "sound_enbl" , 0 );
  339. } else {
  340. GM_setValue( "sound_enbl" , 1 );
  341. pl = ems.getAttribute( 'FlashVars' ).split('=')[1].split(':')[11]!=''?1:0;
  342. }
  343. }
  344. // ========================================================
  345. })();