Widget: DCTList: Difference between revisions

From LINKS Community Center
Jump to: navigation, search
Cschwentker (talk | contribs)
(Created page with "Test Widget")
 
Eschmidt (talk | contribs)
No edit summary
Line 1: Line 1:
Test Widget
<includeonly>
    <script>
        async function getData() {
            const sourceQuery = '/api.php?action=ask&format=json&query=' + encodeURIComponent('[[Category:Social media platform]]|?IMAGE');
            const sourceResponse = await fetch(sourceQuery).then(response => response.json());
 
            const sources = Object.getOwnPropertyNames(sourceResponse.query.results).map(platformName => ({
                name: platformName,
                image: sourceResponse.query.results[platformName].printouts.IMAGE[0].fulltext.replace('PAGENAME:', '')
            }));
 
            const logoUrlQuery = '/api.php?action=query&format=json&prop=imageinfo&iiprop=url&titles=' +
                                  encodeURIComponent(sources.map(source => source.image).join('|'));
            const logoUrlResponse = await fetch(logoUrlQuery).then(response => response.json());
 
            Object.getOwnPropertyNames(logoUrlResponse.query.pages).forEach(pageId => {
                const logoFileName = logoUrlResponse.query.pages[pageId].title;
                const logoUrl = logoUrlResponse.query.pages[pageId].imageinfo[0].url;
                sources[sources.findIndex(source => source.image === logoFileName)].image = logoUrl;
            });
 
            console.log(sources)
        }
 
        getData();
    </script>
</includeonly>

Revision as of 13:34, 2 June 2022