SetsMaster

Наборы армии, навыков и оружия - 3 в 1 (by Tamozhnya1 & Demin)

当前为 2022-06-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name SetsMaster
  3. // @author Tamozhnya1
  4. // @namespace Tamozhnya1
  5. // @description Наборы армии, навыков и оружия - 3 в 1 (by Tamozhnya1 & Demin)
  6. // @homepage https://greasyfork.org/users/1602-demin
  7. // @icon http://i.imgur.com/LZJFLgt.png
  8. // @version 4.3
  9. // @encoding utf-8
  10. // @include http://*heroeswm.ru/*
  11. // @include http://178.248.235.15/*
  12. // @include http://209.200.152.144/*
  13. // @include http://*lordswm.com/*
  14. // @exclude */rightcol.php*
  15. // @exclude */ch_box.php*
  16. // @exclude */chat*
  17. // @exclude */ticker.html*
  18. // @exclude */frames*
  19. // @exclude */brd.php*
  20. // @grant GM_deleteValue
  21. // @grant GM_getValue
  22. // @grant GM_listValues
  23. // @grant GM_setValue
  24. // @grant GM_addStyle
  25. // @grant GM_log
  26. // @grant GM_openInTab
  27. // @license MIT
  28. // ==/UserScript==
  29. // (c) 2012-2015, demin ( http://www.heroeswm.ru/pl_info.php?id=15091 )
  30. // (c) 2012, Tamozhnya1
  31. ensureGmMethods();
  32. var version = '4.3',
  33. url_cur = location.href,
  34. url = 'http://' + location.hostname + '/',
  35. script_num = 124512,
  36. script_name = "SetsMaster: Наборы армии, навыков и оружия - 3 в 1 (by Demin & Tamozhnya1)",
  37. nick,
  38. frak,
  39. menuId = "menuSets";
  40. GlobalCultureName = url.match('lordswm') ? "en-US" : "ru-RU",
  41. Strings = {
  42. "ru-RU": {
  43. Army: ustring("Армия"),
  44. Save: ustring("Сохранить"),
  45. Add: ustring("Добавить"),
  46. AddCurrent: ustring("Добавить текущий"),
  47. SetName: ustring("Наименование набора"),
  48. Delete: ustring("Удалить"),
  49. Talents: ustring("Навыки"),
  50. SavePerkSetAlert: ustring('Сначала выберите навыки и нажмите "Принять"'),
  51. Weapon: ustring("Оружие"),
  52. RemoveAll: ustring("Снять все"),
  53. EnterJpg: "enter0.jpg",
  54. SignInTitle: "Войти",
  55. Castle: "Замок",
  56. Task: "Задание"
  57. },
  58. "en-US": {
  59. Army: "Army",
  60. Save: "Save",
  61. Add: "Add",
  62. AddCurrent: "Add current",
  63. SetName: "Set name",
  64. Delete: "Delete",
  65. Talents: "Talents",
  66. SavePerkSetAlert: 'Please select skills and click on "Accept"',
  67. Weapon: "Weapon",
  68. RemoveAll: "Un-equip all",
  69. EnterJpg: "enter0_eng.jpg",
  70. SignInTitle: "Sign in",
  71. Castle: "Castle",
  72. Task: "Task"
  73. }
  74. },
  75. LocalizedString = Strings[GlobalCultureName];
  76. CalculateUserNameAndFaction();
  77. //update_n(version, script_num, script_name);
  78.  
  79. /************************************************************************************************************/
  80. var armySet = {
  81. oid: 2,
  82. id: "armySet",
  83. name: "<a href='army.php' style='color: #f5c137; text-decoration: none;'>" + LocalizedString.Army + "</a>",
  84. currentSetName: "currentArmySet",
  85. currentSetNumber: undefined,
  86. sets: new Array(),
  87. setObjects: new Array(),
  88. menuItems: {},
  89. currentMenuItem: undefined,
  90. menu: undefined,
  91. savedSetIdsConst: "savedArmySetIds",
  92. savedSetConst: "savedArmySet",
  93. refreshingPages: "home.php;army.php;pl_info.php",
  94. setsTable: null,
  95. getSets: function () {
  96. for(var i = 0; i < this.setObjects.length; i++) {
  97. var setObject = this.setObjects[i];
  98. if(setObject) {
  99. var setName = setObject.name;
  100. var army = setObject.army;
  101. var setTitle = "";
  102. for(var j = 0; j < army.length; j++) {
  103. setTitle += (army[j] == "" ? "0" : army[j]) + "+";
  104. }
  105. setTitle = setTitle.substring(0, setTitle.length - 1);
  106. var data = "";
  107. for(var j = 0; j < army.length; j++) {
  108. data = "countv" + (j + 1) + "=" + (army[j] == "" ? "0" : army[j]) + (data == "" ? "" : "&") + data;
  109. }
  110. this.sets[i] = {
  111. number: parseInt(setObject.oid),
  112. name: setName,
  113. title: setTitle,
  114. method: "POST",
  115. url: "army_apply.php",
  116. data: data,
  117. contentType: "application/x-www-form-urlencoded"
  118. };
  119. }
  120. }
  121. },
  122. init: function () {
  123. this.currentSetNumber = GM_getValue(nick + frak + this.currentSetName, -1);
  124. var savedSetIdsStr = GM_getValue(nick + frak + this.savedSetIdsConst);
  125. var setIds = new Array();
  126. if(savedSetIdsStr) {
  127. setIds = savedSetIdsStr.split("|");
  128. }
  129. for(var i = 0; i < setIds.length; i++) {
  130. if(setIds[i] == "") {
  131. continue;
  132. }
  133. var setStr = GM_getValue(nick + frak + this.savedSetConst + setIds[i]);
  134. if(!setStr) {
  135. continue;
  136. }
  137. var setData = setStr.split("|");
  138. this.setObjects[i] = {
  139. oid: setIds[i],
  140. name: setData[7],
  141. fraction: setData[8],
  142. army: new Array()
  143. };
  144. for(var j = 0; j < 7; j++) {
  145. this.setObjects[i].army[j] = setData[j];
  146. }
  147. }
  148. if(/\/army.php$/.test(location.href)) {
  149. this.drawSetsTable();
  150. }
  151. },
  152. drawSetsTable: function () {
  153. var div = addElement("center", document.querySelector("body"));
  154. addElement("br", div);
  155. this.setsTable = addElement("table", div, { bgcolor: "#959595", bordercolor: "#f5c137", border: "1px" });
  156. this.drawTableHeader();
  157. for (var i = 0; i < this.setObjects.length; i++) {
  158. if (this.setObjects[i]) {
  159. this.drawSetsRow(this.setObjects[i]);
  160. }
  161. }
  162. var saveButton = addElement("input", div, { type: "button", value: LocalizedString.Save });
  163. saveButton.addEventListener("click", this.saveSets);
  164. var addButton = addElement("input", div, { type: "button", value: LocalizedString.Add });
  165. addButton.addEventListener("click", this.addSet);
  166. var addButton = addElement("input", div, { type: "button", value: LocalizedString.AddCurrent });
  167. addButton.addEventListener("click", this.addCurrentSet);
  168. },
  169. drawTableHeader: function () {
  170. if(!this.setsTable) {
  171. return;
  172. }
  173. var units = window.wrappedJSObject.obj;
  174. var tr = addElement("tr", this.setsTable);
  175. var th = addElement("td", tr);
  176. th.style.fontWeight = "bold";
  177. th.innerHTML = LocalizedString.SetName;
  178. for (var i = 1; i <= 7; i++) {
  179. th = addElement("td", tr);
  180. th.style.fontWeight = "bold";
  181. th.innerHTML = units[i]['name'];
  182. }
  183. },
  184. drawSetsRow: function (setObject) {
  185. if(!this.setsTable) {
  186. return;
  187. }
  188. var tr = addElement("tr", this.setsTable, {
  189. oid : setObject.oid
  190. });
  191. var td = addElement("td", tr);
  192. var input = addElement("input", td, {
  193. value : setObject.name,
  194. size : 22
  195. });
  196. for (var i = 0; i < setObject.army.length; i++) {
  197. td = addElement("td", tr);
  198. input = addElement("input", td, { value : setObject.army[i], size : 5 });
  199. }
  200. td = addElement("td", tr);
  201. var delButton = addElement("input", td, { type : "button", value : "x", title : LocalizedString.Delete });
  202. delButton.addEventListener("click", this.deleteSet);
  203. },
  204. saveSets: function () {
  205. var table = armySet.setsTable;
  206. var setIdsStr = "";
  207. for (var i = 1; i < table.rows.length; i++) {
  208. var setStr = "";
  209. var row = table.rows[i];
  210. var oid = row.getAttribute("oid");
  211. setIdsStr = setIdsStr + "|" + oid;
  212. for (var j = 1; j <= 7; j++) {
  213. setStr = setStr + "|" + row.cells[j].firstChild.value;
  214. }
  215. setStr = setStr + "|" + row.cells[0].firstChild.value;
  216. setStr = setStr + "|" + "";
  217. GM_setValue(nick + frak + armySet.savedSetConst + oid, setStr.substr(1));
  218. }
  219. if (setIdsStr && setIdsStr != "") {
  220. GM_setValue(nick + frak + armySet.savedSetIdsConst, setIdsStr.substr(1));
  221. // udalit' udalennye komplekty
  222. if (typeof GM_listValues == 'function') {
  223. var clear_d = GM_listValues();
  224. var clear_d_len = clear_d.length;
  225. var num_id_regexp = new RegExp(nick + frak + armySet.savedSetConst + '(\\d+)');
  226. var num_id;
  227. for (var i = clear_d_len; i--; ) {
  228. num_id = num_id_regexp.exec(clear_d[i]);
  229. if (num_id && !setIdsStr.match(num_id[1])) {
  230. GM_deleteValue(clear_d[i]);
  231. }
  232. }
  233. }
  234. } else {
  235. GM_deleteValue(nick + frak + armySet.savedSetIdsConst);
  236. GM_deleteValue(armySet.currentSetName);
  237. // udalit' udalennye komplekty
  238. if (typeof GM_listValues == 'function') {
  239. var clear_d = GM_listValues();
  240. var clear_d_len = clear_d.length;
  241. var num_id_regexp = new RegExp(nick + frak + armySet.savedSetConst + '(\\d+)');
  242. var num_id;
  243. for (var i = clear_d_len; i--; ) {
  244. num_id = num_id_regexp.exec(clear_d[i]);
  245. if (num_id) {
  246. GM_deleteValue(clear_d[i]);
  247. }
  248. }
  249. }
  250. }
  251. },
  252. addSet: function () {
  253. armySet.drawSetsRow({
  254. oid : (new Date()).getTime(),
  255. name : "",
  256. army : ["", "", "", "", "", "", ""]
  257. });
  258. },
  259. addCurrentSet: function () {
  260. var units = window.wrappedJSObject.obj;
  261. var army = {
  262. oid : (new Date()).getTime(),
  263. name : "",
  264. army : [units[1]['nownumberd'], units[2]['nownumberd'], units[3]['nownumberd'], units[4]['nownumberd'], units[5]['nownumberd'], units[6]['nownumberd'], units[7]['nownumberd']]
  265. };
  266. armySet.drawSetsRow(army);
  267. },
  268. deleteSet: function () {
  269. var table = this.parentNode.parentNode.parentNode;
  270. var row = this.parentNode.parentNode;
  271. table.removeChild(row);
  272. }
  273. };
  274. /***********************************************************************************************************/
  275. var skillSet = {
  276. oid: 1,
  277. id: "skillSet",
  278. name: "<a href='skillwheel.php' style='color: #f5c137; text-decoration: none;'>" + LocalizedString.Talents + "</a>",
  279. currentSetName: "currentSkillSet",
  280. currentSetNumber: undefined,
  281. sets: new Array(),
  282. menuItems: {},
  283. currentMenuItem: undefined,
  284. menu: undefined,
  285. refreshingPages: "skillwheel.php;pl_info.php",
  286. getSets: function () {
  287. var setRefs = document.querySelectorAll("a[href^='skillwheel.php?setuserperk']");
  288. for(var i = 0; i < setRefs.length; i++) {
  289. this.sets[i] = { number: i, name: setRefs[i].innerHTML, title: '', method: "GET", url: setRefs[i].href }
  290. addSetChangerListener(setRefs[i], this.oid, i);
  291. }
  292. },
  293. init: function () {
  294. this.currentSetNumber = GM_getValue(nick + frak + this.currentSetName, -1);
  295. }
  296. };
  297. /************************************************************************************************************/
  298. var weaponSet = {
  299. oid: 0,
  300. id: "weaponSet",
  301. name: "<a href='inventory.php' style='color: #f5c137; text-decoration: none;'>" + LocalizedString.Weapon + "</a>",
  302. currentSetName: nick + "currentWeaponSet",
  303. currentSetNumber: undefined,
  304. sets: new Array(),
  305. menuItems: {},
  306. currentMenuItem: undefined,
  307. menu: undefined,
  308. refreshingPages: "home.php;inventory.php;pl_info.php",
  309. refreshingConditions: function() {
  310. if(/map.php/.test(location.href)) {
  311. var bolds = document.querySelectorAll("b");
  312. for(var i = 0; i < bolds.length; i++) {
  313. if(bolds[i].innerText.includes(LocalizedString.Task)) {
  314. return true;
  315. }
  316. }
  317. var neut_right_block = document.querySelector("div[id='neut_right_block']");
  318. if(neut_right_block) {
  319. return true;
  320. }
  321. }
  322. return false;
  323. },
  324. getSets: function() {
  325. this.sets[0] = { number: 0, name: LocalizedString.RemoveAll, method: "GET", url: "inventory.php?all_off=100" }
  326. for (var i = 1; i <= 5; i++) {
  327. var setName = GM_getValue(nick + "weaponSet" + i);
  328. if (setName) {
  329. this.sets[i] = { number: i, name: setName, method: "GET", url: "inventory.php?all_on=" + i, headers: null }
  330. }
  331. }
  332. },
  333. init: function() {
  334. this.currentSetNumber = GM_getValue(this.currentSetName, -1);
  335. if(/inventory.php/.test(location.href)) {
  336. var undressDiv = document.querySelector("div[id ='undress_all_div']");
  337. addSetChangerListener(undressDiv, this.oid, 0);
  338. var setDivs = document.querySelectorAll("div[set_div_id]");
  339. for(var i = 0; i < setDivs.length; i++) {
  340. var setNumber = setDivs[i].getAttribute("set_div_id");
  341. if(setDivs[i].hasAttribute("onclick")) {
  342. addSetChangerListener(setDivs[i], this.oid, setNumber);
  343. GM_setValue(nick + "weaponSet" + setNumber, setDivs[i].innerText);
  344. } else {
  345. GM_deleteValue(nick + "weaponSet" + setNumber);
  346. }
  347. }
  348. }
  349. this.findSetChangersAndAddListener();
  350. },
  351. findSetChangersAndAddListener: function() {
  352. var setRefs = document.querySelectorAll("a[href^='inventory.php?all_off=100']");
  353. for(var i = 0; i < setRefs.length; i++) {
  354. addSetChangerListener(setRefs[i], this.oid, 0);
  355. }
  356. var setRefs = document.querySelectorAll("a[href*='inventory.php?all_on=']");
  357. for(var i = 0; i < setRefs.length; i++) {
  358. var weaponSetReference = setRefs[i];
  359. var setNumber = weaponSetReference.getAttribute("href").split("all_on=")[1];
  360. addSetChangerListener(weaponSetReference, this.oid, setNumber);
  361. }
  362. }
  363. };
  364. /************************************************************************************************************/
  365. var castlesSet = {
  366. oid: 3,
  367. id: "castle",
  368. name: "<a href='castle.php' style='color: #f5c137; text-decoration: none;'>" + LocalizedString.Castle + "</a>",
  369. currentSetName: nick + "currentCastle",
  370. currentSetNumber: undefined,
  371. sets: new Array(),
  372. menuItems: {},
  373. currentMenuItem: undefined,
  374. menu: undefined,
  375. availableCastleNames: nick + "availableCastleNames",
  376. refreshingPages: "home.php;army.php;pl_info.php;castle.php",
  377. userCastleSign: undefined,
  378. userCastleSignName: nick + "userCastleSign",
  379. getSets: function() {
  380. let serializedCastlesInfo = GM_getValue(this.availableCastleNames);
  381. if(serializedCastlesInfo) {
  382. let castles = serializedCastlesInfo.split("&");
  383. for(var i = 0; i < castles.length; i++) {
  384. let castleName = castles[i].split("=")[0];
  385. let castleNumber = castles[i].split("=")[1];
  386. this.sets[i] = { number: castleNumber, name: castleName, method: "GET" };
  387. if(this.userCastleSign) {
  388. this.sets[i].url = "castle.php?change_clr_to=" + castleNumber + "&sign=" + this.userCastleSign;
  389. }
  390. }
  391. }
  392. },
  393. init: function () {
  394. this.initCastlesList();
  395. this.currentSetNumber = GM_getValue(this.currentSetName, -1);
  396. this.userCastleSign = GM_getValue(this.userCastleSignName);
  397. this.findSetChangersAndAddListener();
  398. },
  399. initCastlesList: function () {
  400. if(!/castle.php/.test(location.href)) {
  401. return;
  402. }
  403. let castleNamesDivs = document.querySelectorAll("div.castle_faction_div_inside");
  404. let serializedCastlesInfo = "";
  405. for(let castleNamesDivIndex = 0; castleNamesDivIndex < castleNamesDivs.length; castleNamesDivIndex++) {
  406. let castleNameDiv = castleNamesDivs[castleNamesDivIndex];
  407. let castleName = castleNameDiv.getAttribute("hint");
  408. let castleSelectRef = castleNameDiv.firstChild.getAttribute("href");
  409. let castleNumber = castleSelectRef.split("=")[1];
  410. serializedCastlesInfo = serializedCastlesInfo + (serializedCastlesInfo == "" ? "" : "&") + castleName + "=" + castleNumber;
  411. }
  412. GM_setValue(this.availableCastleNames, serializedCastlesInfo);
  413. let castle_yes_no_dialogDiv = document.querySelector("div.castle_yes_no_dialog");
  414. if(castle_yes_no_dialogDiv) {
  415. let changeCastleRef = castle_yes_no_dialogDiv.querySelector("a[href*='castle.php?change_clr_to']");
  416. if(changeCastleRef) {
  417. let userCastleSign = changeCastleRef.getAttribute("href").split("?")[1].split("&")[1].split("=")[1];
  418. GM_setValue(this.userCastleSignName, userCastleSign);
  419. }
  420. }
  421. },
  422. findSetChangersAndAddListener: function() {
  423. let setRefs = document.querySelectorAll("a[href*='castle.php?change_clr_to']");
  424. for(let i = 0; i < setRefs.length; i++) {
  425. let changeCastleRef = setRefs[i];
  426. let setNumber = changeCastleRef.getAttribute("href").split("?")[1].split("&")[0].split("=")[1];
  427. addSetChangerListener(changeCastleRef, this.oid, setNumber);
  428. }
  429. },
  430. setChanged: function(newSetNumber) {
  431. frak = "r" + newSetNumber + "_";
  432. GM_setValue(nick + "frak", frak);
  433. }
  434. };
  435. /************************************************************************************************************/
  436. var setObjects = new Array();
  437. setObjects[weaponSet.oid] = weaponSet;
  438. setObjects[armySet.oid] = armySet;
  439. setObjects[skillSet.oid] = skillSet;
  440. setObjects[castlesSet.oid] = castlesSet;
  441. var timer;
  442.  
  443. if(document.querySelector("body") && nick && frak) {
  444. main();
  445. }
  446.  
  447. function main() {
  448. var menuId = "menuSetsTable";
  449. var logobEngChild = document.querySelector("img[src*='logob_eng']");
  450. if(!logobEngChild) {
  451. return;
  452. }
  453. var styleObject = { borderColor : "#f5c137", background : "#6b6b69", color : "#f5c137", "z-index": "100" }
  454. if(document.querySelector("img[src*='i/top_ny']")) {
  455. styleObject.background = "#003399";
  456. }
  457. var offSet = -106;
  458. for(var i = 0; i < setObjects.length; i++) {
  459. if(!setObjects[i]) {
  460. continue;
  461. }
  462. var currentSetObject = setObjects[i];
  463. if(currentSetObject.init) {
  464. currentSetObject.init();
  465. }
  466. currentSetObject.getSets();
  467.  
  468. if(i > 0) {
  469. offSet += $(menuId + (i - 1) + "Header").clientWidth;
  470. }
  471. var menuHeaderStyleObject = {
  472. position: "absolute",
  473. margin: "2px 0px 0px " + offSet + "px",
  474. background: styleObject.background,
  475. color: styleObject.color,
  476. border: "1px solid " + styleObject.borderColor,
  477. "font-weight": "bold",
  478. padding: "2px 6px 4px 5px",
  479. "z-index": (url_cur.match('photo_pl_photos') ? "0" : "100")
  480. }
  481. var menuHeader = addElement("div", logobEngChild.parentNode, { id: menuId + i + "Header", headerId: menuId + i + "Header", menuId: menuId + i }, menuHeaderStyleObject);
  482. var aLevel1 = addElement("b", menuHeader, {}, "color: #f5c137;");
  483. // aLevel1.style.cursor = "pointer";
  484. aLevel1.innerHTML = currentSetObject.name;
  485. currentSetObject.menu = aLevel1;
  486. var menuContent = addElement("div", menuHeader, { id: menuId + i, headerId: menuId + i + "Header", menuId: menuId + i }, "position: relative; padding: 6px 3px 2px 3px; white-space: nowrap;");
  487. menuHeader.addEventListener("mouseover", showMenu, false);
  488. menuHeader.addEventListener("mouseout", hideMenu, false);
  489. menuContent.addEventListener("mouseover", showMenuCont, false);
  490. menuContent.addEventListener("mouseout", hideMenu, false);
  491. for(var j = 0; j < currentSetObject.sets.length; j++) {
  492. var currentSet = currentSetObject.sets[j];
  493. if(!currentSet) {
  494. continue;
  495. }
  496. var liLevel2 = addElement(url_cur.match('photo_pl_photos') ? "div" : "li", menuContent, { type: "disc", title: currentSetObject.title || "" });
  497. var aLevel2 = addElement("b", liLevel2, currentSet, "color: #f5c137;");
  498. aLevel2.style.cursor = "pointer";
  499. aLevel2.innerHTML = currentSet.name;
  500. if(currentSet.url) {
  501. aLevel2.addEventListener("click", applySet, false);
  502. }
  503. aLevel2.setAttribute("oid", currentSetObject.oid);
  504. if(currentSet.number == currentSetObject.currentSetNumber) {
  505. markCurrent(aLevel2);
  506. }
  507. currentSetObject.menuItems[j] = aLevel2;
  508. }
  509. $(menuId + i).style.width = ($(menuId + i).clientWidth + 20) + "px";
  510. $(menuId + i).style.display = "none";
  511. }
  512. }
  513. function showMenu() {
  514. var menu = $(this.getAttribute("menuId"));
  515. timer = setTimeout(function () {
  516. if (menu) {
  517. menu.style.display = "block";
  518. }
  519. }, 100);
  520. }
  521. function showMenuCont() {
  522. var menu = $(this.getAttribute("menuId"));
  523. if (menu) {
  524. menu.style.display = "block";
  525. }
  526. }
  527. function hideMenu() {
  528. if (timer) {
  529. clearTimeout(timer);
  530. }
  531. var menu = $(this.getAttribute("menuId"));
  532. if (menu) {
  533. menu.style.display = "none";
  534. }
  535. }
  536. function markCurrentEventHandler(e) {
  537. var obj = setObjects[this.getAttribute("oid")];
  538. var menuItemToMark = obj.menuItems[this.getAttribute("number")];
  539. markCurrent(menuItemToMark);
  540. }
  541. function markCurrent(el) {
  542. var obj = setObjects[el.getAttribute("oid")];
  543. GM_setValue(obj.currentSetName, el.getAttribute("number"));
  544. el.style.color = '#0f0';
  545. if (obj.currentMenuItem && obj.currentMenuItem != el) {
  546. obj.currentMenuItem.style.color = "#f5c137";
  547. }
  548. obj.currentMenuItem = el;
  549. }
  550. function addSetChangerListener(htmlElement, setObjectId, setNumber) {
  551. htmlElement.addEventListener("click", markCurrentEventHandler, false);
  552. htmlElement.setAttribute("number", setNumber);
  553. htmlElement.setAttribute("oid", setObjectId);
  554. }
  555. function applySet() {
  556. markCurrent(this);
  557. var obj = setObjects[parseInt(this.getAttribute("oid"))];
  558. var setNumber = this.getAttribute("number");
  559. var _this = this;
  560. var title = this.innerHTML;
  561. this.innerHTML += " " + getLoadGif();
  562. var objXMLHttpReqSM = new XMLHttpRequest();
  563. objXMLHttpReqSM.open(this.getAttribute("method"), this.getAttribute("url"), true);
  564. objXMLHttpReqSM.onreadystatechange = function () {
  565. if (objXMLHttpReqSM.readyState == 2) {
  566. objXMLHttpReqSM.abort();
  567. _this.innerHTML = title;
  568. if(typeof(obj.setChanged) == "function") {
  569. obj.setChanged(setNumber);
  570. }
  571. if(obj.refreshingPages) {
  572. var pages = obj.refreshingPages.split(';');
  573. for(var i = 0; i < pages.length; i++) {
  574. if(location.href.indexOf(pages[i]) > -1) {
  575. window.location.href = window.location.href;
  576. }
  577. }
  578. }
  579. if(obj.refreshingConditions && obj.refreshingConditions()) {
  580. window.location.href = window.location.href;
  581. }
  582. }
  583. };
  584. var contentType = this.getAttribute("contentType");
  585. if (contentType) {
  586. objXMLHttpReqSM.setRequestHeader('Content-type', contentType);
  587. }
  588. objXMLHttpReqSM.send(this.getAttribute("data"));
  589. return false;
  590. }
  591. function addElement(type, parent, data, style) {
  592. var el = document.createElement(type);
  593. if (parent) {
  594. parent.appendChild(el);
  595. }
  596. if (data) {
  597. for (var key in data) {
  598. el.setAttribute(key, data[key]);
  599. }
  600. }
  601. if (style && el.id) {
  602. var styleStr = "";
  603. if (typeof(style) == "string") {
  604. styleStr = style;
  605. } else {
  606. for (var key in style) {
  607. styleStr += key + ": " + style[key] + "; ";
  608. }
  609. }
  610. GM_addStyle("#" + el.id + "{" + styleStr + "}");
  611. }
  612. return el;
  613. }
  614. function getLoadGif() {
  615. return '<img border="0" align="absmiddle" height="11" src="data:image/gif;base64,' +
  616. 'R0lGODlhEAAQAMQAAP///+7u7t3d3bu7u6qqqpmZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREQAR' +
  617. 'AAAAAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05F' +
  618. 'VFNDQVBFMi4wAwEAAAAh+QQFBwAQACwAAAAAEAAQAAAFdyAkQgGJJOWoQgIjBM8jkKsoPEzgyMGs' +
  619. 'CjPDw7ADpkQBxRDmSCRetpRA6Rj4kFBkgLC4IlUGhbNQIwXOYYWCXDufzYPDMaoKGBoKb886OjAK' +
  620. 'dgZAAgQkfCwzAgsDBAUCgl8jAQkHEAVkAoA1AgczlyIDczUDA2UhACH5BAUHABAALAAAAAAPABAA' +
  621. 'AAVjICSO0IGIATkqIiMKDaGKC8Q49jPMYsE0hQdrlABCGgvT45FKiRKQhWA0mPKGPAgBcTjsspBC' +
  622. 'AoH4gl+FmXNEUEBVAYHToJAVZK/XWoQQDAgBZioHaX8igigFKYYQVlkCjiMhACH5BAUHABAALAAA' +
  623. 'AAAQAA8AAAVgICSOUGGQqIiIChMESyo6CdQGdRqUENESI8FAdFgAFwqDISYwPB4CVSMnEhSej+Fo' +
  624. 'gNhtHyfRQFmIol5owmEta/fcKITB6y4choMBmk7yGgSAEAJ8JAVDgQFmKUCCZnwhACH5BAUHABAA' +
  625. 'LAAAAAAQABAAAAViICSOYkGe4hFAiSImAwotB+si6Co2QxvjAYHIgBAqDoWCK2Bq6A40iA4yYMgg' +
  626. 'NZKwGFgVCAQZotFwwJIF4QnxaC9IsZNgLtAJDKbraJCGzPVSIgEDXVNXA0JdgH6ChoCKKCEAIfkE' +
  627. 'BQcAEAAsAAAAABAADgAABUkgJI7QcZComIjPw6bs2kINLB5uW9Bo0gyQx8LkKgVHiccKVdyRlqjF' +
  628. 'SAApOKOtR810StVeU9RAmLqOxi0qRG3LptikAVQEh4UAACH5BAUHABAALAAAAAAQABAAAAVxICSO' +
  629. '0DCQKBQQonGIh5AGB2sYkMHIqYAIN0EDRxoQZIaC6bAoMRSiwMAwCIwCggRkwRMJWKSAomBVCc5l' +
  630. 'UiGRUBjO6FSBwWggwijBooDCdiFfIlBRAlYBZQ0PWRANaSkED1oQYHgjDA8nM3kPfCmejiEAIfkE' +
  631. 'BQcAEAAsAAAAABAAEAAABWAgJI6QIJCoOIhFwabsSbiFAotGMEMKgZoB3cBUQIgURpFgmEI0EqjA' +
  632. 'CYXwiYJBGAGBgGIDWsVicbiNEgSsGbKCIMCwA4IBCRgXt8bDACkvYQF6U1OADg8mDlaACQtwJCEA' +
  633. 'IfkEBQcAEAAsAAABABAADwAABV4gJEKCOAwiMa4Q2qIDwq4wiriBmItCCREHUsIwCgh2q8MiyEKO' +
  634. 'DK7ZbHCoqqSjWGKI1d2kRp+RAWGyHg+DQUEmKliGx4HBKECIMwG61AgssAQPKA19EAxRKz4QCVIh' +
  635. 'ACH5BAUHABAALAAAAAAQABAAAAVjICSOUBCQqHhCgiAOKyqcLVvEZOC2geGiK5NpQBAZCilgAYFM' +
  636. 'ogo/J0lgqEpHgoO2+GIMUL6p4vFojhQNg8rxWLgYBQJCASkwEKLC17hYFJtRIwwBfRAJDk4Obwsi' +
  637. 'dEkrWkkhACH5BAUHABAALAAAAQAQAA8AAAVcICSOUGAGAqmKpjis6vmuqSrUxQyPhDEEtpUOgmgY' +
  638. 'ETCCcrB4OBWwQsGHEhQatVFhB/mNAojFVsQgBhgKpSHRTRxEhGwhoRg0CCXYAkKHHPZCZRAKUERZ' +
  639. 'MAYGMCEAIfkEBQcAEAAsAAABABAADwAABV0gJI4kFJToGAilwKLCST6PUcrB8A70844CXenwILRk' +
  640. 'IoYyBRk4BQlHo3FIOQmvAEGBMpYSop/IgPBCFpCqIuEsIESHgkgoJxwQAjSzwb1DClwwgQhgAVVM' +
  641. 'IgVyKCEAIfkECQcAEAAsAAAAABAAEAAABWQgJI5kSQ6NYK7Dw6xr8hCw+ELC85hCIAq3Am0U6JUK' +
  642. 'jkHJNzIsFAqDqShQHRhY6bKqgvgGCZOSFDhAUiWCYQwJSxGHKqGAE/5EqIHBjOgyRQELCBB7EAQH' +
  643. 'fySDhGYQdDWGQyUhADs=">';
  644. }
  645. function $(id) {
  646. return document.querySelector("#" + id);
  647. }
  648. function addEvent(elem, evType, fn) {
  649. if (elem.addEventListener) {
  650. elem.addEventListener(evType, fn, false);
  651. } else if (elem.attachEvent) {
  652. elem.attachEvent("on" + evType, fn);
  653. } else {
  654. elem["on" + evType] = fn;
  655. }
  656. }
  657. function update_n(a, b, c, d, e) {
  658. if (e) {
  659. e++
  660. } else {
  661. e = 1;
  662. d = (Number(GM_getValue(b + '_update_script_last2', '0')) || 0)
  663. }
  664. if (e > 3) {
  665. return
  666. }
  667. var f = new Date().getTime();
  668. var g = document.querySelector('#update_demin_script2');
  669. if (g) {
  670. if ((d + 86400000 < f) || (d > f)) {
  671. g = g.innerHTML;
  672. if (/100000=1.1/.exec(g)) {
  673. var h = new RegExp(b + '=(\\d+\\.\\d+)=(\\d+)').exec(g);
  674. var i = /url7=([^%]+)/.exec(g);
  675. if (a && h && i) {
  676. if (Number(h[1]) > Number(a))
  677. setTimeout(function () {
  678. if (confirm('\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u043E \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u0435 \u0441\u043A\u0440\u0438\u043F\u0442\u0430: "' + c + '".\n\u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u044C \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u043D\u0443\u044E \u0432\u0435\u0440\u0441\u0438\u044E \u0441\u0435\u0439\u0447\u0430\u0441?\n\nThere is an update available for the script: "' + c + '".\nWould you like install the script now?')) {
  679. if (typeof GM_openInTab == 'function') {
  680. GM_openInTab(i[1].replace(/\s/g, '') + h[2])
  681. } else {
  682. window.open(i[1].replace(/\s/g, '') + h[2], '_blank')
  683. }
  684. }
  685. }, 500)
  686. }
  687. GM_setValue(b + '_update_script_last2', '' + f)
  688. } else {
  689. setTimeout(function () {
  690. update_n(a, b, c, d, e)
  691. }, 1000)
  692. }
  693. }
  694. } else {
  695. var j = document.querySelector('body');
  696. if (j) {
  697. var k = GM_getValue(b + '_update_script_array2');
  698. if (e == 1 && ((d + 86400000 < f) || (d > f) || !k)) {
  699. if (k) {
  700. GM_deleteValue(b + '_update_script_array2')
  701. }
  702. setTimeout(function () {
  703. update_n(a, b, c, d, e)
  704. }, 1000);
  705. return
  706. }
  707. var l = document.createElement('div');
  708. l.id = 'update_demin_script2';
  709. l.setAttribute('style', 'position: absolute; width: 0px; height: 0px; top: 0px; left: 0px; display: none;');
  710. l.innerHTML = '';
  711. j.appendChild(l);
  712. if ((d + 86400000 < f) || (d > f) || !k) {
  713. var m = new XMLHttpRequest();
  714. m.open('GET', 'photo_pl_photos.php?aid=1777' + '&rand=' + (Math.random() * 100), true);
  715. m.onreadystatechange = function () {
  716. update(m, a, b, c, d, e)
  717. };
  718. m.send(null)
  719. } else {
  720. document.querySelector('#update_demin_script2').innerHTML = k;
  721. setTimeout(function () {
  722. update_n(a, b, c, d, e)
  723. }, 10)
  724. }
  725. }
  726. }
  727. }
  728. function update(a, b, c, d, e, f) {
  729. if (a.readyState == 4 && a.status == 200) {
  730. a = a.responseText;
  731. var g = /(\d+=\d+\.\d+(=\d+)*)/g;
  732. var h = '';
  733. var i = /(url7=[^%]+\%)/.exec(a);
  734. if (i) {
  735. h += i[1]
  736. }
  737. while ((i = g.exec(a)) != null) {
  738. if (h.indexOf(i[1]) == -1) {
  739. h += ' ' + i[1]
  740. }
  741. };
  742. GM_setValue(c + '_update_script_array2', '' + h);
  743. var j = document.querySelector('#update_demin_script2');
  744. if (j) {
  745. j.innerHTML = h;
  746. setTimeout(function () {
  747. update_n(b, c, d, e, f)
  748. }, 10)
  749. }
  750. }
  751. }
  752. function ensureGmMethods() {
  753. if (!this.GM_getValue) {
  754. this.GM_getValue = function (key, def) {
  755. return localStorage[key] || def;
  756. };
  757. this.GM_setValue = function (key, value) {
  758. return localStorage[key] = value;
  759. };
  760. this.GM_deleteValue = function (key) {
  761. return delete localStorage[key];
  762. };
  763. }
  764. if (!this.GM_addStyle) {
  765. this.GM_addStyle = function (key) {
  766. var style = document.createElement('style');
  767. style.textContent = key;
  768. document.querySelector("head").appendChild(style);
  769. }
  770. }
  771. if (!this.GM_listValues) {
  772. this.GM_listValues = function () {
  773. var values = [];
  774. for (var i = 0; i < localStorage.length; i++) {
  775. values.push(localStorage.key(i));
  776. }
  777. return values;
  778. }
  779. }
  780. }
  781. function CalculateUserNameAndFaction() {
  782. var enterButton = document.querySelector("input[src$='" + LocalizedString.EnterJpg + "']");
  783. if(/login.php$/.test(location.href)) {
  784. enterButton = document.querySelector("input[value='" + LocalizedString.SignInTitle + "']");
  785. }
  786. var loginTextBox = document.querySelector("input[name='login']");
  787. if(enterButton && loginTextBox) {
  788. enterButton.addEventListener("click", function() { GM_setValue("UserName", loginTextBox.value + "_"); })
  789. } else {
  790. nick = GM_getValue("UserName");
  791. if(!nick) {
  792. return;
  793. }
  794. nick = encodeURIComponent(nick);
  795. let currentFactionNumber = undefined;
  796. if(location.pathname == '/home.php') {
  797. var currentHeroFactionGifInfo = /\/i\/f\/(r\d+)\.png/.exec(document.querySelector("body").innerHTML);
  798. if (currentHeroFactionGifInfo) {
  799. currentFactionNumber = currentHeroFactionGifInfo[1].substring(1);
  800. }
  801. } else if(location.pathname=='/pl_info.php') {
  802. var temp_nick = nick;
  803. var temp_regexp = new RegExp(temp_nick.slice(0, -1)+'.\{30,150\}\\/i\\/f\\/(r\\d+)\\.png');
  804. let frakPng = temp_regexp.exec( document.querySelector("body").innerHTML );
  805. if(frakPng) {
  806. currentFactionNumber = frakPng[1].substring(1);
  807. }
  808. } else if(location.pathname=='/castle.php') {
  809. var selectedFactionImg = document.querySelector("div.castle_faction_div_inside2 img");
  810. var selectedFactionImgName = selectedFactionImg.getAttribute("src");
  811. var selectedFactionNumber = selectedFactionImgName.split("kukla_png/kukla")[1].split(".")[0]; //dcdn.heroeswm.ru/i/kukla_png/kukla5.png
  812. let faction_listDiv = document.querySelector("div[id='faction_list']");
  813. if(faction_listDiv.getAttribute("style").includes("display:none;")) {
  814. currentFactionNumber = selectedFactionNumber;
  815. }
  816. }
  817. if(currentFactionNumber) {
  818. GM_setValue(nick + "currentCastle", currentFactionNumber);
  819. GM_setValue(nick + "frak", "r" + currentFactionNumber + "_");
  820. }
  821. frak = GM_getValue(nick + "frak");
  822. }
  823. }
  824. function uchar(s) {
  825. switch (s[0]) {
  826. case "А":
  827. return "\u0410";
  828. case "Б":
  829. return "\u0411";
  830. case "В":
  831. return "\u0412";
  832. case "Г":
  833. return "\u0413";
  834. case "Д":
  835. return "\u0414";
  836. case "Е":
  837. return "\u0415";
  838. case "Ж":
  839. return "\u0416";
  840. case "З":
  841. return "\u0417";
  842. case "И":
  843. return "\u0418";
  844. case "Й":
  845. return "\u0419";
  846. case "К":
  847. return "\u041a";
  848. case "Л":
  849. return "\u041b";
  850. case "М":
  851. return "\u041c";
  852. case "Н":
  853. return "\u041d";
  854. case "О":
  855. return "\u041e";
  856. case "П":
  857. return "\u041f";
  858. case "Р":
  859. return "\u0420";
  860. case "С":
  861. return "\u0421";
  862. case "Т":
  863. return "\u0422";
  864. case "У":
  865. return "\u0423";
  866. case "Ф":
  867. return "\u0424";
  868. case "Х":
  869. return "\u0425";
  870. case "Ц":
  871. return "\u0426";
  872. case "Ч":
  873. return "\u0427";
  874. case "Ш":
  875. return "\u0428";
  876. case "Щ":
  877. return "\u0429";
  878. case "Ъ":
  879. return "\u042a";
  880. case "Ы":
  881. return "\u042b";
  882. case "Ь":
  883. return "\u042c";
  884. case "Э":
  885. return "\u042d";
  886. case "Ю":
  887. return "\u042e";
  888. case "Я":
  889. return "\u042f";
  890. case "а":
  891. return "\u0430";
  892. case "б":
  893. return "\u0431";
  894. case "в":
  895. return "\u0432";
  896. case "г":
  897. return "\u0433";
  898. case "д":
  899. return "\u0434";
  900. case "е":
  901. return "\u0435";
  902. case "ж":
  903. return "\u0436";
  904. case "з":
  905. return "\u0437";
  906. case "и":
  907. return "\u0438";
  908. case "й":
  909. return "\u0439";
  910. case "к":
  911. return "\u043a";
  912. case "л":
  913. return "\u043b";
  914. case "м":
  915. return "\u043c";
  916. case "н":
  917. return "\u043d";
  918. case "о":
  919. return "\u043e";
  920. case "п":
  921. return "\u043f";
  922. case "р":
  923. return "\u0440";
  924. case "с":
  925. return "\u0441";
  926. case "т":
  927. return "\u0442";
  928. case "у":
  929. return "\u0443";
  930. case "ф":
  931. return "\u0444";
  932. case "х":
  933. return "\u0445";
  934. case "ц":
  935. return "\u0446";
  936. case "ч":
  937. return "\u0447";
  938. case "ш":
  939. return "\u0448";
  940. case "щ":
  941. return "\u0449";
  942. case "ъ":
  943. return "\u044a";
  944. case "ы":
  945. return "\u044b";
  946. case "ь":
  947. return "\u044c";
  948. case "э":
  949. return "\u044d";
  950. case "ю":
  951. return "\u044e";
  952. case "я":
  953. return "\u044f";
  954. case "Ё":
  955. return "\u0401";
  956. case "ё":
  957. return "\u0451";
  958. default:
  959. return s[0];
  960. }
  961. }
  962. function ustring(s) {
  963. s = String(s);
  964. var result = "";
  965. for (var i = 0; i < s.length; i++) {
  966. result += uchar(s[i]);
  967. }
  968. return result;
  969. }
  970.