Widget: Homepage: Difference between revisions

From LINKS Community Center
Jump to: navigation, search
Eschmidt (talk | contribs)
No edit summary
Eschmidt (talk | contribs)
No edit summary
Line 106: Line 106:
     <script>
     <script>
         async function getData() {
         async function getData() {
             var platformQuery = '/api.php?action=ask&format=json&query=' + encodeURIComponent('[[Category:Social media platform]]|?IMAGE');
             const sourceQuery = '/api.php?action=ask&format=json&query=' + encodeURIComponent('[[Category:Social media platform]]|?IMAGE');
             var platformResponse = await fetch(platformQuery).then(response => response.json());
             const sourceResponse = await fetch(sourceQuery).then(response => response.json());


             var platformData = Object.getOwnPropertyNames(platformResponse.query.results).map(pName => {
             const sources = Object.getOwnPropertyNames(sourceResponse.query.results).map(platformName => ({
                return {
                     name: platformName,
                     name: pName,
                     image: sourceResponse.query.results[platformName].printouts.IMAGE[0].fulltext.replace('PAGENAME:', '')
                     image: platformResponse.query.results[pName].printouts.IMAGE[0].fulltext.replace('PAGENAME:', '')
             }));
                };
             });


             console.log(platformData)
             var logoUrlQuery = '/api.php?action=query&format=json&prop=imageinfo&iiprop=url&titles=' +
                encodeURIComponent(sources.map(source => source.image).join('|'));
            var logoUrlResponse = await fetch(logoUrlQuery).then(response => response.json());


             var imageUrlQuery = '/api.php?action=query&format=json&prop=imageinfo&iiprop=url&titles=' +
             for (const page of logoUrlResponse.query.pages) {
                 encodeURIComponent(platformData.map(platform => platform.image).join('|'));
                 console.log(page)
             var res = await fetch(imageUrlQuery).then(response => response.json());
             }


             Object.getOwnPropertyNames(res.query.pages).forEach(pageId => {
             // Object.getOwnPropertyNames(logoUrlResponse.query.pages).forEach(pageId => {
                var filename = res.query.pages[pageId].title;
            //    var filename = logoUrlResponse.query.pages[pageId].title;
                var url = res.query.pages[pageId].imageinfo[0].url;
            //    var url = logoUrlResponse.query.pages[pageId].imageinfo[0].url;
                platformData[platformData.findIndex(platform => platform.image === filename)].image = url;
            //    sources[sources.findIndex(platform => platform.image === filename)].image = url;
             });
             // });


             console.log(platformData)
             // console.log(sources)





Revision as of 13:15, 2 June 2022

Development verstion of the DCT Homepage.
Not ready for production!