// (c) 2008-2010, xo4yxa
// (c) 2014, Ded Moroz
//
// ==UserScript==
// @name hwmmapmove
// @namespace ded_moroz
// @description перемещение по карте в один клик, скрипт для ГВД
// @version 2.6
// @homepage https://greasyfork.org/users/7571-ded-moroz
// @include http://www.heroeswm.ru/map.php*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// @downloadURL none
// ==/UserScript==
if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported") > -1))
{
this.GM_getValue = function(key, def)
{
return localStorage[key] || def;
};
this.GM_setValue = function(key, value)
{
return localStorage[key] = value;
};
this.GM_deleteValue = function(key)
{
return delete localStorage[key];
};
}
var coop = '
| Пункт назначения: | ' + loc[par[MapParams.LOC_CURRENT]][0][0] + ' ' + coop;
link = document.getElementsByTagName('a');
link = link[link.length - 1].parentNode;
link.appendChild(div);
}
$("hwmmm_options").addEventListener("click", setting, false);
update_time(new Date().getTime(), document.title);
}
else
{
// currently not moving
// report completed mercenary task if needed
if (GM_getValue("checkgn", 0) == 1 && par[MapParams.MERC] == -1 && loc_merc.indexOf(parseInt(par[MapParams.LOC_CURRENT])) != -1)
{
window.location.href = url + 'mercenary_guild.php';
return;
}
nado.appendChild(dm);
$("hwmmm_options").addEventListener("click", setting, false);
// create a grid of map locations with the moving links
for (l = 1; l < loc.length; l++)
{
var d = $('loc_' + l);
if (d == null) continue;
d.parentNode.style.textAlign = 'center';
d.style.padding = '1px 3px';
d.style.fontSize = '11px';
d.parentNode.style.border = par[MapParams.LOC_VIEW] == l ? '1px solid #00f' : '1px solid #abc';
if (l == par[MapParams.LOC_CURRENT])
{
d.style.fontWeight = 'bold';
d.parentNode.style.backgroundColor = 'FFF8DC';
if (l == par[MapParams.MERC]) d.style.color = 'FF0000';
d.innerHTML = loc[l][0][0];
}
else
{
a = document.createElement('a');
a.style.fontSize = '11px';
a.href = 'http://www.heroeswm.ru/move_sector.php?id=' + l;
if (l == par[MapParams.MERC]) a.style.color = 'FF0000';
a.innerHTML = loc[l][0][0];
a.setAttribute('tz', l);
// do not generate links when we have advanced transport
if (par[MapParams.COMPLEX_PATH] == 0)
{
a.href = 'javascript: void(0)';
a.addEventListener("click", setMXY, false);
}
a.addEventListener("mouseover", viewPath, false);
a.addEventListener("mouseout", hidePath, false);
d.appendChild(a);
}
// highlight locations with mercenary guild
if (par[MapParams.MERC] == -1 && loc_merc.indexOf(l) != -1)
{
b = document.createElement('b');
b.style.color = '#00F';
b.innerHTML = ' X';
d.appendChild(b);
}
// view sector
if (GM_getValue("checkvs") && par[MapParams.LOC_VIEW] != l)
{
a = document.createElement('a');
a.href= 'http://www.heroeswm.ru/map.php?cx=' + (48 + loc[l][0][2]) + '&cy=' + (48 + loc[l][0][1]);
a.style.display = 'block';
a.style.width = '100%';
a.title = 'Осмотреть сектор ' + loc[l][0][0];
vi = document.createElement('img');
vi.src = "data:image/gif,GIF89a%10%00%10%00%D5%00%00B%40B%15%15%18((-PPUzz%7FHHJ%5D%5D_--.zz%7BWWX23%3BEHS%80%88%A2rx%8C%DA%DD%E7bj%80sx%87%88%8C%97%7D%85%98HO_%7D%85%97%88%8C%95psz%DC%DD%DF%D4%D5%D7x%7F%8C%2B-0%C2%DF%FF%DF%F4%FFMOPmop%EF%F1%F2%E7%F9%FF%EA%FD%FF%E7%FF%FF%13%15%15%E9%FF%FF%18%1A%1A%FA%FF%FFmoo%FC%FF%FF%FD%FF%FFZ%5B%5B%5D%5D%5B%40%3F%3F%FF%FF%FF%16%16%16%10%10%10%05%05%05%00%00%00%FF%FF%FF%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%01%00%002%00%2C%00%00%00%00%10%00%10%00%00%06%5C%40%99pH%2C%12%13%01%8D%80e%24%02ZP%A8%A2)k%C8%A2%D1As%01Ma'%CDF%D4%14%7D4!-%94%A8%95%BAJ%9A%07P%8B%E4mm%2C%D4H(%CA%A9%AC%A82%05%19%0C%14%041*%17%80E0%1D%18%8AD%2F%06%89%8FB%25'%1F%94B.%08-%992%23%1E%9ECA%00%3B";
vi.style.border = '0px';
a.appendChild(vi);
d.parentNode.appendChild(a);
}
}
}
}
function update_time(start, title)
{
s = par[MapParams.LAST_TIME] - ~~((new Date().getTime() - start) / 1000);
if (s < 0) return;
m = ~~(s / 60);
s = s % 60;
if (s < 10) s = "0" + s;
if (m < 10) m = "0" + m;
document.title = " [" + m + ":" + s + "] " + title;
setTimeout(function(){update_time(start, title);}, 1000);
}
function move(from, to, force_move)
{
if (par[MapParams.LOC_FROM] != 0)
{
// currently moving
init();
return;
}
if (to == from)
{
// arrived
stop();
// report completed mercenary task if needed
if (par[MapParams.MERC] == -1 && loc_merc.indexOf(from) != -1 && GM_getValue("checkgn", 0) == 1)
{
window.location.href = url + 'mercenary_guild.php';
return;
}
init();
return;
}
// stop if hunt is available
if (par[MapParams.HUNT] != '' && GM_getValue("checkgo", 0) == 1 && !force_move)
{
stop();
init();
return;
}
new_id = loc[from][to];
if (new_id && new_id > 0)
{
move(from, new_id, force_move);
return;
}
A = loc[from][0];
B = loc[to][0];
row = B[1] > A[1] ? A[1] + 1 : (B[1] == A[1] ? A[1] : A[1] - 1);
col = B[2] > A[2] ? A[2] + 1 : (B[2] == A[2] ? A[2] : A[2] - 1);
go(map_square[row][col]);
}
var warned = false;
function go(to)
{
// check if move is legal
if (par.slice(MapParams.LOC_MOVE_FIRST, MapParams.LOC_MOVE_LAST + 1).indexOf(to.toString()) != -1)
{
GM_xmlhttpRequest({
method: "GET",
url: map_url,
onload: function (response)
{
/* ! Map checks enabled by default. Do NOT change it unless you know what you are doing. */
map_swf_passed = false;
/* Flash-map which generates links as below */
old_size = 220039;
old_hash = "b441f0ac541408a809ec907b54cc0060";
new_size = response.responseText.length;
if (new_size == old_size)
{
new_hash = CryptoJS.MD5(response.responseText);
if (new_hash == old_hash) map_swf_passed = true;
}
if (map_swf_passed)
{
rand = ((par[MapParams.LOC_CURRENT] * 153 + to * 234) % 333 * 234 + par[MapParams.MAGIC_NUMBER] % 346234 - 142) % 10000 / 10000;
window.location.href = url + 'move_sector.php?id=' + to + '&rand=' + rand;
return;
}
else
{
if (new_size != old_size) console.log("New map size: " + response.responseText.length + "\nOld map size: " + old_size);
else console.log("New map hash: " + new_hash + "\nOld map hash: " + old_hash);
if (!warned)
{
nado = ems.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
warn = document.createElement('div');
warn.innerHTML += "Flash-карта была изменена, генерация ссылок для перемещения отключена";
nado.appendChild(warn);
warned = true;
}
}
}
});
}
else
{
alert('Нет пути из ' + par[MapParams.LOC_CURRENT] + ' в ' + to);
}
// reset path
stop();
}
function setMXY()
{
GM_setValue("hwm_map_move_mz", this.getAttribute('tz'))
GM_setValue("hwm_map_move", 1);
move(parseInt(par[MapParams.LOC_CURRENT]), GM_getValue("hwm_map_move_mz"), true);
}
function stop()
{
GM_setValue("hwm_map_move", 0);
GM_setValue("hwm_map_move_mz", 0);
}
function setCheck()
{
name = this.getAttribute('id');
if (GM_getValue(name) && GM_getValue(name) == 1)
GM_setValue(name, 0);
else
GM_setValue(name, 1);
}
function setTransport(id)
{
$("transp" + transp).style.background="#F6F3EA";
$("transp" + id).style.background="#0000ff";
GM_setValue("transport", id);
transp = id;
}
function viewPath()
{
travel_time = [120, 84, 60, 36, 24, 12];
to = this.getAttribute('tz');
this.title = loc[to][0][0] + ' (' + path(par[MapParams.LOC_CURRENT], to, 0) + ')';
function path(from, to, t)
{
// return time if reached destination
if (to == from)
{
myT = new Date(t * 1000);
myTs = myT.getSeconds();
return myT.getMinutes() + ':' + (myTs < 10 ? '0' : '') + myTs;
}
A = loc[from][0];
B = loc[to][0];
new_id = loc[from][to];
if (new_id && new_id > 0) B = loc[new_id][0];
drow = B[1] > A[1] ? 1 : (B[1] == A[1] ? 0 : -1);
dcol = B[2] > A[2] ? 1 : (B[2] == A[2] ? 0 : -1);
t = (drow == 0 || dcol == 0) ? t + travel_time[transp] : t + ~~(travel_time[transp] * 1.41);
id = map_square[A[1] + drow][A[2] + dcol];
td = $('loc_' + id)
td.parentNode.style.backgroundColor = 'F0E68C';
road[road.length] = id;
return path(id, to, t);
}
return;
}
function hidePath()
{
for (i = 0; i < road.length; i ++)
{
$('loc_' + road[i]).parentNode.style.backgroundColor = 'DDD9CD';
}
road = [];
}
//+ закрытие форм
function form_close()
{
bg = $('bgOverlay');
bgc = $('bgCenter');
if (bg)
{
bg.style.display = bgc.style.display = 'none';
}
}
//-
//+ форма настроек
function setting()
{
bg = $('bgOverlay');
bgc = $('bgCenter');
if (!bg)
{
bg = document.createElement('div');
bg.id = 'bgOverlay';
document.body.appendChild(bg);
bg.style.position = 'absolute';
bg.style.left = '0';
bg.style.width = '100%';
bg.style.height = '100%';
bg.style.background = "#000000";
bg.style.opacity = "0.5";
bg.addEventListener("click", form_close, false);
bgc = document.createElement('div');
bgc.id = 'bgCenter';
document.body.appendChild(bgc);
bgc.style.position = 'absolute';
bgc.style.width = '400px';
bgc.style.background = "#F6F3EA";
bgc.style.left = ((document.body.offsetWidth - 400) / 2) + 'px';
}
text = '';
adv_transp = ' |  |  |  |
';
if (par[MapParams.COMPLEX_PATH] == 0)
{
bgc.innerHTML = text + spl_transp;
$("transp0").addEventListener("click", function(){setTransport(0)}, false);
$("transp1").addEventListener("click", function(){setTransport(1)}, false);
$("transp2").addEventListener("click", function(){setTransport(2)}, false);
}
else
{
bgc.innerHTML = text + adv_transp;
$("transp3").addEventListener("click", function(){setTransport(3)}, false);
$("transp4").addEventListener("click", function(){setTransport(4)}, false);
$("transp5").addEventListener("click", function(){setTransport(5)}, false);
}
$("transp" + transp).style.background="#0000ff";
$("bt_close").addEventListener("click", form_close, false);
check_id = ['checkgo', 'checkgn', 'checkgv', 'checkgvn', 'checkvm', 'checkvs'];
for (i = 0; i < check_id.length; i++)
{
checkbox = $(check_id[i]);
checkbox.checked = GM_getValue(check_id[i], 0) == 1 ? 'checked' : '';
checkbox.addEventListener("click", setCheck, false);
}
bg.style.top = (-document.body.scrollTop) + 'px';
bgc.style.top = (document.body.scrollTop + 150) + 'px';
bg.style.display = bgc.style.display = 'block';
}
//-
function $(id) { return document.getElementById(id); }
/*
CryptoJS v3.1.2
code.google.com/p/crypto-js
(c) 2009-2013 by Jeff Mott. All rights reserved.
code.google.com/p/crypto-js/wiki/License
*/
var CryptoJS=CryptoJS||function(s,p){var m={},l=m.lib={},n=function(){},r=l.Base={extend:function(b){n.prototype=this;var h=new n;b&&h.mixIn(b);h.hasOwnProperty("init")||(h.init=function(){h.$super.init.apply(this,arguments)});h.init.prototype=h;h.$super=this;return h},create:function(){var b=this.extend();b.init.apply(b,arguments);return b},init:function(){},mixIn:function(b){for (var h in b)b.hasOwnProperty(h)&&(this[h]=b[h]);b.hasOwnProperty("toString")&&(this.toString=b.toString)},clone:function(){return this.init.prototype.extend(this)}},
q=l.WordArray=r.extend({init:function(b,h){b=this.words=b||[];this.sigBytes=h!=p?h:4*b.length},toString:function(b){return(b||t).stringify(this)},concat:function(b){var h=this.words,a=b.words,j=this.sigBytes;b=b.sigBytes;this.clamp();if (j%4)for (var g=0;g