Widget: HouseTile: Unterschied zwischen den Versionen

Aus Herrenhäuser
Wechseln zu: Navigation, Suche
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 59: Zeile 59:
var params = {
var params = {
     action: "parse",
     action: "parse",
     page: "<!--{$page|escape:'url'}-->",   
     prop: "extracts&explaintext",
    titles: "<!--{$page|escape:'url'}-->",   
     format: "json"
     format: "json"
};
};

Version vom 22. Oktober 2024, 12:34 Uhr

Loading image...

   <a href="" class="btn btn-primary">EXPLORE</a>


<script> var url = "https://wb.manorhouses.tibwiki.io/w/api.php";

var params = {

   action: "query",
   prop: "images",
   titles: "",  // Page title whose first image you want to retrieve
   format: "json"

};

url = url + "?origin=*"; Object.keys(params).forEach(function(key) {

   url += "&" + key + "=" + params[key];

});

fetch(url)

   .then(function(response) {
       return response.json();
   })
   .then(function(response) {
       var pages = response.query.pages;
       var firstImageTitle = null;
       // Find the first image title
       for (var page in pages) {
           if (pages[page].images && pages[page].images.length > 0) {
               firstImageTitle = pages[page].images[0].title;
               break;  // Exit loop after getting the first image
           }
       }
       // If a first image is found, display it
       if (firstImageTitle) {
           // Construct the URL to display the image
           var imageUrl = "https://wb.manorhouses.tibwiki.io/wiki/Special:FilePath/" + firstImageTitle.replace('File:', );
           document.getElementById("firstImageContainer").innerHTML = '<img src="' + imageUrl + '" alt="First Image" style="max-width:100%;">';
       } else {
           document.getElementById("firstImageContainer").innerHTML = "No image found.";
       }
   })
   .catch(function(error) {
       console.log("Error: " + error);
       document.getElementById("firstImageContainer").innerHTML = "Error retrieving image.";
   });

// now get wikitext from page var params = {

   action: "parse",
   prop: "extracts&explaintext", 
   titles: "",  
   format: "json"

}; url = "https://wb.manorhouses.tibwiki.io/w/api.php"; url = url + "?origin=*"; Object.keys(params).forEach(function(key) {

   url += "&" + key + "=" + params[key];

}); console.log(url); fetch(url)

   .then(function(response) {
       return response.json();
   })
   .then(function(response) {
       var text = response.parse.text['*'];
       
       // If a first image is found, display it
       if (text) {
           document.getElementById("textContainer").innerHTML = text;
       } else {
           document.getElementById("textContainer").innerHTML = "No text found.";
       }
   })
   .catch(function(error) {
       console.log("Error: " + error);
       document.getElementById("textContainer").innerHTML = "Error retrieving text.";
   });

</script>