您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Цветные протоколы боёв, передач, клана и склада. Загрузка следующих страниц. Фильтрация.
当前为
// ==UserScript== // @name hwmAdvancedProtocol // @namespace Tamozhnya1 // @version 1.4 // @description Цветные протоколы боёв, передач, клана и склада. Загрузка следующих страниц. Фильтрация. // @author Tags, Tamozhnya1 2024 // @include /^https{0,1}:\/\/((www|my)\.(heroeswm|lordswm)\.(ru|com))\/(sklad_log|pl_transfers|pl_warlog|clan_log)\.(php.*)/ // @grant GM.xmlHttpRequest // @license MIT // ==/UserScript== // Tags https://greasyfork.org/ru/users/924307-foxxelias, Tamozhnya1 2024 const isEn = document.documentElement.lang == "en"; GM_addStyle(` .battle_row { width: 100%; border-right: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; } .battle_row img { width: 14px; height: 14px; vertical-align: bottom; } `); const types = [{ pattern: "бриллиантов обменяно ", icon: ``, color: "#00F120" }, { pattern: "вернул c ремонта ", icon: ``, color: "#FFF000" }, { pattern: "возвращено автоматически c ремонта", icon: ``, color: "#0008DC" }, { pattern: "Золото о", icon: ``, color: "#FFF8DC" }, { pattern: "взял в ремонт", icon: ``, color: "#FFF8DC" }, { pattern: "Куплен", icon: ``, color: "#DEB887" }, { pattern: "Вернул ", icon: ``, color: "#FFDEAD" }, { pattern: "арендова", icon: ``, color: "#FFEBCD" }, { pattern: "Передан", icon: ``, color: "#E0FFFF" }, { pattern: ", доп. комиссия ", icon: ``, color: "#B0C4DE" }, { pattern: "Продан ", icon: ``, color: "#ADFF2F" }, { pattern: "вернул", icon: ``, color: "#00FA9A" }, { pattern: "возвращ", icon: ``, color: "#7FFF00" }, { pattern: "Возвращено автоматически ", icon: ``, color: "#3CB371" }, { pattern: "Взят в ремонт ", icon: ``, color: "#7CFC00" }, { pattern: "Вернул c ремонта ", icon: ``, color: "#FA8072" }, { pattern: "Получен элемент ", icon: ``, color: "#00FF00" }, { pattern: "Получен ", icon: ``, color: "#F08080" }, { pattern: "<!--0-->", icon: `<img src="https://dcdn.heroeswm.ru/i/rewards/hunt_1.png" alt="hunt">`, color: "#cceecc" }, { pattern: "<!--7-->", icon: `<a href="mercenary_guild.php" style="height: inherit;"><img src="https://dcdn.heroeswm.ru/i/rewards/gn/task4.png" style="height: inherit;" ></a>`, color: "#eeeecc" }, { pattern: "<!--8-->", icon: `<a href="mercenary_guild.php" style="height: inherit;"><img src="https://dcdn3.heroeswm.ru/i/rewards/gn/task5.png" alt="" style="height: inherit;" ></a>`, color: "#eeeecc" }, { pattern: "<!--12-->", icon: `<a href="mercenary_guild.php" style="height: inherit;"><img src="https://dcdn2.heroeswm.ru/i/rewards/gn/task9.png" alt="" style="height: inherit;" ></a>`, color: "#eeeecc" }, { pattern: "<!--95-->", icon: `<a href="task_guild.php" style="height: inherit;" title="${isEn ? "Watcher's guild" : "Гильдия стражей"}"><img src="https://dcdn.heroeswm.ru/i/zvezda.png" ></a>`, color: "#17d3bf" }, { pattern: "<!--29-->", icon: `<a href="mercenary_guild.php" style="height: inherit;"><img src="https://dcdn3.heroeswm.ru/i/rewards/gn/task3.png" alt="" style="height: inherit;"></a>`, color: "#eeeecc" }, { pattern: "<!--10-->", icon: `<a href="mercenary_guild.php" style="height: inherit;"><img src="https://dcdn3.heroeswm.ru/i/rewards/gn/task7.png" alt="" style="height: inherit;" ></a>`, color: "#eeeecc" }, { pattern: "<!--5-->", icon: `<a href="mercenary_guild.php" style="height: inherit;"><img src="https://dcdn3.heroeswm.ru/i/rewards/gn/task2.png" alt="" style="height: inherit;" ></a>`, color: "#eeeecc" }, { pattern: "<!--28-->", icon: `<a href="mercenary_guild.php" style="height: inherit;"><img src="https://dcdn1.heroeswm.ru/i/rewards/gn/task10.png" alt="" style="height: inherit;" ></a>`, color: "#eeeecc" }, { pattern: "<!--66-->", icon: `<img title="Гильдия воров" src="//dcdn.heroeswm.ru/i/artifacts/thief_paper_s.jpg" >`, color: "#ccccee" }, { pattern: "<!--68-->", icon: `<img src="https://dcdn.heroeswm.ru/i/top/line/2x2fast.gif" title="Турнир" alt="Турнир">`, color: "" }, { pattern: "<!--127-->", icon: `<a href="leader_guild.php" style="height: inherit;"><img src="https://dcdn.heroeswm.ru/i/icons/attr_leadership.png" title="Гильдия Лидеров" alt="Гильдия Лидеров" style="height: inherit;"></a>`, color: "#cccccc" }, { pattern: "<!--89-->", icon: `<a href="leader_guild.php" style="height: inherit;"><img src="https://dcdn.heroeswm.ru/i/icons/attr_leadership.png" title="Гильдия Лидеров" alt="Гильдия Лидеров" style="height: inherit;"></a>`, color: "#cccccc" }, { pattern: "<!--94-->", icon: `<a href="tj_single.php"><img src="//dcdn.heroeswm.ru/i/tj2ev200.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#cccccc" }, { pattern: "<!--117-->", icon: `<a href="tj_single.php"><img src="//dcdn.heroeswm.ru/i/tj2ev200.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#cccccc" }, { pattern: "<!--110-->", icon: `<a href="campaign_list.php"><img src="//dcdn.heroeswm.ru/i/camp/dif3.png" alt="" width="15" height="15" border="0"></a>`, color: "#b5b5b5" }, { pattern: "<!--119-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#9b5755" }, { pattern: "<!--126-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#8FBC8F" }, { pattern: "<!--40-->", icon: `<a href="pvp_guild.php"><img src="https://dcdn.heroeswm.ru/i/pvp_gerb2.png" alt="" width="15" height="15" border="0"></a>`, color: "#20B2A0" }, { pattern: "<!--44-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#20B2AA" }, { pattern: "<!--111-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#808000" }, { pattern: "<!--115-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#9ACD32" }, { pattern: "<!--142-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#008000" }, { pattern: "<!--138-->", icon: `<a href="map_hero_event.php"><img src="https://dcdn3.heroeswm.ru/i/portraits/cmajakanip33.png" alt="" width="15" height="15" border="0"></a>`, color: "#2E8B55" }, { pattern: "<!--139-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#2E8B57" }, { pattern: "<!--26-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#FFFF00" }, { pattern: "<!--143-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#AFEEEE" }, { pattern: "<!--80-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#00FA9A" }, { pattern: "<!--140-->", icon: `<a href="hunting_event.php"><img src="//dcdn.lordswm.com/i/hunting_event2022_08.png" title="${isEn ? "Hunting Season" : "Сезон охоты"}" width="15" height="15" border="0"></a>`, color: "#7FFFD4" }, { pattern: "<!--133-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#40E0D0" }, { pattern: "<!--131-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#00CED1" }, { pattern: "<!--67-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#5F9EA0" }, { pattern: "<!--99-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#D2B48C" }, { pattern: "<!--81-->", icon: `<a href="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" width="15" height="15" border="0"></a>`, color: "#A52A2A" }, ]; const logContainerSelector = doc => doc.querySelectorAll('div.global_a_hover')[1]; const logContainer = logContainerSelector(document); main(); function main() { if(!logContainer) { return; } logContainer.style.fontSize = "9pt"; logContainer.style.borderTop = "1px solid black"; const header = document.querySelector("div.hwm_pagination").parentNode; const protocolSearchInput = addElement("input", { id: "protocolSearchInput", type: "text", style: "width: 150px; vertical-align: top;", title: isEn ? "Protocol filter" : "Фильтр по протоколу" }, header); protocolSearchInput.addEventListener("input", search); const currentPageIndex = getUrlParamValue(location.href, "page") || 0; if(currentPageIndex != "last") { // Кнопки загрузки const pageCount = 5; logContainer.insertAdjacentHTML("afterend", ` <center> <div id=loadNextPageButton name=loader class="home_button2 btn_hover2" style="display: inline-block;">${isEn ? "Load next page" : "Загрузить следующую страницу"}</div> <div id=loadNextPagesButton name=loader class="home_button2 btn_hover2" style="display: inline-block;">${isEn ? `Load next ${pageCount} page` : `Загрузить ${pageCount} страниц`}</div> </center>`); document.getElementById("loadNextPagesButton").addEventListener("click", function() { loadNextPage(pageCount); }); document.getElementById("loadNextPageButton").addEventListener("click", function() { loadNextPage(1); }); } processWarLog(); } async function loadNextPage(pageCount) { const currentPageIndex = parseInt(getUrlParamValue(location.href, "page") || 0); for(let newPageIndex = currentPageIndex + 1; newPageIndex <= currentPageIndex + pageCount; newPageIndex++) { const nextPageUrl = new URL(location.href); nextPageUrl.searchParams.set('page', newPageIndex); console.log(nextPageUrl.toString()); const nextPage = await getRequest(nextPageUrl); processWarLog(nextPage); window.history.replaceState(null, nextPage.title, nextPageUrl); } } function processWarLog(doc = document) { const nextPageLogContainer = logContainerSelector(doc); const rawBattles = nextPageLogContainer.innerHTML.split('<br>'); rawBattles.pop(); if(doc == document) { logContainer.innerHTML = ""; } for(const rawBattle of rawBattles) { const type = types.find(x => rawBattle.includes(x.pattern)); const rowHtml = (type?.icon || "") + rawBattle.replace("vs", " vs ").replace(" ", " "); const battleContainer = addElement('div', { innerHTML: rowHtml, class: "battle_row", style: `background-color: ${type?.color || "inherit"}` }, logContainer); } search(); } function search() { const value = document.getElementById("protocolSearchInput").value; const regex = new RegExp(value, "gi"); Array.from(logContainer.querySelectorAll("div")).forEach(x => { x.innerHTML = x.innerHTML.replace(/<\/?mark[^>]*>/g, ""); const searched = regex.test(x.innerHTML); x.style.display = searched ? "" : "none"; if(searched && value.length > 0) { x.innerHTML = x.innerHTML.replace(regex, `<mark>$&</mark>`); } }); } // API function GM_addStyle(css) { addElement("style", { type: "text/css", innerHTML: css }, document.head); } function addElement(type, data = {}, parent = undefined, insertPosition = "beforeend") { const el = document.createElement(type); for(const key in data) { if(key == "innerText" || key == "innerHTML") { el[key] = data[key]; } else { el.setAttribute(key, data[key]); } } if(parent) { parent.insertAdjacentElement(insertPosition, el); } return el; } function getRequest(url, overrideMimeType = "text/html; charset=windows-1251") { return new Promise((resolve, reject) => { GM.xmlHttpRequest({ method: "GET", url: url, overrideMimeType: overrideMimeType, onload: function(response) { resolve((new DOMParser).parseFromString(response.responseText, "text/html")); }, onerror: function(error) { reject(error); } }); }); } function getUrlParamValue(url, paramName) { return (new URLSearchParams(url.split("?")[1])).get(paramName); }