Widget:ProjectLabel: Difference between revisions
From Makerpedia
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
<script> | <script> | ||
function appStart(){ | |||
if(pageParams["page"]) | if(pageParams["page"]){ | ||
new mw.Api().get({ | new mw.Api().get({ | ||
action: 'query', | action: 'query', | ||
| Line 17: | Line 17: | ||
console.log(categories); | console.log(categories); | ||
}); | }); | ||
} | |||
} | } | ||
Revision as of 02:56, 21 March 2025
<script> function appStart(){ if(pageParams["page"]){ new mw.Api().get({
action: 'query', prop: 'revisions', rvprop: 'content', titles: pageParams["page"], format: 'json'
}).done(function (pageData) {
var pageId = Object.keys(pageData.query.pages)[0]; var content = pageData.query.pages[pageId].revisions[0]['*']; var pageUrl = mw.util.getUrl(page.title);
const regex = /\[\[Category:(.*?)\]\]/gi; let categories = content.match(regex); console.log(categories);
}); } }
if(!window.widgets) window.widgets = []; window.widgets.push(appStart); </script>