Widget:GOV

Aus wiki
Zur Navigation springen Zur Suche springen
   <noscript>

⚠ JavaScript wird benötigt, um diese Inhalte anzuzeigen.

   </noscript>

???? Lade GOV-Daten... Falls nichts erscheint, ist JavaScript deaktiviert.

Um das GOV-Objekt direkt im GOV aufzurufen, <a href="https://gov.genealogy.net/item/show/" target="_blank">klicken Sie hier</a>

<script>

   (function () {
       const govId = ""; 
       const checkURL = `https://gov.genealogy.net/api/checkObjectId?itemId=${govId}`;
       const fetchURL = `https://gov.genealogy.net/item/wikihtml/${govId}`;
       const baseURL = "https://gov.genealogy.net";
       const containerId = `widget-container-${govId}`;
       const contentId = `widget-content-${govId}`;
       const warningId = `js-warning-${govId}`;
       const headerId = `gov-header-${govId}`;
       const widgetContainer = document.getElementById(containerId);
       const contentContainer = document.getElementById(contentId);
       const jsWarning = document.getElementById(warningId);
       const govHeader = document.getElementById(headerId);
       if (!widgetContainer || !contentContainer || !govHeader) {
           console.error("Fehler: Container für GOV-ID nicht gefunden:", govId);
           return;
       }
       // Entfernt den Ladehinweis, wenn JavaScript aktiv ist
       if (jsWarning) jsWarning.style.display = "none";
       // GOV-ID-Prüfung vor dem Laden der Daten

let govIdNew = null; // Globale Variable für neue GOV-ID

fetch(checkURL)

   .then(response => {
       if (response.status === 200) {
           return response.text(); // GOV-ID ist gültig → Weiter mit Hauptabfrage
       } else if (response.status === 301) {
           return response.text().then(body => {
               govIdNew = body.trim(); // Speichert die neue GOV-ID
               console.debug(`Check-Response Body:`, govIdNew);
               // **Sicherstellen, dass der Header aktualisiert wird**
               if (govHeader) {
                   govHeader.innerHTML = `Das GOV-Objekt ${govId} existiert nicht mehr. Es wurde durch ${govIdNew} ersetzt.
                       <a href="https://gov.genealogy.net/item/show/${govId}" target="_blank">
                       klicken Sie hier</a>, um Näheres zu erfahren.`;
               }
               // **Statt fetch() wird nur der Hinweis ausgegeben**

widgetContainer.innerHTML += `

Die GOV-ID ${govId} ist nicht mehr gültig und wurde durch ${govIdNew} ersetzt.

`;

               throw new Error("GOV-ID ersetzt");
           });
       } else if (response.status === 302) {
           // **Sicherstellen, dass der Header aktualisiert wird**
           if (govHeader) {
               govHeader.innerHTML = `Das GOV-Objekt ${govId} existiert nicht mehr. 
                   <a href="https://gov.genealogy.net/item/show/${govId}" target="_blank">
                   klicken Sie hier</a>, um Näheres zu erfahren.`;
           }
           // **Statt fetch() wird nur der Hinweis ausgegeben**

widgetContainer.innerHTML += `

Die GOV-ID ${govId} ist nicht mehr gültig und wurde durch eine andere ersetzt.

`;

           throw new Error("GOV-ID ersetzt");                
       } else if (response.status === 404) {

widgetContainer.innerHTML = `

${govId} ist keine gültige GOV-ID!

`;

           throw new Error("GOV-ID nicht gültig");
       } else {
           throw new Error(`Unerwarteter Status: ${response.status}`);
       }
   })
   .then(() => {
       // Falls die GOV-ID gültig ist oder ersetzt wurde, lade die Daten mit der neuen GOV-ID (falls vorhanden)
       const fetchTarget = govIdNew || govId;
       return fetch(`https://gov.genealogy.net/item/wikihtml/${fetchTarget}`);
   })
           .then(response => {
               if (!response.ok) {
                   throw new Error(`HTTP-Fehler! Status: ${response.status}`);
               }
               return response.text();
           })
           .then(html => {
               // Shadow DOM erstellen
               const shadow = contentContainer.attachShadow({ mode: 'open' });
               // Stile für das Widget im Shadow DOM hinzufügen
               const style = document.createElement('style');
               style.textContent = `
                   :host {
                       all: initial;
                       display: block;
                       max-width: 1200px;
                       margin: 20px auto;
                       padding: 0;
                       border: none;
                       background-color: #fff;
                       overflow: auto;
                       font-family: Arial, sans-serif;
                       font-size: 16px;
                   }
                   table {
                       width: 100%;
                       table-layout: auto;
                       border-collapse: collapse;
                       margin: 10px 0;
                       border: 1px solid #ccc;
                   }
                   th, td {
                       border: 1px solid #ddd;
                       padding: 10px;
                       text-align: left;
                       word-wrap: break-word;
                   }
                   th {
                       background-color: #f2f2f2;
                   }
                   td:first-child {
                       width: 1%;
                       white-space: nowrap;
                   }
                   ul {
                       padding-left: 20px;
                       margin: 10px 0;
                   }
                   object {
                       max-width: 100%;
                       width: 100%;
                       height: 500;
                       display: block;
                       margin: 0;
                   }
                   .map-container {
                       text-align: left;
                   }
                   a {
                       color: #007BFF;
                       text-decoration: none;
                   }
                   a:hover {
                       text-decoration: underline;
                   }
               `;
               // Geladenen HTML-Inhalt einfügen
               const content = document.createElement('div');
               content.innerHTML = html;
               // 1) Passe width und height in <object> an
               const objects = content.querySelectorAll('object[data^="https://www.genealogy.net/viewer-js/"]');
               objects.forEach(obj => {
                   obj.setAttribute('width', '100%');
                   obj.setAttribute('height', '500');
               });
               // 2) Passe <a> und  für den relationshipGraph an
               const imageLinks = content.querySelectorAll('a[href*="relationshipGraph"]');
               imageLinks.forEach(link => {
                   const originalHref = link.getAttribute('href');
                   link.setAttribute('href', baseURL + originalHref);
                   const img = link.querySelector('img');
                   if (img) {
                       const originalSrc = img.getAttribute('src');
                       img.setAttribute('src', baseURL + originalSrc + "?full-size=1");
                       img.setAttribute('width', '80%');
                   }
               });
               // 3) Füge Base-URL zu allen relativen <a> hinzu
               const allLinks = content.querySelectorAll('a[href^="/"]');
               allLinks.forEach(link => {
                   const originalHref = link.getAttribute('href');
                   link.setAttribute('href', baseURL + originalHref);
               });
               // 4) Füge Base-URL zu allen relativen  hinzu
               const allImages = content.querySelectorAll('img[src^="/"]');
               allImages.forEach(img => {
                   const originalSrc = img.getAttribute('src');
                   img.setAttribute('src', baseURL + originalSrc);
               });
               // Stile und Inhalte in das Shadow DOM einfügen
               shadow.appendChild(style);
               shadow.appendChild(content);
           })
           .catch(error => {
               console.error('Fehler beim Laden:', error);
           });
   })();

</script>