Dateien nach "/" hochladen

Anpassungen an die neue Spielseite
This commit is contained in:
2026-08-20 19:14:20 +02:00
parent 1494027ce5
commit f736866e70
+70 -66
View File
@@ -1,8 +1,8 @@
// ==UserScript== // ==UserScript==
// @name Jasbee Gebäude-Prozentanzeige // @name Jasbee Gebäude-Prozentanzeige
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 3.2 // @version 3.7
// @description Erlaubt das Scannen aller Gebäude im Hintergrund per Klick auf city.php (Mit optischen CSS-Fixes) // @description Scannt alle Gebäude im Hintergrund über direkte Pfade (Unterstützt neues Layout, robuste Pfeilerkennung per URL & Namenskorrektur)
// @author Daniel + Gemini // @author Daniel + Gemini
// @match https://www.jasbee.de/module/* // @match https://www.jasbee.de/module/*
// @grant none // @grant none
@@ -11,7 +11,6 @@
(function() { (function() {
'use strict'; 'use strict';
// Liste der erlaubten Dateinamen
const allowedPages = [ const allowedPages = [
'city.php', 'lager.php', 'baumarkt.php', 'sportsbar.php', 'city.php', 'lager.php', 'baumarkt.php', 'sportsbar.php',
'aliengeb.php', 'sauna.php', 'haus.php', 'fussball.php', 'aliengeb.php', 'sauna.php', 'haus.php', 'fussball.php',
@@ -21,11 +20,10 @@
const currentPath = window.location.pathname; const currentPath = window.location.pathname;
const currentPage = currentPath.substring(currentPath.lastIndexOf('/') + 1).toLowerCase(); const currentPage = currentPath.substring(currentPath.lastIndexOf('/') + 1).toLowerCase();
if (!allowedPages.includes(currentPage)) { if (!allowedPages.some(page => currentPage.includes(page))) {
return; return;
} }
// 1. Popup-Element erstellen und stylen
const popup = document.createElement('div'); const popup = document.createElement('div');
popup.id = 'gebaeude-prozent-popup'; popup.id = 'gebaeude-prozent-popup';
popup.style.position = 'fixed'; popup.style.position = 'fixed';
@@ -58,13 +56,11 @@
document.body.appendChild(popup); document.body.appendChild(popup);
// Scan-Button nur auf city.php einblenden
const scanBtn = document.getElementById('scan-jasbee-buildings'); const scanBtn = document.getElementById('scan-jasbee-buildings');
if (currentPage === 'city.php') { if (currentPage.includes('city.php')) {
scanBtn.style.display = 'inline-block'; scanBtn.style.display = 'inline-block';
} }
// Drag-and-Drop Steuerung
const header = document.getElementById('popup-header'); const header = document.getElementById('popup-header');
let isDragging = false; let isDragging = false;
let currentX, currentY, initialX, initialY; let currentX, currentY, initialX, initialY;
@@ -122,24 +118,39 @@
localStorage.setItem('jasbee_building_data', JSON.stringify(data)); localStorage.setItem('jasbee_building_data', JSON.stringify(data));
} }
// Hintergrund-Scanner Funktion function extractBuildingState(doc) {
const ringElement = doc.querySelector('.city-building-dashboard__ring');
if (ringElement) {
const strongEl = ringElement.querySelector('strong');
if (strongEl && strongEl.textContent.includes('%')) {
return strongEl.textContent.trim();
}
const textContent = ringElement.textContent.trim();
if (textContent.includes('%')) {
return textContent;
}
}
const percentElements = doc.querySelectorAll('.pie-number');
for (let el of percentElements) {
const txt = el.textContent.trim();
if (txt.includes('%')) {
const parentCard = el.closest('.card');
if (parentCard) {
const cardHeader = parentCard.querySelector('h3');
if (cardHeader && cardHeader.textContent.trim() === 'Gebäudezustand') {
return txt;
}
}
}
}
return '';
}
function startBackgroundScan() { function startBackgroundScan() {
const links = Array.from(document.querySelectorAll('a[href]')); const targets = allowedPages
const targets = []; .filter(page => page !== 'city.php')
.map(page => `https://www.jasbee.de/module/${page}`);
links.forEach(link => {
const href = link.getAttribute('href');
allowedPages.forEach(page => {
if (page !== 'city.php' && href.includes(page) && !targets.includes(href)) {
targets.push(href);
}
});
});
if (targets.length === 0) {
alert('Keine Gebäude-Links auf der Seite gefunden!');
return;
}
scanBtn.disabled = true; scanBtn.disabled = true;
scanBtn.style.background = '#555'; scanBtn.style.background = '#555';
@@ -169,31 +180,25 @@
const doc = iframe.contentDocument || iframe.contentWindow.document; const doc = iframe.contentDocument || iframe.contentWindow.document;
let buildingName = ''; let buildingName = '';
if (iframe.src.includes('aliengeb.php')) {
buildingName = 'Aliengebäude';
} else {
const breadcrumbItems = doc.querySelectorAll('.breadcrumb li'); const breadcrumbItems = doc.querySelectorAll('.breadcrumb li');
if (breadcrumbItems.length > 0) { if (breadcrumbItems.length > 0) {
buildingName = breadcrumbItems[breadcrumbItems.length - 1].textContent.trim().replace(/[\t\r\n]/g, ''); buildingName = breadcrumbItems[breadcrumbItems.length - 1].textContent.trim().replace(/[\t\r\n]/g, '');
} }
const percentElements = doc.querySelectorAll('.pie-number'); if (!buildingName) {
let stateValue = ''; const currentTarget = targets[index - 1];
const pageName = currentTarget.substring(currentTarget.lastIndexOf('/') + 1).replace('.php', '');
buildingName = pageName.charAt(0).toUpperCase() + pageName.slice(1);
}
}
for (let el of percentElements) { const stateValue = extractBuildingState(doc);
const txt = el.textContent.trim();
if (txt.includes('%')) {
const parentCard = el.closest('.card');
if (parentCard) {
const cardHeader = parentCard.querySelector('h3');
if (cardHeader && cardHeader.textContent.trim() === 'Gebäudezustand') {
stateValue = txt;
break;
}
}
}
}
if (buildingName && stateValue) { if (buildingName && stateValue) {
let currentStorage = getStoredData(); let currentStorage = getStoredData();
// Wir speichern Zustand und die genaue URL als Objekt ab
currentStorage[buildingName] = { currentStorage[buildingName] = {
value: stateValue, value: stateValue,
url: iframe.src url: iframe.src
@@ -211,38 +216,25 @@
loadNext(); loadNext();
} }
// Hauptfunktion zur Anzeige
function updateBuildingStatus() { function updateBuildingStatus() {
const contentDiv = document.getElementById('popup-content'); const contentDiv = document.getElementById('popup-content');
let currentStorage = getStoredData(); let currentStorage = getStoredData();
let hasNewData = false; let hasNewData = false;
let buildingName = ''; let buildingName = '';
if (window.location.href.includes('aliengeb.php')) {
buildingName = 'Aliengebäude';
} else {
const breadcrumbItems = document.querySelectorAll('.breadcrumb li'); const breadcrumbItems = document.querySelectorAll('.breadcrumb li');
if (breadcrumbItems.length > 0) { if (breadcrumbItems.length > 0) {
buildingName = breadcrumbItems[breadcrumbItems.length - 1].textContent.trim().replace(/[\t\r\n]/g, ''); buildingName = breadcrumbItems[breadcrumbItems.length - 1].textContent.trim().replace(/[\t\r\n]/g, '');
} }
}
const percentElements = document.querySelectorAll('.pie-number'); if (buildingName && !buildingName.toLowerCase().includes('city')) {
const stateValue = extractBuildingState(document);
if (buildingName && buildingName.toLowerCase() !== 'city' && percentElements.length > 0) {
let stateValue = '';
for (let el of percentElements) {
const txt = el.textContent.trim();
if (txt.includes('%')) {
const parentCard = el.closest('.card');
if (parentCard) {
const cardHeader = parentCard.querySelector('h3');
if (cardHeader && cardHeader.textContent.trim() === 'Gebäudezustand') {
stateValue = txt;
break;
}
}
}
}
if (stateValue) { if (stateValue) {
// Abwärtskompatibilität prüfen (falls alte Datenstruktur ohne .value existiert)
const oldVal = (typeof currentStorage[buildingName] === 'object') ? currentStorage[buildingName].value : currentStorage[buildingName]; const oldVal = (typeof currentStorage[buildingName] === 'object') ? currentStorage[buildingName].value : currentStorage[buildingName];
if (oldVal !== stateValue) { if (oldVal !== stateValue) {
@@ -262,7 +254,6 @@
let buildingList = []; let buildingList = [];
for (let name in currentStorage) { for (let name in currentStorage) {
const entry = currentStorage[name]; const entry = currentStorage[name];
// Abwärtskompatibler Check für die Datenstruktur
const val = (typeof entry === 'object') ? entry.value : entry; const val = (typeof entry === 'object') ? entry.value : entry;
const url = (typeof entry === 'object') ? entry.url : ''; const url = (typeof entry === 'object') ? entry.url : '';
@@ -285,14 +276,27 @@
if (item.numeric < 50) color = '#f44336'; if (item.numeric < 50) color = '#f44336';
else if (item.numeric < 90) color = '#ffeb3b'; else if (item.numeric < 90) color = '#ffeb3b';
const isCurrent = (item.name === buildingName) ? 'background-color: rgba(255,255,255,0.08); font-style: italic;' : ''; // Robuster Vergleich: Entweder über den Gebäudenamen ODER über den Dateinamen der URL
let isCurrentBuilding = false;
if (buildingName && item.name.toLowerCase() === buildingName.toLowerCase()) {
isCurrentBuilding = true;
} else if (item.url && window.location.href) {
const currentFile = window.location.pathname.split('/').pop().toLowerCase();
const itemFile = item.url.split('/').pop().toLowerCase();
if (currentFile && itemFile && currentFile === itemFile && currentFile !== 'city.php') {
isCurrentBuilding = true;
}
}
const isCurrentStyle = isCurrentBuilding ? 'background-color: rgba(255,255,255,0.08); font-style: italic;' : '';
const prefix = isCurrentBuilding ? '➡️ ' : '';
// Falls eine URL vorhanden ist, betten wir den Namen in einen Link ein
const nameDisplay = item.url const nameDisplay = item.url
? `<a href="${item.url}" style="color: #ddd; text-decoration: none; border-bottom: 1px dashed #666; transition: color 0.2s;" onmouseover="this.style.color='#ffca28'" onmouseout="this.style.color='#ddd'">${item.name}</a>` ? `<a href="${item.url}" style="color: #ddd; text-decoration: none; border-bottom: 1px dashed #666; transition: color 0.2s;" onmouseover="this.style.color='#ffca28'" onmouseout="this.style.color='#ddd'">${prefix}${item.name}</a>`
: item.name; : `${prefix}${item.name}`;
html += `<tr style="border-bottom: 1px solid #333; ${isCurrent}"> html += `<tr style="border-bottom: 1px solid #333; ${isCurrentStyle}">
<td style="padding: 6px 4px; padding-right: 15px;">${nameDisplay}</td> <td style="padding: 6px 4px; padding-right: 15px;">${nameDisplay}</td>
<td style="padding: 6px 4px; text-align: right; font-weight: bold; color: ${color}; white-space: nowrap;">${item.value}</td> <td style="padding: 6px 4px; text-align: right; font-weight: bold; color: ${color}; white-space: nowrap;">${item.value}</td>
</tr>`; </tr>`;