Gebruiker:MakiBoy/Gadget-TestGadget.js: verschil tussen versies

Uit Wikikids
Naar navigatie springen Naar zoeken springen
Regel 8: Regel 8:
 
     document.title = "LogCounter - WikiKids";
 
     document.title = "LogCounter - WikiKids";
  
     // table = `<table class="wikitable sortable">
+
     table = `<table class="wikitable sortable">
    //    <thead>
+
        <thead>
    //        <tr>  
+
            <tr>  
    //            <th>Paginatitel</th>
+
                <th>Paginatitel</th>
    //            <th>Laatst bezocht</th>
+
                <th>Laatst bezocht</th>
    //            <th>Normaal bezocht</th>
+
                <th>Normaal bezocht</th>
    //            <th>Via hoofdpagina bezocht</th>
+
                <th>Via hoofdpagina bezocht</th>
    //            <th>Totaal aantal</th>
+
                <th>Totaal aantal</th>
    //        </tr>
+
            </tr>
    //    </thead>
+
        </thead>
    //    <tbody>
+
        <tbody>
    //        ${pages.map((function (page, index) {
+
             ${pages.map((function (page) {
    //    var totalVisitors = page.normalVisitors + page.mainPageVisitors;
 
    //    var pageTitle = page.title.replace(/_/g, ' ');
 
    //    return `<tr>
 
    //                <td><a href="/${page.title}">${pageTitle}</a></td>
 
    //                <td>${page.date}</td>
 
    //                <td>${page.normalVisitors}</td>
 
    //                <td>${page.mainPageVisitors}</td>
 
    //                <td>${totalVisitors}</td>
 
    //             </tr>`;
 
    // })).join('')}
 
    //    </tbody>
 
    // </table>`;
 
 
 
    table = `
 
    {| class="wikitable sortable"
 
    ! Paginatitel
 
    ! Laatst bezocht
 
    ! Normaal bezocht
 
    ! Via hoofdpagina bezocht
 
    ! Totaal aantal
 
    ${pages.map((function (page, index) {
 
 
         var totalVisitors = page.normalVisitors + page.mainPageVisitors;
 
         var totalVisitors = page.normalVisitors + page.mainPageVisitors;
 
         var pageTitle = page.title.replace(/_/g, ' ');
 
         var pageTitle = page.title.replace(/_/g, ' ');
         return `
+
         return `<tr>
        |-
+
                    <td><a href="/${page.title}">${pageTitle}</a></td>
        | [[${page.title}|${pageTitle}]]
+
                    <td>${page.date}</td>
        | ${page.date}
+
                    <td>${page.normalVisitors}</td>
        | ${page.normalVisitors}
+
                    <td>${page.mainPageVisitors}</td>
        | ${page.mainPageVisitors}
+
                    <td>${totalVisitors}</td>
        | ${totalVisitors}
+
                </tr>`;
        `;
 
 
     })).join('')}
 
     })).join('')}
     `;
+
        </tbody>
 +
     </table>`;
  
 
     document.getElementById('bodyContent').innerHTML = table;
 
     document.getElementById('bodyContent').innerHTML = table;
Regel 58: Regel 37:
  
 
function getPages() {
 
function getPages() {
     return [
+
     var pages = [];
        {
+
    var request = new XMLHttpRequest();
            "title": "Wikikids:Boomhut",
+
    request.open('GET', 'https://wikikids.martvanweeghel.nl/pages', false);
            "date": "2023-01-13",
+
    request.send(null);
            "normalVisitors": 314,
+
    if (request.status === 200) {
            "mainPageVisitors": 0
+
         pages = JSON.parse(request.responseText);
        },
+
    }
        {
+
     return pages;
            "title": "Portaal:Kids",
 
            "date": "2023-01-13",
 
            "normalVisitors": 105,
 
            "mainPageVisitors": 0
 
        },
 
         {
 
            "title": "Hoofdpagina",
 
            "date": "2023-01-13",
 
            "normalVisitors": 3171,
 
            "mainPageVisitors": 0
 
        },
 
        {
 
            "title": "Stefanskroon",
 
            "date": "2023-01-12",
 
            "normalVisitors": 1,
 
            "mainPageVisitors": 0
 
        },
 
        {
 
            "title": "Wikikids:Awards",
 
            "date": "2023-01-13",
 
            "normalVisitors": 78,
 
            "mainPageVisitors": 0
 
        },
 
        {
 
            "title": "Federale_Republiek_Joegoslavië",
 
            "date": "2023-01-13",
 
            "normalVisitors": 1,
 
            "mainPageVisitors": 0
 
        },
 
        {
 
            "title": "Wikikids:Alarm",
 
            "date": "2023-01-13",
 
            "normalVisitors": 88,
 
            "mainPageVisitors": 0
 
        },
 
        {
 
            "title": "Bestormingen_op_het_Plein_van_de_Drie_Machten",
 
            "date": "2023-01-13",
 
            "normalVisitors": 0,
 
            "mainPageVisitors": 2
 
        },
 
        {
 
            "title": "Gebruiker:Rots61",
 
            "date": "2023-01-13",
 
            "normalVisitors": 1,
 
            "mainPageVisitors": 0
 
        },
 
        {
 
            "title": "PIM-systeem",
 
            "date": "2023-01-13",
 
            "normalVisitors": 1,
 
            "mainPageVisitors": 0
 
        },
 
        {
 
            "title": "Gebruiker:MakiBoy",
 
            "date": "2023-01-13",
 
            "normalVisitors": 3,
 
            "mainPageVisitors": 0
 
        },
 
        {
 
            "title": "Koninkrijk_Joegoslavië",
 
            "date": "2023-01-13",
 
            "normalVisitors": 1,
 
            "mainPageVisitors": 0
 
        },
 
        {
 
            "title": "Socialistische_Federale_Republiek_Joegoslavië",
 
            "date": "2023-01-13",
 
            "normalVisitors": 0,
 
            "mainPageVisitors": 1
 
        }
 
     ];
 
 
}
 
}
  

Versie van 13 jan 2023 14:26

/* jshint sub:true maxerr:100000 */
// Gadget gemaakt door [[User:MakiBoy]]
// Documentatie op [[WikiKids:LogCounter]]
var version = '1.2';

function showProject(pages) {
    document.getElementsByTagName("h1")[0].textContent = "Speciaal:LogCounter";
    document.title = "LogCounter - WikiKids";

    table = `<table class="wikitable sortable">
        <thead>
            <tr> 
                <th>Paginatitel</th>
                <th>Laatst bezocht</th>
                <th>Normaal bezocht</th>
                <th>Via hoofdpagina bezocht</th>
                <th>Totaal aantal</th>
            </tr>
        </thead>
        <tbody>
            ${pages.map((function (page) {
        var totalVisitors = page.normalVisitors + page.mainPageVisitors;
        var pageTitle = page.title.replace(/_/g, ' ');
        return `<tr>
                    <td><a href="/${page.title}">${pageTitle}</a></td>
                    <td>${page.date}</td>
                    <td>${page.normalVisitors}</td>
                    <td>${page.mainPageVisitors}</td>
                    <td>${totalVisitors}</td>
                </tr>`;
    })).join('')}
        </tbody>
    </table>`;

    document.getElementById('bodyContent').innerHTML = table;
}

function getPages() {
    var pages = [];
    var request = new XMLHttpRequest();
    request.open('GET', 'https://wikikids.martvanweeghel.nl/pages', false);
    request.send(null);
    if (request.status === 200) {
        pages = JSON.parse(request.responseText);
    }
    return pages;
}

if (mw.config.get('wgNamespaceNumber') === -1 && mw.config.get('wgTitle') === "LogCounter") {
    document.getElementById("footer-places").innerHTML += '<li id="footer-places-gadget-LogCounter">Script gemaakt door <a href="/User:MakiBoy" title="Gebruiker:MakiBoy">MakiBoy</a>, versie: ' + version + '</li>';
    var allPages = getPages();
    showProject(allPages);
}
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=Gebruiker:MakiBoy/Gadget-TestGadget.js&oldid=759773"