您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Расширенное меню
当前为
// ==UserScript== // @name hwmAdvancedMenu // @namespace Tamozhnya1 // @author Tamozhnya1 // @description Расширенное меню // @version 1.0 // @include *heroeswm.ru/* // @include *lordswm.com/* // @exclude */rightcol.php* // @exclude */ch_box.php* // @exclude */chat* // @exclude */ticker.html* // @exclude */frames* // @exclude */brd.php* // @license MIT // ==/UserScript== if(!this.GM_getValue) { this.GM_getValue = function(key, def) { return localStorage[key] || def; }; this.GM_setValue = function(key, value) { localStorage[key] = value; }; this.GM_deleteValue = function(key) { return delete localStorage[key]; }; } const playerIdMatch = document.cookie.match(/pl_id=(\d+)/); if(!playerIdMatch) { return; } const PlayerId = playerIdMatch[1]; const isEn = document.documentElement.lang == "en"; const isNewInterface = document.querySelector("#main_top_table") ? false : true; const QuickLinksDefault = '[{"Name":"","Refernce":""},{"Name":"","Refernce":""},{"Name":"","Refernce":""},{"Name":"","Refernce":""},{"Name":"","Refernce":""},{"Name":"","Refernce":""},{"Name":"","Refernce":""},{"Name":"","Refernce":""},{"Name":"","Refernce":""},{"Name":"","Refernce":""}]'; main(); function main() { processHouses(); processQuickLinks(); //var map_change = document.querySelector("li * a[href='map.php']") //if ( map_change ) { setTimeout(function() { map_change.href = 'map.php?st=sh'; }, 500) } // uncomment this line to have map link replaced // pers - market const auctionRef = isNewInterface ? document.querySelector("div.sh_dd_container a[href='auction.php']") : getParent(document.querySelector("li > a[href='auction.php']"), "li"); if(auctionRef) { let resourcesShowTimer; let resourcesShown = false; auctionRef.addEventListener("mouseover", function() { if(!resourcesShown) resourcesShowTimer = setTimeout(function() { // insert after Market in Pers const auctionResourcesReferences = [ { href: "auction.php?cat=res&sort=0&type=1", text: ` ${isEn ? 'Wood' : 'Древесина'}` }, { href: "auction.php?cat=res&sort=0&type=2", text: ` ${isEn ? 'Ore' : 'Руда'}` }, { href: "auction.php?cat=res&sort=0&type=3", text: ` ${isEn ? 'Mercury' : 'Ртуть'}` }, { href: "auction.php?cat=res&sort=0&type=4", text: ` ${isEn ? 'Sulfur' : 'Сера'}` }, { href: "auction.php?cat=res&sort=0&type=5", text: ` ${isEn ? 'Crystals' : 'Кристаллы'}` }, { href: "auction.php?cat=res&sort=0&type=6", text: ` ${isEn ? 'Gems' : 'Самоцветы'}` }, { href: "arts_arenda.php", text: isEn ? 'Artifacts at lease' : 'Артефакты в аренде' } ]; const html = auctionResourcesReferences.reduce((t, x) => t + getMenuItemTemplate(x.href, x.text), ""); auctionRef.insertAdjacentHTML('afterend', html); resourcesShown = true; }, 500) } ); auctionRef.addEventListener("mouseout", function() { clearTimeout(resourcesShowTimer); }); } const transferRef = isNewInterface ? document.querySelector("div.sh_dd_container a[href='transfer.php']") : getParent(document.querySelector("li > a[href='transfer.php']"), "li"); if(transferRef) { const personalReferences = [ { href: `el_transfer.php`, text: isEn ? 'Transfer elements' : 'Передача элементов' }, { href: 'javascript:void(0);', text: "" }, { href: `pl_info.php?id=${PlayerId}`, text: isEn ? 'Character' : 'Персонаж' }, { href: `pl_transfers.php?id=${PlayerId}`, text: isEn ? 'Transfer log' : 'Протокол передач' }, { href: `pl_warlog.php?id=${PlayerId}`, text: isEn ? 'Combat log' : 'Протокол боев' }, { href: `pl_cardlog.php?id=${PlayerId}`, text: isEn ? 'Game log' : 'Протокол игр' }, { href: `friends.php`, text: isEn ? 'Your friends' : 'Ваши друзья' }, { href: `ephoto_albums.php`, text: isEn ? 'Your photos' : 'Ваш фотоальбом' }, { href: 'javascript:void(0);', text: "" }, { href: `logout.php?${Math.round( Math.random()* 100000 )}`, text: isEn ? 'Logout' : 'Выход' } ]; const html = personalReferences.reduce((t, x) => t + getMenuItemTemplate(x.href, x.text), ""); transferRef.insertAdjacentHTML('afterend', html); } const mapMenuContainer = isNewInterface ? document.querySelector("div.sh_dd_container a[href='map.php?st=hs']") : getParent(document.querySelector("li > a[href='map.php?st=hs']"), "li"); if(mapMenuContainer) { const housesInfo = JSON.parse(GM_getValue(`PlayerHouses${PlayerId}`, "{}")); let mapExtenders = Object.keys(housesInfo).map(x => ({ href: `house_info.php?id=${x}`, text: housesInfo[x].replace(" ", " ") })); // Арендованные дома. Берутся из скрипта Transporter for(let locationNumber = 1; locationNumber <= 27; locationNumber++) { const guestInfo = JSON.parse(GM_getValue(`GuestInfo${locationNumber}`, "{}")); for(const key in guestInfo) { mapExtenders = [...mapExtenders, { href: `house_info.php?id=${key}`, text: guestInfo[key].HostInfo, title: `до ${(new Date(guestInfo[key].ExpireDate)).toLocaleString()}` }]; } } // mapExtenders = [...mapExtenders, { href: 'javascript:void(0);', text: "" }, { href: 'ecostat.php', text: isEn ? 'Economic statistics' : 'Эконом. статистика' }]; const html = mapExtenders.reduce((t, x) => t + getMenuItemTemplate(x.href, x.text, x.title), ""); //console.log(mapExtenders) mapMenuContainer.insertAdjacentHTML('afterend', html); } const forumsContainer = isNewInterface ? document.querySelector("div.sh_dd_container a[href='forum.php#t1']") : getParent(document.querySelector("li > a[href='forum.php#t1']"), "li"); if(forumsContainer) { const forumExtenders = [ { href: `forum_thread.php?id=${isEn ? '103' : '3'}`, text: isEn ? 'Ideas and suggestions' : 'Идеи и предложения' }, { href: `forum_thread.php?id=${isEn ? '121' : '22'}`, text: isEn ? 'Smiths and Ench. services' : 'Услуги кузнецов и оруж.' }, { href: 'javascript:void(0);', text: "" }, { href: `${isEn ? 'http://daily.heroeswm.ru/newscom.php' : 'http://daily.heroeswm.ru/'}`, text: isEn ? 'HWM Daily ENG' : 'Геройская лента' } ]; const html = forumExtenders.reduce((t, x) => t + getMenuItemTemplate(x.href, x.text), ""); forumsContainer.insertAdjacentHTML('afterend', html); } const framesContainer = isNewInterface ? document.querySelector("div.sh_dd_container a[href='frames.php?room=4']") : getParent(document.querySelector("li > a[href='frames.php?room=4']"), "li"); if(framesContainer) { //GM_deleteValue(`QuickLinks${PlayerId}`); let quickLinks = JSON.parse(GM_getValue(`QuickLinks${PlayerId}`, "[]")).filter(x => x.Name != "" && x.Refernce != ""); if(quickLinks.length > 0) { quickLinks = [{ Refernce: "javascript:void(0);", Name: "" }, ...quickLinks]; const html = quickLinks.reduce((t, x) => t + getMenuItemTemplate(x.Refernce, x.Name), ""); framesContainer.insertAdjacentHTML('afterend', html); } } } function getMenuItemTemplate(href, text, title) { return !isNewInterface ? `<li>${text != "" ? `<a href='${href}'${!title ? "" : ` title='${title}'`}>${text}</a>` : "<hr>"}</li>` : `<a href='${href}'${!title ? "" : ` title='${title}'`} style='text-decoration:none;'><div${text == "" ? " style='padding: 0; height: 2px;'" : ""}>${text}</div></a>`; } function processHouses() { if(location.pathname == "/pl_info_realty.php" && getUrlParamValue(location.href, "id") == PlayerId) { const housesInfo = Array.from(document.querySelectorAll("a[href^='house_info.php']")).reduce((t, x) => ({...t, [getUrlParamValue(x.href, "id")]: getParent(x, "tr").cells[4].innerText }), {}); console.log(housesInfo); GM_setValue(`PlayerHouses${PlayerId}`, JSON.stringify(housesInfo)); } } function processQuickLinks() { if(location.pathname == "/pers_navlinks.php") { const tbody = getParent(document.querySelector("form[action='pers_navlinks.php']"), "tbody"); const tr = addElement("tr", tbody); const td = addElement("td", tr); const table = addElement("table", td); let quickLinks = JSON.parse(GM_getValue(`QuickLinks${PlayerId}`, QuickLinksDefault)); if(quickLinks.length != 10) { GM_deleteValue(`QuickLinks${PlayerId}`); quickLinks = JSON.parse(QuickLinksDefault); } //console.log(quickLinks) let i = 0; for(const quickLink of quickLinks) { const html = ` <tr> <td> <input id="linkName${i}" name="linkName" type="text" style="width: 200px;" /> <input id="linkValue${i}" name="linkValue" type="text" style="width: 300px;" /> </td> </tr>`; table.insertAdjacentHTML('beforeend', html); table.querySelector(`#linkName${i}`).value = quickLink.Name; table.querySelector(`#linkValue${i}`).value = quickLink.Refernce; table.querySelector(`#linkName${i}`).addEventListener("change", saveQuickLinks); table.querySelector(`#linkValue${i}`).addEventListener("change", saveQuickLinks); i++; } } } function saveQuickLinks() { const quickLinks = Array.from(document.querySelectorAll("input[name=linkName]")).map(x => ({ Name: x.value, Refernce: document.getElementById(x.id.replace("linkName", "linkValue")).value })); console.log(quickLinks) GM_setValue(`QuickLinks${PlayerId}`, JSON.stringify(quickLinks)); } function addElement(type, parent, data, insertFirst = false) { let el = createElement(type, data); if(parent) { if(insertFirst) { parent.insertBefore(el, parent.firstChild); } else { parent.appendChild(el); } } return el; } function createElement(type, data) { let el = document.createElement(type); if(data) { for(let key in data) { if(key == "innerText" || key == "innerHTML") { el[key] = data[key]; } else { el.setAttribute(key, data[key]); } } } return el; } function getParent(element, parentType, number = 1) { if(!element) { return; } let result = element; let foundNumber = 0; while(result = result.parentNode) { if(result.nodeName.toLowerCase() == parentType.toLowerCase()) { foundNumber++; if(foundNumber == number) { return result; } } } } function getUrlParamValue(url, paramName) { return (new URLSearchParams(url.split("?")[1])).get(paramName); } function createElementFromHtml(html) { const template = document.createElement('template'); template.innerHTML = html; const result = template.content.children; if (result.length === 1) { return result[0]; } return result; }