hwmAdvancedLogTable

Цветные протоколы боёв, передач, склада. Загрузка следующей страницы.

目前為 2024-02-26 提交的版本,檢視 最新版本

// ==UserScript==
// @name hwmAdvancedLogTable
// @namespace Tamozhnya1
// @version 1.2
// @description Цветные протоколы боёв, передач, склада. Загрузка следующей страницы.
// @author Tags, Tamozhnya1 2024
// @include /^https{0,1}:\/\/((www|my)\.(heroeswm|lordswm)\.(ru|com))\/(sklad_log|pl_transfers|pl_warlog)\.(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 {
  display: flex;
  width: 100%;
}
.battle_row img {
  width: 18px;
  height: 18px;
}
`);
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: `<img src="https://dcdn.heroeswm.ru/i/zvezda.png" >`,
	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="village_def.php"><img src="//dcdn.heroeswm.ru/i/vil_def_n.jpg" alt="" 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"
},
];

main();
function main() {
    const currentPageIndex = getUrlParamValue(location.href, "page") || 0;
    if(currentPageIndex != "last") {
        // Кнопка загрузки следующей страницы
        const mainElement = document.querySelectorAll('div.global_a_hover')[1];
        mainElement.insertAdjacentHTML("afterend", `<center id=loadNextPageButton style="cursor: pointer;"><ins>${isEn ? "Load next page" : "Загрузить следующую страницу"}</ins><span style="display: none;" id=currentPageIndexHolder>${currentPageIndex}</span></center>`);
        document.getElementById("loadNextPageButton").addEventListener("click", loadNextPage);
        console.log(document.getElementById("loadNextPageButton"))
    }
    processWarLog();
}
function processWarLog(doc = document, mainElementToAppend = undefined) {
    const mainElement = doc.querySelectorAll('div.global_a_hover')[1];
    mainElementToAppend = mainElementToAppend || mainElement;
    const rawBattles = mainElement.innerHTML.split('<br>');
	rawBattles.pop();
	mainElement.innerHTML = "";
	mainElement.style.fontSize = "10pt";
    mainElement.style.borderTop = "1px solid black";
	for(const rawBattle of rawBattles) {
        const type = types.find(x => rawBattle.includes(x.pattern));
        const rowHtml = (type?.icon || "") + rawBattle.replace("vs", "&nbsp;vs&nbsp;").replace("&nbsp;&nbsp;", "&nbsp;");
		const battleContainer = addElement('div', mainElementToAppend, { innerHTML: rowHtml, class: "battle_row", style: `border-right: 1px solid black; border-bottom: 1px solid black; border-left: 1px solid black; background-color: ${type?.color || "inherit"}` });
	}
}
async function loadNextPage() {
    const currentPageIndex = parseInt(getUrlParamValue(location.href, "page") || 0);
    const newPageIndex = currentPageIndex + 1;
    
    const nextPageUrl = new URL(location.href);
    nextPageUrl.searchParams.set('page', newPageIndex);
    console.log(nextPageUrl.toString());
    const nextPage = await getRequest(nextPageUrl);
    const mainElement = document.querySelectorAll('div.global_a_hover')[1];
    processWarLog(nextPage, mainElement);

    window.history.replaceState(null, nextPage.title, nextPageUrl);
}
// API
function GM_addStyle(css) { addElement("style", document.head, { type: "text/css", innerHTML: css }); }
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 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); }function getValue(key, defaultValue) { return GM_getValue(key, defaultValue); };