User:VikysyaKrayt/global.js

mw.loader.using("mediawiki.api").then(   function  {        if (mw.config.get("wgCanonicalSpecialPageName") === "Newimages") {

const api = new mw.Api;

const files = document.querySelectorAll(".wikia-gallery-item .lightbox"); const fileCaptions = document.querySelectorAll(".wikia-gallery-item .lightbox-caption");

var fileNames = [];

for (var file of files) { fileNames.push(file.href.split("/wiki/")[1]); }

for (let i = 0; i < fileCaptions.length; i++) { api.get({                   action: "query",                    titles: decodeURI(fileNames[i]),                    prop: "fileusage",                    format: "json"                }).done(                    function (data) {                        var fileUsage = document.createElement("div");                        var usage = data.query.pagesObject.keys(data.query.pages)[0].fileusage;

if (typeof usage !== "undefined") { console.log(usage);

usageText = document.createElement("span"); usageText.innerHTML = "Используется в: ";

usageText.style.fontSize = "14px";

for (var page of usage) { var usageLinkWrapper = document.createElement("span");

usageLinkWrapper.classList.add("file-used-in");

mw.util.addCSS(".file-used-in:not(:first-child):before { content: ', ' }");

var usageLink = document.createElement("a");

usageLink.href = mw.util.getUrl(page.title); usageLink.innerHTML = page.title;

usageText.appendChild(usageLinkWrapper);

usageLinkWrapper.appendChild(usageLink); }

fileUsage.appendChild(usageText);

fileCaptions[i].after(fileUsage); }                   }                );            }        }    } )