diff --git a/Jasbee Gebäude-Prozentanzeige.js b/Jasbee Gebäude-Prozentanzeige.js index 2e09b9e..e451bda 100644 --- a/Jasbee Gebäude-Prozentanzeige.js +++ b/Jasbee Gebäude-Prozentanzeige.js @@ -1,8 +1,8 @@ // ==UserScript== // @name Jasbee Gebäude-Prozentanzeige // @namespace http://tampermonkey.net/ -// @version 3.2 -// @description Erlaubt das Scannen aller Gebäude im Hintergrund per Klick auf city.php (Mit optischen CSS-Fixes) +// @version 3.7 +// @description Scannt alle Gebäude im Hintergrund über direkte Pfade (Unterstützt neues Layout, robuste Pfeilerkennung per URL & Namenskorrektur) // @author Daniel + Gemini // @match https://www.jasbee.de/module/* // @grant none @@ -11,7 +11,6 @@ (function() { 'use strict'; - // Liste der erlaubten Dateinamen const allowedPages = [ 'city.php', 'lager.php', 'baumarkt.php', 'sportsbar.php', 'aliengeb.php', 'sauna.php', 'haus.php', 'fussball.php', @@ -21,11 +20,10 @@ const currentPath = window.location.pathname; const currentPage = currentPath.substring(currentPath.lastIndexOf('/') + 1).toLowerCase(); - if (!allowedPages.includes(currentPage)) { + if (!allowedPages.some(page => currentPage.includes(page))) { return; } - // 1. Popup-Element erstellen und stylen const popup = document.createElement('div'); popup.id = 'gebaeude-prozent-popup'; popup.style.position = 'fixed'; @@ -58,13 +56,11 @@ document.body.appendChild(popup); - // Scan-Button nur auf city.php einblenden const scanBtn = document.getElementById('scan-jasbee-buildings'); - if (currentPage === 'city.php') { + if (currentPage.includes('city.php')) { scanBtn.style.display = 'inline-block'; } - // Drag-and-Drop Steuerung const header = document.getElementById('popup-header'); let isDragging = false; let currentX, currentY, initialX, initialY; @@ -122,25 +118,40 @@ localStorage.setItem('jasbee_building_data', JSON.stringify(data)); } - // Hintergrund-Scanner Funktion - function startBackgroundScan() { - const links = Array.from(document.querySelectorAll('a[href]')); - const targets = []; - - 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; + 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() { + const targets = allowedPages + .filter(page => page !== 'city.php') + .map(page => `https://www.jasbee.de/module/${page}`); + scanBtn.disabled = true; scanBtn.style.background = '#555'; @@ -169,31 +180,25 @@ const doc = iframe.contentDocument || iframe.contentWindow.document; let buildingName = ''; - const breadcrumbItems = doc.querySelectorAll('.breadcrumb li'); - if (breadcrumbItems.length > 0) { - buildingName = breadcrumbItems[breadcrumbItems.length - 1].textContent.trim().replace(/[\t\r\n]/g, ''); - } + if (iframe.src.includes('aliengeb.php')) { + buildingName = 'Aliengebäude'; + } else { + const breadcrumbItems = doc.querySelectorAll('.breadcrumb li'); + if (breadcrumbItems.length > 0) { + buildingName = breadcrumbItems[breadcrumbItems.length - 1].textContent.trim().replace(/[\t\r\n]/g, ''); + } - const percentElements = doc.querySelectorAll('.pie-number'); - 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 (!buildingName) { + const currentTarget = targets[index - 1]; + const pageName = currentTarget.substring(currentTarget.lastIndexOf('/') + 1).replace('.php', ''); + buildingName = pageName.charAt(0).toUpperCase() + pageName.slice(1); } } + const stateValue = extractBuildingState(doc); + if (buildingName && stateValue) { let currentStorage = getStoredData(); - // Wir speichern Zustand und die genaue URL als Objekt ab currentStorage[buildingName] = { value: stateValue, url: iframe.src @@ -211,38 +216,25 @@ loadNext(); } - // Hauptfunktion zur Anzeige function updateBuildingStatus() { const contentDiv = document.getElementById('popup-content'); let currentStorage = getStoredData(); let hasNewData = false; let buildingName = ''; - const breadcrumbItems = document.querySelectorAll('.breadcrumb li'); - if (breadcrumbItems.length > 0) { - buildingName = breadcrumbItems[breadcrumbItems.length - 1].textContent.trim().replace(/[\t\r\n]/g, ''); + if (window.location.href.includes('aliengeb.php')) { + buildingName = 'Aliengebäude'; + } else { + const breadcrumbItems = document.querySelectorAll('.breadcrumb li'); + if (breadcrumbItems.length > 0) { + buildingName = breadcrumbItems[breadcrumbItems.length - 1].textContent.trim().replace(/[\t\r\n]/g, ''); + } } - const percentElements = document.querySelectorAll('.pie-number'); - - 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 (buildingName && !buildingName.toLowerCase().includes('city')) { + const stateValue = extractBuildingState(document); if (stateValue) { - // Abwärtskompatibilität prüfen (falls alte Datenstruktur ohne .value existiert) const oldVal = (typeof currentStorage[buildingName] === 'object') ? currentStorage[buildingName].value : currentStorage[buildingName]; if (oldVal !== stateValue) { @@ -262,7 +254,6 @@ let buildingList = []; for (let name in currentStorage) { const entry = currentStorage[name]; - // Abwärtskompatibler Check für die Datenstruktur const val = (typeof entry === 'object') ? entry.value : entry; const url = (typeof entry === 'object') ? entry.url : ''; @@ -285,14 +276,27 @@ if (item.numeric < 50) color = '#f44336'; 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 - ? `${item.name}` - : item.name; + ? `${prefix}${item.name}` + : `${prefix}${item.name}`; - html += `