User:Lectrician1/WikibaseEcho.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// THIS IS A TYPESCRIPT FILE

jQuery(() => {
    $('.mw-echo-ui-notificationBadgeButtonPopupWidget-notice a').on('click', () => {
        var entities: string[] = [];

        $('.mw-echo-ui-notificationBadgeButtonPopupWidget-popup strong').each((index, element) => {
            if (element.innerText.includes('Q') || element.innerText.includes('L') || element.innerText.includes('P')) {
                entities.push(element.innerText)
            }
        })

        var api = new mw.Api();

        const d = await api.get({
            action: 'wbgetentities',
            ids: entities,
            format: 'json'
        }).promise()

        const userLanguages = OO.ui.getUserLanguages();

        $.each(d.entities, function (entityID, entity) {
            entityID = String(entityID)
            for (let language of userLanguages) {
                if (entity.labels[language]) {
                    $(`.mw-echo-ui-notificationBadgeButtonPopupWidget-popup strong:contains('${entityID}')`).val(`${entity.labels[language].value} (${entityID})`)
                    break;
                }
            }
        });
    })
})