.+<\/b><\/a>)/; // pattern
let loading = false;
let stop = false;
const loadCaption = isEn ? "Load" : "Загрузить";
const stopLoadCaption = isEn ? "Stop" : "Остановить";
const forumThreadId = getUrlParamValue(location.href, "id");
const threadId = getUrlParamValue(location.href, "tid");
const smithsThread = isEn ? 121 : 22;
const miscellaneousThread = isEn ? 122 : 23;
main();
function main() {
if(processProtocols()) {
return;
}
if(location.pathname == "/sms.php") {
Array.from(document.querySelectorAll("table.wbwhite > tbody > tr > td")).filter(x => x.innerHTML.indexOf("| b")).find(x => x.innerText == (isEn ? "Personal info" : "Личная информация"));
const personalInfoTable = personalInfoTitleContainer.closest("table");
const personalInfoCell = personalInfoTable.rows[1].cells[0];
exudeReferences(personalInfoCell);
return;
}
const table3 = document.querySelector("table.table3");
if(location.pathname == "/forum_thread.php" && forumThreadId == smithsThread) {
// Фильтры для форума услуг кузнецов и оружейников
table3.insertAdjacentHTML("beforebegin", `
|
|
|
|
|
`);
document.getElementById("hideCraftersCheckbox").addEventListener("click", function() { setPlayerValue("hideCrafters", this.checked); filterMessages(); });
document.getElementById("hideSmithsCheckbox").addEventListener("click", function() { setPlayerValue("hideSmiths", this.checked); filterMessages(); });
document.getElementById("hideSmiths90Checkbox").addEventListener("click", function() { setPlayerValue("hideSmiths90", this.checked); filterMessages(); });
}
if(location.pathname == "/forum_thread.php" && forumThreadId == miscellaneousThread) {
// Фильтры для форума покупок, продаж, услуг
table3.insertAdjacentHTML("beforebegin", `
|
|
|
|
`);
document.getElementById("hideServicesCheckbox").addEventListener("click", function() { setPlayerValue("hideServices", this.checked); filterMessages(); });
document.getElementById("hideBuyCheckbox").addEventListener("click", function() { setPlayerValue("hideBuy", this.checked); filterMessages(); });
document.getElementById("hideSellCheckbox").addEventListener("click", function() { setPlayerValue("hideSell", this.checked); filterMessages(); });
}
if(location.pathname == "/forum_messages.php") {
table3.insertAdjacentHTML("beforebegin", `
|
|
`);
document.getElementById("hideBlackListMessagesCheckbox").addEventListener("click", function() { setPlayerValue("hideBlackListMessages", this.checked); filterMessages(); });
document.getElementById("markedOnlyCheckbox").addEventListener("click", function() { setPlayerValue("markedOnly", this.checked); filterMessages(); });
document.getElementById("compactForumViewCheckbox").addEventListener("click", function() { setPlayerValue("compactForumView", this.checked); filterMessages(); });
addBlackListCheckboxes();
Array.from(table3.querySelectorAll('tr:nth-child(odd) > td:first-child')).forEach(exudeReferences);
}
const currentPageIndex = getUrlParamValue(location.href, "page") || 0;
if(currentPageIndex != "last") {
// Кнопка загрузки следующей страницы
table3.insertAdjacentHTML("afterend", `${isEn ? "Load next page" : "Загрузить следующую страницу"}${currentPageIndex}`);
document.getElementById("loadNextPageButton").addEventListener("click", loadNextPage);
}
filterMessages();
}
function processProtocols() {
if(!["/sklad_log.php", "/pl_transfers.php", "/pl_warlog.php", "/clan_log.php", "/gift_box_log.php"].includes(location.pathname)) {
return;
}
const header = pagingContainerSelector(document);
const protocolSearchInput = addElement("input", { id: "protocolSearchInput", type: "text", style: "width: 150px; vertical-align: top;", title: isEn ? "Protocol filter" : "Фильтр по протоколу", onfocus: "this.select();" }, header);
protocolSearchInput.addEventListener("input", search);
const toggleLoadingButton = addElement("div", { id: "toggleLoadingButton", class: "home_button2 btn_hover2", style: "display: inline-block; vertical-align: top; padding: 0px 4px; width: fit-content;", innerText: loadCaption }, header);
toggleLoadingButton.addEventListener("click", toggleLoading);
const pageCountInput = addElement("input", { id: "pageCountInput", type: "number", value: getPlayerValue("ProtocolPageAmount", 5), style: "width: 70px; vertical-align: top;", title: isEn ? "Page amount to loading" : "Количество страниц для загрузки", onfocus: "this.select();" }, header);
pageCountInput.addEventListener("change", function() { setPlayerValue("ProtocolPageAmount", this.value); });
processLog();
return true;
}
async function toggleLoading() {
const toggleLoadingButton = document.getElementById("toggleLoadingButton");
if(loading) {
stop = true;
return;
}
loading = true;
//stop = false;
const currentPageIndex = parseInt(getUrlParamValue(location.href, "page") || 0);
const pageCount = Number(getPlayerValue("ProtocolPageAmount", 5)) || 5;
for(let newPageIndex = currentPageIndex + 1; newPageIndex <= currentPageIndex + pageCount; newPageIndex++) {
toggleLoadingButton.innerText = `${stopLoadCaption} ${newPageIndex + 1}`;
const nextPageUrl = new URL(location.href);
nextPageUrl.searchParams.set('page', newPageIndex);
//console.log(nextPageUrl.toString());
const nextPage = await getRequest(nextPageUrl);
processLog(nextPage);
window.history.replaceState(null, nextPage.title, nextPageUrl);
if(stop) {
break;
}
}
loading = false;
stop = false;
toggleLoadingButton.innerText = loadCaption;
}
function processLog(doc = document) {
remap(doc);
const logContainer = logContainerSelector(document);
if(!logContainer) {
return;
}
logContainer.style.fontSize = "9pt";
logContainer.style.borderTop = "1px solid black";
const nextPageLogContainer = logContainerSelector(doc);
let rawBattles = nextPageLogContainer.innerHTML.split('
').filter(x => x && x != "\n" && (!x.startsWith("") || doc == document));
//console.log(rawBattles)
//rawBattles.pop(); //location.pathname == '/gift_box_log.php'
if(doc == document) {
logContainer.innerHTML = "";
}
for(let rawBattle of rawBattles) {
if(rawBattle.startsWith("")) {
logContainer.insertAdjacentHTML("beforeend", rawBattle);
continue;
}
const type = types.find(x => rawBattle.includes(x.pattern));
// rawBattle = rawBattle.replace(p_date, "$1
$2
");
// rawBattle = rawBattle.replace(p_user, "$1
");
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 remap(doc) {
if(location.pathname == '/gift_box_log.php') {
const logContainer = addElement("div", { class: "global_a_hover" });
const td = doc.querySelector('td.wbwhite');
let i = 0;
const children = Array.from(td.childNodes);
for(const child of children) {
if(i == 3) {
child.insertAdjacentElement("afterend", logContainer);
//console.log(logContainer)
}
//console.log(child)
if(i > 3) {
if(child.nodeName.toLowerCase() == "center") {
child.remove();
} else {
logContainer.appendChild(child);
}
}
i++;
}
}
}
function search() {
const value = document.getElementById("protocolSearchInput").value;
const regex = new RegExp(value, "gi");
const logContainer = logContainerSelector(document);
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, `$&`);
}
});
}
function addBlackListCheckboxes() {
if(location.pathname != "/forum_messages.php") {
return;
}
const table3 = document.querySelector("table.table3");
const authorRefs = table3.querySelectorAll("tr > td a[href^='pl_info.php?id=']");
const forumBlackList = JSON.parse(getValue("forumBlackList", "[]"));
for(authorRef of authorRefs) {
const cell = authorRef.closest("td");
if(!cell.querySelector("input[name=blackListCheckbox]")) {
const playerId = parseInt(getUrlParamValue(authorRef.href, "id"));
const blackListCheckbox = addElement("input", { type: "checkbox", name: "blackListCheckbox", playerId: playerId, title: isEn ? "Mark" : "Пометить" });
blackListCheckbox.checked = forumBlackList.includes(playerId);
blackListCheckbox.addEventListener("change", function() { addToBlackList(this.getAttribute("playerId"), this.checked); });
cell.insertAdjacentElement("afterbegin", blackListCheckbox);
}
}
}
function addToBlackList(playerId, adding) {
const forumBlackList = JSON.parse(getValue("forumBlackList", "[]"));
playerId = parseInt(playerId);
if(adding) {
if(!forumBlackList.includes(playerId)) {
forumBlackList.push(playerId);
Array.from(document.querySelectorAll(`table.table3 input[name=blackListCheckbox]`)).filter(x => x.getAttribute("playerId") == playerId).forEach(x => x.checked = true);
}
} else {
const indexOfId = forumBlackList.indexOf(playerId);
if(indexOfId > -1) {
forumBlackList.splice(indexOfId, 1);
Array.from(document.querySelectorAll(`table.table3 input[name=blackListCheckbox]`)).filter(x => x.getAttribute("playerId") == playerId).forEach(x => x.checked = false);
}
}
setValue("forumBlackList", JSON.stringify(forumBlackList));
filterMessages();
}
async function loadNextPage() {
document.getElementById("loadNextPageButton").disabled = true;
const currentPageIndexHolder = document.getElementById('currentPageIndexHolder');
const nextPageIndex = Number(currentPageIndexHolder.innerText) + 1;
currentPageIndexHolder.innerText = nextPageIndex;
const pageBottom = document.body.scrollHeight;
const nextPageUrl = `${location.pathname}?${threadId ? `tid=${threadId}` : ""}${forumThreadId ? `id=${forumThreadId}` : ""}&page=${nextPageIndex}`;
//console.log(nextPageUrl)
const nextPage = await getRequest(nextPageUrl);
const newTable3 = nextPage.querySelector("table.table3 > tbody");
if(location.pathname == "/forum_messages.php") {
Array.from(newTable3.querySelectorAll('tr:nth-child(odd) > td:first-child')).forEach(exudeReferences);
}
const newRows = Array.from(newTable3.rows).slice(1); //console.log(newRows);
//const newTable3exec = /(<\/td><\/tr>)/.exec(nextPage.querySelector("table.table3").innerHTML);
const table3 = document.querySelector("table.table3 > tbody");
//table3.insertAdjacentHTML("beforeend", `
| ${nextPageIndex + 1} |
| ${newTable3exec[1]}`);
table3.insertAdjacentHTML("beforeend", getBreakLine(nextPageIndex, nextPageUrl));
newRows.forEach(x => table3.insertAdjacentElement("beforeend", x));
addBlackListCheckboxes();
filterMessages();
Array.from(document.querySelectorAll(`center > a[href='${nextPageUrl.slice(1)}']`)).forEach(x => x.replaceWith(addElement("b", {innerHTML: `${nextPageIndex + 1}`}))); // Ссылку на загруженную страницу заменяем красным номером страницы
//window.scrollTo(0, pageBottom + 1);
window.history.replaceState(null, nextPage.title, nextPageUrl);
document.getElementById("loadNextPageButton").disabled = false;
}
function getBreakLine(nextPageIndex, nextPageUrl) {
if(location.pathname == "/forum_thread.php") {
return `
|
${nextPageIndex + 1}
|
|
`;
}
if(location.pathname == "/forum_messages.php") {
return `
|
|
`;
}
}
function filterMessages() {
const userFilters = { hideCrafters: getPlayerBool("hideCrafters", true), hideSmiths: getPlayerBool("hideSmiths"), hideSmiths90: getPlayerBool("hideSmiths90"), hideServices: getPlayerBool("hideServices", true), hideBuy: getPlayerBool("hideBuy"), hideSell: getPlayerBool("hideSell"), hideBlackListMessages: getPlayerBool("hideBlackListMessages"), markedOnly: getPlayerBool("markedOnly") };
const forumBlackList = JSON.parse(getValue("forumBlackList", "[]"));
let evenRow = false;
const allRows = Array.from(document.querySelectorAll("table.table3 > tbody > tr"));
if(location.pathname == "/forum_messages.php") {
allRows[0].cells[0].style.display = getPlayerBool("compactForumView") ? "none" : "";
}
let rows = allRows.slice(1);
if(location.pathname == "/forum_messages.php") {
rows = rows.filter(x => x.cells[0].getAttribute("rowspan") == "2");
}
//console.log(`rows.length: ${rows.length}`);
for(const row of rows) {
if(location.pathname == "/forum_messages.php") {
const innerRow = row.cells[1].querySelector("table tr");
const authorInfo = innerRow.querySelector("td[name=authorInfo]");
if(getPlayerBool("compactForumView") && !authorInfo) {
addElement("td", { name: "authorInfo", innerHTML: row.cells[0].innerHTML }, innerRow);
innerRow.querySelector("br").remove();
}
if(!getPlayerBool("compactForumView") && authorInfo) {
authorInfo.remove();
}
row.cells[0].style.display = getPlayerBool("compactForumView") ? "none" : "";
}
let isHideRow = evalHideRow(userFilters, row, forumBlackList);
row.style.display = isHideRow ? 'none' : '';
if(location.pathname == "/forum_messages.php") {
row.nextElementSibling.style.display = isHideRow ? 'none' : '';
}
if(!isHideRow) {
if(location.pathname == "/forum_thread.php") {
row.className = evenRow ? "second" : "";
}
evenRow = !evenRow;
}
}
}
function evalHideRow(userFilters, row, forumBlackList) {
if(location.pathname == "/forum_messages.php") {
if(userFilters.hideBlackListMessages) {
const authorRef = row.cells[0].querySelector("a[href^='pl_info.php?id=']");
if(authorRef) {
const playerId = parseInt(getUrlParamValue(authorRef.href, "id"));
return forumBlackList.includes(playerId);
}
}
if(userFilters.markedOnly) {
const authorRef = row.cells[0].querySelector("a[href^='pl_info.php?id=']");
if(authorRef) {
const playerId = parseInt(getUrlParamValue(authorRef.href, "id"));
return !forumBlackList.includes(playerId);
}
}
return false;
}
const messageRef = row.querySelector("td > a[href^='forum_messages.php?tid=']");
if(!messageRef) {
return false;
}
const message = messageRef.innerHTML.toLowerCase();
return location.pathname == "/forum_thread.php" && forumThreadId == smithsThread && (
userFilters.hideCrafters && isCraft(message) && !isRepair(message)
|| userFilters.hideSmiths && isRepairExcept90(message) && !isCraft(message)
|| userFilters.hideSmiths90 && isRepair90(message) && !isCraft(message)
)
|| location.pathname == "/forum_thread.php" && forumThreadId == miscellaneousThread && (
userFilters.hideServices && (message.indexOf("услуги") != -1 || message.indexOf("service") != -1)
|| userFilters.hideBuy && (message.indexOf("куплю") != -1 || message.indexOf("kуплю") != -1 || message.indexOf("buy") != -1)
|| userFilters.hideSell && (message.indexOf("прода") != -1 || message.indexOf("sell") != -1)
);
}
function isCraft(message) { return message.indexOf("крафт") != -1 || message.indexOf("kрафт") != -1 || message.indexOf("armour") != -1 || message.indexOf("weapon") != -1 || message.indexOf("jewe") != -1; }
function isRepair(message) { return message.indexOf("ремонт") != -1 || message.indexOf("repair") != -1; }
function is90(message) { return (message.indexOf("90%") != -1 || message.indexOf("90 %") != -1 || message.indexOf("90 за") != -1); }
function isRepair90(message) { return isRepair(message) && is90(message); }
function isRepairExcept90(message) { return isRepair(message) && !is90(message); }
function exudeReferences(element) { Array.from(element.childNodes).filter(x => x.nodeName == "#text").forEach(x => { addElement('span', { innerHTML: linkify(x.textContent) }, x, "beforebegin"); x.remove(); }) }
function linkify(text) {
//const Rexp = /(\b(https?|ftp|file):\/\/([-A-Z0-9+&@#%?=~_|!:,.;]*)([-A-Z0-9+&@#%?\/=~_|!:,.;]*)[-A-Z0-9+&@#\/%=~_|])/ig; // Put the URL to variable $1 and Domain name to $3 after visiting the URL
const linkRexp = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;
return text.replace(linkRexp, "$1");
}
|