window.dwKeep2 = {
'/user_warnings.php': ['id', 'pageID'],
'/votes.php': ['id', 'pageID'],
'/reh_hlp.php': ['mode'],
'/contacts.php': ['ignore', 'pageID'],
'/push.php': ['id', 'settings'],
'/empire.php': ['all', 'empire_info', 'info', 'armyinfo', 'army', 'getwar', 'armyattack', 'armydefence', 'build', 'vip', 'res', 'sell_list', 'terr', 'result', 'sell', 'def_mode', 'pageID'],
'/service_blog.php': ['id', 'uid', 'admin', 'sort', 'pageID', 'cId'],
'/service_foto.php': ['foto_id', 'id', 'new', 'pid', 'uid', 'admin', 'add', 'edit', 'upload', 'show', 'pageID', 'cId'],
'/service_friends.php': ['id', 'pageID'],
'/service_communities.php': ['id', 'sort', 'my', 'allusers', 'forum', 'all', 'questbook', 'add', 'edit', 'users', 'pageID'],
'/adventure_group.php': ['privateadd', 'pageID'],
'/world/graal.php': ['all', 'id', 'pageID'],
'/second_class.php': ['class_change', 'class', 'info'],
'/reqVipStatus.php': ['type', 'k', 'silver'],
'/buystone.php': ['runes', 'stone', 'godstone', 'stuffed', 'graded', 'level1', 'level2', 'pageID', 'buy', 'cnt'],
'/send_gold_gold.php': ['id'],
'/sendMoney.php': ['id'],
'/reqArt.php': ['clan', 'up', 'del', 'type', 'item', 'id', 'level', 'pageID'],
'/arts.php': ['type', 'pageID'],
'/fight_shadow.php': ['fromarena'],
'/waitEnemyMagic.php': ['id'],
'/autocraft.php': ['item'],
'/avatars.php': ['id', 'pageID', 'show'],
'/count_r.php': ['pageID'],
'/geo_stat.php': ['type', 'from', 'country_id', 'town_id', 'pageID'],
'/graph.php': ['type', 'times'],
'/send_gold.php': ['id'],
'/reqChangeTatoo.php': ['item', 'new', 'up'],
'/outgoing.php': ['dealer'],
'/sellArt.php': ['item'],
'/reqCredit.php': ['history', 'pageID'],
'/reqChangeGs.php': ['item', 'new', 'up']
};
(function () {
if (!window.URL) { return; }
var AMP = String.fromCharCode(38);
var KEEP = {
'/index.php': ['tab'],
'/user.php': ['id'],
'/item.php': ['id', 'i', 'us'],
'/inventory.php': ['uid', 'chest', 'folder', 'drop', 'fif', 'wearkit', 'pageID'],
'/mail.php': ['uid', 'history', 'notes', 'nt', 'write', 'clan', 'pageID'],
'/online.php': ['pageID'],
'/service_events.php': ['type', 'all', 'pageID'],
'/craft.php': ['prof'],
'/leader.php': ['use', 'quest', 'panel', 'read', 'up', 'info', 'build', 'hist', 'rank', 'getrank', 'reg', 'message', 'pageID'],
'/sell.php': [],
'/find.php': ['nick', 'how', 'pageID'],
'/apteka.php': ['valor', 'monets', 'klan', 'id', 'pageID'],
'/forge.php': ['hub', 'grav', 'up', 'runes', 'ff', 'gs', 'grade', 'combo', 'combo_skill', 'ex', 'delete', 'delete_rune', 'delete_gs', 'fi'],
'/shop_new.php': ['private', 'clan', 'unique', 'lev', 'razdel', 'type', 'sort', 'myitems', 'info', 'pageID'],
'/shop.php': ['komok', 'valor', 'arena', 'monets', 'pid', 'rid', 'id', 'item', 'original', 'drop', 'cid', 'clan', 'mod', 'pageID'],
'/buy_item.php': ['id', 'komok', 'valor', 'arena', 'monets'],
'/auction.php': ['id', 'pageID'],
'/komok.php': ['auction', 'rent', 'show', 'pageID'],
'/stones.php': [],
'/autobuy.php': [],
'/skill_learn.php': ['class', 'filter', 'myskills', 'info', 'cls', 'pageID'],
'/tatoo.php': ['t', 'info'],
'/sub.php': [],
'/buff.php': ['info'],
'/points.php': [],
'/forex.php': ['buy', 'sell', 'my', 'pageID'],
'/lottery.php': ['gold', 'pageID'],
'/fight_group.php': ['h', 'd', 'pageID'],
'/colisey.php': ['id', 'type', 'olimp', 'k', 'allog', 'pageID'],
'/competitions.php': ['comp'],
'/admin/clan.php': ['pageID'],
'/clan.php': ['id', 'side', 'type', 'sort', 'pageID', 'rating', 'od', 'history', 'uid', 'stats', 'create', 'missions', 'quest', 'p', 'rep', 'repinfo'],
'/forum/': ['id', 'sub_id', 'tid', 'new', 'my', 'clan', 'begin', 'pageID'],
'/forum/index.php': ['id', 'sub_id', 'tid', 'new', 'my', 'clan', 'begin', 'pageID'],
'/forum/post.php': ['id', 'sub_id', 'tid', 'reply'],
'/chat/': ['id', 'pageID', 'f'],
'/chat/index.php': ['id', 'pageID', 'f'],
'/chat/post.php': ['id'],
'/chat/list.php': ['rules', 'pageID', 'insert'],
'/chat/rating.php': ['m', 'pageID'],
'/useItem.php': ['item_id'],
'/anketa.php': ['id', 'gball', 'views', 'change', 'block', 'comm_all', 'fotohow', 'town', 'country', 'l', 'pageID'],
'/menus.php': ['block'],
'/class.php': ['class', 'class_change', 'info', 'myskills'],
'/info.php': ['block', 'id'],
'/read.php': ['file', 'pageID'],
'/table.php': ['health', 'valor', 'clan_level', 'pageID'],
'/faq.php': ['id', 'pageID'],
'/parcels.php': ['read', 'myread', 'myp', 'write', 'who', 'nick', 'pageID'],
'/tournaments_new2.php': ['show', 'grid', 'day', 'users_list', 'type', 'key'],
'/world/castle.php': ['all', 'id', 'hist', 'manage', 'allow_klan', 'allow_warehouse', 'warehouse_log', 'warehouse', 'razdel', 'type', 'drop', 'enterCastle', 'forge', 'hub', 'up', 'grav', 'runes', 'ff', 'gs', 'grade', 'combo', 'combo_skill', 'ex', 'delete', 'delete_rune', 'delete_gs', 'pageID'],
'/world/tower.php': ['all', 'id', 'pageID'],
'/world/build.php': ['id', 'castle'],
'/news.php': ['id', 'lottery', 'pageID'],
'/blocked.php': ['pageID'],
'/olimp.php': ['info', 'shop', 'rating', 'class', 'hist', 'hero_get', 'pageID'],
'/rating.php': ['type', 'race', 'p', 'mm', 'pageID'],
'/logBattle.php': ['id', 'type', 'tournament', 'championat', 'tour', 'grid', 'pageID'],
'/fight.php': ['new'],
'/world/obelisk.php': ['all', 'id', 'pageID'],
'/world/resource.php': []
};
var K2 = window.dwKeep2 || {};
Object.keys(K2).forEach(function (k) { KEEP[k] = K2[k]; });
var SKIP = { '/forum/edit.php': 1, '/addStat.php': 1, '/unsubscribe.php': 1 };
var SESSION = ['sid', 'UIN', 'pass'];
var clean = function (href, noPage) {
var u;
try { u = new URL(href, window.location.href); } catch (e) { return null; }
if (u.origin !== window.location.origin) { return null; }
var path = u.pathname === '/' ? '/index.php' : u.pathname;
if (SKIP[path]) { return null; }
var keep = (KEEP[path] || []).concat(SESSION);
if (path === '/inventory.php') { if (u.searchParams.get('wearkit')) { keep.push('id'); } }
var out = [];
keep.forEach(function (k) {
var v = u.searchParams.get(k);
if (v === null) { return; }
if (v === '') { return; }
if (noPage) { if (k === 'pageID') { return; } }
out.push(encodeURIComponent(k) + '=' + encodeURIComponent(v));
});
return path + (out.length ? '?' + out.join(AMP) : '');
};
window.dwClean = clean;
})();
(function () {
var clean = window.dwClean;
if (!clean) { return; }
var BACK = '\u041d\u0430\u0437\u0430\u0434';
var CITY = '\u0413\u043e\u0440\u043e\u0434';
var read = function (k) { try { return JSON.parse(window.sessionStorage.getItem(k)); } catch (e) { return null; } };
var write = function (k, v) { try { window.sessionStorage.setItem(k, JSON.stringify(v)); } catch (e) {} };
var path = function (u) { return u.split('?')[0]; };
var back = document.getElementById('dw-back');
var links = Array.prototype.filter.call(document.querySelectorAll('.dw-backto'), function (a) { return a !== back; });
var top = links[0] || null;
var plain = top ? top.children.length === 0 : false;
var href0 = top ? top.getAttribute('href') : '';
var text0 = top ? top.textContent : '';
var run = function () {
var here = clean(window.location.href);
if (!here) { return; }
var key = clean(here, 1);
var h = document.querySelector('h1');
var title = h ? h.textContent.replace(/\s+/g, ' ').trim().slice(0, 60) : '';
if (!title) { if (path(here) === '/index.php') { title = CITY; } }
var up = '';
if (top) { if (!top.hasAttribute('data-dw-clean')) { up = clean(href0, 1) || ''; } }
var st = read('dw_back');
st = Array.isArray(st) ? st.filter(function (s) { return typeof s === 'string'; }) : [];
var tm = read('dw_back_t') || {};
var n = st.length;
while (n > 1) {
if (clean(st[n - 2], 1) !== key) { break; }
st.pop();
n--;
}
var same = false;
if (n) {
var last = st[n - 1];
var m = tm[last];
if (clean(last, 1) === key) { same = true; }
else if (title) { if (Array.isArray(m)) { if (path(last) === path(here)) { if (m[0] === title) { same = m[1] === up; } } } }
}
if (same) { st[n - 1] = here; } else { st.push(here); }
st = st.slice(-30);
var meta = {};
st.forEach(function (u) { if (Array.isArray(tm[u])) { meta[u] = tm[u]; } });
meta[here] = [title, up];
write('dw_back', st);
write('dw_back_t', meta);
var prev = st.length > 1 ? st[st.length - 2] : null;
var name = BACK;
if (prev) { if (meta[prev]) { if (typeof meta[prev][0] === 'string') { if (meta[prev][0]) { if (meta[prev][0].length < 25) { name = meta[prev][0]; } } } } }
name = '\u2039 ' + name;
if (plain) {
top.setAttribute('href', href0);
top.textContent = text0;
}
links.forEach(function (a) {
if (!a.hasAttribute('data-dw-clean')) { return; }
var c = clean(a.getAttribute('href'));
if (c) { a.setAttribute('href', c); }
});
if (plain) { if (prev) { if (!top.hasAttribute('data-dw-keep')) {
var mine = clean(href0, 1);
if (mine !== key || top.hasAttribute('data-dw-clean')) {
top.setAttribute('href', prev);
if (mine !== clean(prev, 1)) { top.textContent = name; }
}
} } }
if (!back) { return; }
if (prev) {
back.setAttribute('href', prev);
back.textContent = name;
}
back.hidden = !prev || links.length > 0;
};
run();
window.addEventListener('pageshow', function (event) { if (event.persisted) { run(); } });
})();
(function () {
var mark = document.getElementById('dw-live');
if (!mark) { return; }
if (!window.EventSource) { return; }
if (!window.URL) { return; }
var link = document.querySelector('a[href*="UIN="]');
if (!link) { return; }
var q = new URL(link.href, window.location.href).searchParams;
var parts = ['uid=' + encodeURIComponent(mark.getAttribute('data-uid'))];
var klan = mark.getAttribute('data-klan');
if (klan) { if (klan !== '0') { parts.push('klan=' + encodeURIComponent(klan)); } }
['UIN', 'pass', 'sid'].forEach(function (k) {
var v = q.get(k);
if (v) { parts.push(k + '=' + encodeURIComponent(v)); }
});
var url = '/dw-push/sub?' + parts.join(String.fromCharCode(38));
var root = document.documentElement;
var badge = function (n) {
var a = document.querySelector('.dw-head a.dw-alert[href*="mail.php"]');
if (!a) { return; }
var b = a.querySelector('.dw-alert__n');
if (n > 0) {
if (!b) { b = document.createElement('b'); b.className = 'dw-alert__n'; a.appendChild(b); }
b.textContent = n;
a.classList.add('dw-alert--new');
} else {
if (b) { b.parentNode.removeChild(b); }
a.classList.remove('dw-alert--new');
}
};
window.dwMailBadge = badge;
var uid = mark.getAttribute('data-uid');
var LOCK = 'dw-live-' + uid;
var chan = null;
try { chan = new BroadcastChannel(LOCK); } catch (error) { chan = null; }
var shared = !!chan;
if (shared) { shared = !!(navigator.locks); }
if (shared) { shared = typeof navigator.locks.request === 'function'; }
var tries = 0;
var es = null;
var seen = 0;
var opened = false;
var parked = false;
var parkTimer = 0;
var lead = false;
var claiming = false;
var born = Date.now();
var release = null;
var alive = function () { seen = Date.now(); root.classList.add('dw-live'); };
var tell = function (data) { if (chan) { try { chan.postMessage(data); } catch (error) {} } };
var take = function (data) {
if (data.t === 'new') { if (typeof data.n === 'number') { badge(data.n); } }
document.dispatchEvent(new CustomEvent('dw:mail', { detail: data }));
};
var resync = function () { take({ t: 'resync' }); };
var drop = function () { if (es) { es.close(); es = null; } };
var open = function () {
drop();
if (document.hidden) { if (lead) { resign(); } else { parked = true; } return; }
parked = false;
es = new EventSource(url);
es.onopen = function () {
tries = 0;
alive();
if (opened || Date.now() - born > 5000) { resync(); tell({ t: 'resync' }); }
opened = true;
};
es.addEventListener('ping', function () { alive(); tell({ t: 'ping' }); });
es.onmessage = function (event) {
alive();
var data = null;
try { data = JSON.parse(event.data); } catch (error) { return; }
if (!data) { return; }
take(data);
tell(data);
};
var mine = es;
es.onerror = function () {
if (mine !== es) { return; }
if (es.readyState === 2) {
root.classList.remove('dw-live');
if (document.hidden) { es = null; if (lead) { resign(); } else { parked = true; } return; }
tries += 1;
window.setTimeout(function () { if (lead || !shared) { open(); } }, tries === 1 ? 5000 : (tries === 2 ? 15000 : 60000));
}
};
};
var claim = function () {
if (!shared) { open(); return; }
if (lead) { return; }
if (claiming) { return; }
claiming = true;
navigator.locks.request(LOCK, function () {
claiming = false;
if (document.hidden) { parked = true; return null; }
lead = true;
open();
return new Promise(function (resolve) { release = resolve; });
}).catch(function () { claiming = false; });
};
var resign = function () {
drop();
parked = true;
root.classList.remove('dw-live');
if (lead) { lead = false; if (release) { release(); release = null; } }
};
if (chan) {
chan.onmessage = function (event) {
var data = event.data;
if (!data) { return; }
if (lead) { return; }
alive();
if (data.t === 'ping') { return; }
take(data);
};
}
var park = function () {
if (!document.hidden) { return; }
if (shared) { resign(); return; }
drop();
parked = true;
root.classList.remove('dw-live');
};
window.setInterval(function () {
if (!es) { return; }
if (es.readyState !== 1) { return; }
if (Date.now() - seen < 65000) { return; }
root.classList.remove('dw-live');
open();
}, 15000);
var leave = function () {
window.clearTimeout(parkTimer);
resign();
window.setTimeout(function () { if (!document.hidden) { claim(); } }, 3000);
};
window.addEventListener('beforeunload', leave);
window.addEventListener('pagehide', function () { resign(); });
window.addEventListener('pageshow', function (event) { if (event.persisted) { claim(); } });
var wake = function () {
if (document.hidden) { window.clearTimeout(parkTimer); parkTimer = window.setTimeout(park, 1000); return; }
window.clearTimeout(parkTimer);
var stale = Date.now() - seen >= 40000;
if (shared) {
if (!lead) { claim(); if (stale) { resync(); } return; }
if (!es) { open(); return; }
if (!stale) { return; }
if (es.readyState === 1) { resync(); return; }
open();
return;
}
if (parked) { open(); return; }
if (!es) { return; }
if (!stale) { return; }
if (es.readyState === 1) { resync(); return; }
open();
};
document.addEventListener('visibilitychange', wake);
window.addEventListener('focus', wake);
window.addEventListener('online', wake);
claim();
})();
(function () {
if (!window.fetch) { return; }
if (!window.DOMParser) { return; }
var last = 0;
var busy = false;
var heal = function () {
if (busy) { return; }
if (document.hidden) { return; }
if (Date.now() - last < 20000) { return; }
var mine = document.querySelector('.dw-head .dw-head__alerts');
var link = document.querySelector('a[href*="tab=talk"]');
if (!mine) { return; }
if (!link) { return; }
busy = true;
last = Date.now();
window.fetch(link.href, { credentials: 'same-origin' }).then(function (r) { return r.arrayBuffer(); }).then(function (buffer) {
var doc = new DOMParser().parseFromString(new TextDecoder(document.characterSet).decode(buffer), 'text/html');
var fresh = doc.querySelector('.dw-head .dw-head__alerts');
var now = document.querySelector('.dw-head .dw-head__alerts');
if (fresh) { if (now) { now.parentNode.replaceChild(document.importNode(fresh, true), now); } }
busy = false;
}).catch(function () { busy = false; });
};
document.addEventListener('dw:mail', function (e) { if (e.detail) { if (e.detail.t === 'resync') { heal(); } } });
})();
(function () {
var box = document.getElementById('dw-av');
if (!box) { return; }
var file = document.getElementById('dw-av-file');
var msg = box.querySelector('.dw-av__msg');
var name = box.querySelector('.dw-av__pickname');
var del = box.querySelector('.dw-av__del');
document.addEventListener('click', function (e) { if (box.open) { if (!box.contains(e.target)) { box.open = false; } } });
document.addEventListener('keydown', function (e) { if (e.key === 'Escape') { box.open = false; } });
if (!window.fetch) { return; }
if (!window.FormData) { return; }
if (!file) { return; }
box.classList.add('dw-av--js');
var say = {
size: 'Файл больше 10 МБ.',
type: 'Это не фото: нужен jpg, png, webp или gif.',
big: 'Слишком большой снимок, выберите поменьше.',
limit: 'Не больше 10 смен фото в сутки. Попробуйте завтра.',
auth: 'Вход устарел — обновите страницу.',
read: 'Телефон не отдал файл. Если фото в облаке — сохраните его на телефон и выберите снова.',
fail: 'Не получилось, попробуйте ещё раз.'
};
var note = function (stage, e) {
try {
var u = new URL(file.form.action, window.location.href);
u.searchParams.set('json', '1');
u.searchParams.set('dw_err', (stage + ' ' + (e ? (e.name || '') + ' ' + (e.message || '') : '')).slice(0, 140));
window.fetch(u.toString(), { credentials: 'same-origin' }).catch(function () {});
} catch (x) {}
};
var show = function (t) {
msg.textContent = t;
msg.hidden = !t;
if (t) { box.open = true; }
};
var paint = function (r) {
var on = !!r.s;
document.querySelectorAll('[data-dw-av-box]').forEach(function (b) { b.classList.toggle('dw-av--pic', on); });
document.querySelectorAll('[data-dw-av-me]').forEach(function (im) {
if (on) { im.src = im.getAttribute('data-dw-av-me') === 'l' ? r.l : r.s; } else { im.removeAttribute('src'); }
});
if (name) { name.textContent = on ? 'Сменить фото' : 'Поставить фото'; }
};
var post = function (form, fd) {
if (fd.set) { fd.set('json', '1'); } else { fd.append('json', '1'); }
box.classList.add('dw-av--busy');
return window.fetch(form.action, { method: 'POST', body: fd, credentials: 'same-origin' }).then(function (r) {
return r.json();
}).then(function (r) {
box.classList.remove('dw-av--busy');
if (!r.ok) { throw new Error(r.err || 'fail'); }
return r;
}).catch(function (e) {
box.classList.remove('dw-av--busy');
if (say[e.message]) { show(say[e.message]); return null; }
note('send', e);
show(e.name === 'TypeError' ? say.read : say.fail);
return null;
});
};
var cut = function (src, w, h, f, done) {
try {
var side = Math.min(w, h);
var x = Math.floor((w - side) / 2);
var y = Math.floor((h - side) / (h > w ? 3 : 2));
var n = Math.min(side, 512);
var cv = document.createElement('canvas');
cv.width = n;
cv.height = n;
cv.getContext('2d').drawImage(src, x, y, side, side, 0, 0, n, n);
var png = /png|gif|webp/.test(f.type);
if (!cv.toBlob) { done(f); return; }
cv.toBlob(function (b) { done(b ? new Blob([b], { type: b.type }) : f); }, png ? 'image/png' : 'image/jpeg', 0.9);
} catch (e) { note('cut', e); done(f); }
};
var viaImg = function (f, done) {
if (!window.URL) { done(f); return; }
var url = URL.createObjectURL(f);
var im = new Image();
im.onload = function () { cut(im, im.naturalWidth, im.naturalHeight, f, function (b) { URL.revokeObjectURL(url); done(b); }); };
im.onerror = function () { URL.revokeObjectURL(url); note('decode', null); done(f); };
im.src = url;
};
var square = function (f) {
return new Promise(function (done) {
if (!window.createImageBitmap) { viaImg(f, done); return; }
window.createImageBitmap(f).then(function (bmp) { cut(bmp, bmp.width, bmp.height, f, done); }).catch(function () { viaImg(f, done); });
});
};
file.addEventListener('change', function () {
var f = file.files ? file.files[0] : null;
if (!f) { return; }
show('');
square(f).then(function (one) {
if (one === f) { if (f.size > 10485760) { note('size', { name: 'big', message: String(f.size) }); show(say.size); return null; } }
var fd = new FormData(file.form);
var nm = one.name || (/png/.test(one.type) ? 'photo.png' : 'photo.jpg');
if (fd.set) { fd.set('dw_avatar', one, nm); } else { fd.append('dw_avatar', one, nm); }
return post(file.form, fd);
}).then(function (r) {
file.value = '';
if (r) { paint(r); box.open = false; }
});
});
if (del) {
del.addEventListener('submit', function (e) {
e.preventDefault();
post(del, new FormData(del)).then(function (r) { if (r) { paint({}); box.open = false; } });
});
}
})();