From fc24996193646a810ef8821479db616f97421d21 Mon Sep 17 00:00:00 2001 From: Kwack Date: Mon, 20 May 2024 20:32:08 +0800 Subject: [PATCH 1/3] Fix warnings --- lib/providers/quick_items_provider.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/providers/quick_items_provider.dart b/lib/providers/quick_items_provider.dart index 01cf1283..829bfb18 100644 --- a/lib/providers/quick_items_provider.dart +++ b/lib/providers/quick_items_provider.dart @@ -82,6 +82,7 @@ class QuickItemsProvider extends ChangeNotifier { void decreaseInventory(QuickItem item) { return; // Temporary removed items in Torn + // ignore: dead_code if (item.inventory! > 0) { item.inventory = item.inventory! - 1; _saveListAfterChanges(); From 23d7da20d5eefaeb7463db9c89fc1fa34b2ba9fd Mon Sep 17 00:00:00 2001 From: Kwack Date: Tue, 21 May 2024 00:44:44 +0800 Subject: [PATCH 2/3] Highlight own OC and NNB fixes (Own OC highlight #234) --- lib/utils/js_snippets.dart | 300 ++++++------------------- lib/widgets/webviews/webview_full.dart | 2 +- 2 files changed, 70 insertions(+), 232 deletions(-) diff --git a/lib/utils/js_snippets.dart b/lib/utils/js_snippets.dart index 63320062..2c49a1c9 100644 --- a/lib/utils/js_snippets.dart +++ b/lib/utils/js_snippets.dart @@ -1161,239 +1161,77 @@ String bountiesJS({ '''; } -String ocNNB({required String members}) { +String ocNNB({required String members, required int playerID}) { return ''' - // Credits: some functions and logic thanks to Torn Tools - - (function() { - - var data = $members; - - function loadNNB () { - - var iw = window.innerWidth; - - // Avoid adding NNB twice - var savedFound = document.querySelector(".pdaNNBListener") !== null; - if (!savedFound) { - var save = document.querySelector(".faction-crimes-wrap"); - save.classList.add("pdaNNBListener"); - console.log("Torn PDA: adding NNB!"); - } else { - console.log("PDA NNB found, returning"); - return; - } - - // Add style nnb title - function addStyle(styleString) { - const style = document.createElement('style'); - style.textContent = styleString; - document.head.append(style); - } - - addStyle( - `.pda-nnb-title { - text-align: right; - width: 30px; - }` - ); - - addStyle( - `.pda-nnb-value { - width: 30px; - }` - ); - - addStyle( - `.member.pda-modified-top-narrow { - width: 140px !important; - }` - ); - - addStyle( - `.member.pda-modified-top-wide { - width: 200px !important; - }` - ); - - addStyle( - `.member.pda-modified-bottom-narrow { - width: 80px !important; - }` - ); - - addStyle( - `.member.pda-modified-bottom-wide { - width: 140px !important; - }` - ); - - addStyle( - `.level.pda-modified-top-narrow { - width: 15px !important; - }` - ); - - addStyle( - `.level.pda-modified-top-wide { - width: 25px !important; - }` - ); - - addStyle( - `.level.pda-modified-bottom-narrow { - width: 15px !important; - }` - ); - - addStyle( - `.level.pda-modified-bottom-wide { - width: 25px !important; - }` - ); - - addStyle( - `.offences.pda-modified { - width: 50px !important; - }` - ); - - addStyle( - `.act.pda-modified { - width: 29px !important; - }` - ); - - addStyle( - `.stat.pda-modified { - width: 50px !important; - }` - ); - - - function createNerveTitle () { - var newDiv = document.createElement("li"); - var newContent = document.createTextNode("NNB"); - newDiv.className = "pda-nnb-title"; - newDiv.appendChild(newContent); - return newDiv; - } - - function createNerveValue (value) { - var newDiv = document.createElement("li"); - var newContent = document.createTextNode(value); - newDiv.className = "pda-nnb-value"; - newDiv.appendChild(newContent); - return newDiv; + ((members, playerID) => { + const waitForOCs = (maxCount = 100) => + new Promise((resolve, reject) => { + const intID = setInterval(() => { + const ocRows = \$("ul.crimes-list > li"); + if (ocRows.length) { + clearInterval(intID); + resolve(ocRows); + } else { + if (maxCount-- <= 0) { + clearInterval(intID); + reject(new Error("Could not find member rows")); + } + } + }, 100); + }); + + const handleOCRows = (ocRows) => { + ocRows.each((_, row) => { + const table = \$(row).find(".details-wrap:not(.pda-modified)"); + if (!table.length) return // No new table to update + const shouldHighlightRow = handleOCTable(table); + if (shouldHighlightRow) \$(row).find("> ul.item").addClass("pda-highlight-row"); + }); + }; + + const handleOCTable = (table) => { + let shouldHighlightRow = false; + table.addClass("pda-modified"); + table.find("> ul > li > ul:not(.pda-table-row)").each((i, row) => { + \$(row).addClass("pda-table-row"); + if (i === 0) + return \$("
  • ", { text: "NNB" }).insertBefore( + \$(row).find("li.stat") + ); + const id = \$(row) + .find("a[href*='profiles.php?XID=']") + .attr("href") + ?.match(/XID=(\\d+)/)?.[1]; + if (!id) return console.error("Missing ID for row", row); + if (id === playerID.toString()) shouldHighlightRow = true; + \$("
  • ", { text: members[id] || "unk" }).insertBefore( + \$(row).find("li.stat") + ); + }); + return shouldHighlightRow; + }; + + const addStyles = () => { + const styles = ` + .pda-table-row { + display: grid; + grid-template-columns: 1fr 3rem 3rem 5rem; + } + .pda-table-row > * { + width: unset !important; + } + .pda-table-row > *:not(.member) { + text-align: center !important; } - - var member = document.querySelectorAll('.member'); - for (var m of member) { - // Crimes scheduled - var row = m.closest(".organize-wrap .crimes-list .details-list > li > ul"); - if (row !== null) - { - row.querySelectorAll(`.offences`).forEach((element) => element.classList.add("pda-modified")); - - row.querySelectorAll(`.level`).forEach((element) => element.classList.add("pda-modified")); - if (iw < 785) { - row.querySelectorAll(`.level`).forEach((element) => element.classList.add("pda-modified-top-narrow")); - } else { - row.querySelectorAll(`.level`).forEach((element) => element.classList.add("pda-modified-top-wide")); - } - - if (iw < 387) { - row.querySelectorAll(`.member`).forEach((element) => element.classList.add("pda-modified-top-narrow")); - } else { - row.querySelectorAll(`.member`).forEach((element) => element.classList.add("pda-modified-top-wide")); - } - - row.querySelectorAll(`.stat`).forEach((element) => element.classList.add("pda-modified")); - - let stat = row.querySelector(".stat"); - if (stat === null) continue; - - if (row.classList.contains("title")) { - stat.parentElement.insertBefore( - createNerveTitle(), - stat - ); - continue; - } - - const id = row.querySelector(".h").getAttribute("href").split("XID=")[1]; - - var found = false; - for (const [key, value] of Object.entries(data)) { - if (id === key) { - stat.insertAdjacentElement("beforebegin", createNerveValue(value)); - found = true; - continue; - } - } - if (!found) { - stat.insertAdjacentElement("beforebegin", createNerveValue("unk")); - } - continue; - } - - - // Crimes available - var row = m.closest(".plans-list .item"); - if (row !== null) { - row.querySelectorAll(`.offences`).forEach((element) => element.classList.add("pda-modified")); - - row.querySelectorAll(`.level`).forEach((element) => element.classList.add("pda-modified")); - if (iw < 785) { - row.querySelectorAll(`.level`).forEach((element) => element.classList.add("pda-modified-bottom-narrow")); - } else { - row.querySelectorAll(`.level`).forEach((element) => element.classList.add("pda-modified-bottom-wide")); - } - - if (iw < 387) { - row.querySelectorAll(`.member`).forEach((element) => element.classList.add("pda-modified-bottom-narrow")); - } else { - row.querySelectorAll(`.member`).forEach((element) => element.classList.add("pda-modified-bottom-wide")); - } - - row.querySelectorAll(`.act`).forEach((element) => element.classList.add("pda-modified")); - - let act = row.querySelector(".act"); - if (act === null) continue; - - if (row.classList.contains("title")) { - act.parentElement.insertBefore( - createNerveTitle(), - act - ); - continue; - } - - const id = row.querySelector(".h").getAttribute("href").split("XID=")[1]; - - var found = false; - for (const [key, value] of Object.entries(data)) { - if (id === key) { - act.insertAdjacentElement("beforebegin", createNerveValue(value)); - found = true; - continue; - } - } - if (!found) { - act.insertAdjacentElement("beforebegin", createNerveValue("unk")); - } - } - } - } - - let waitForOCAndRun = setInterval(() => { - if (document.querySelector(".faction-crimes-wrap")) { - loadNNB(); - return clearInterval(waitForOCAndRun); - } - }, 300); - - })(); + .pda-highlight-row { + background-color: #F0F7 !important; + } + `; + \$("