Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1:
// Wikipedia UserOptions API Explorer with Tools Menu Integration
$(document).ready(function() {
// Add link to Tools menu on all pages
mw.hook('wikipage.content').add(function() {
mw.loader.using(['mediawiki.util'], function() {
// Only add the link if it doesn't already exist
if (!document.getElementById('t-useroptions-api')) {
mw.util.addPortletLink(
'p-tb', // Target portlet ID (Tools menu)
mw.config.get('wgServer') + '/wiki/Special:BlankPage/UserOptions', // Link URL
'User Options API', // Link text
't-useroptions-api', // Link ID
'Explore user options via MediaWiki API' // Tooltip
);
}
});
});
// Only run the main interface if we're on the specific page
if (mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' &&
mw.config.get('wgPageName') === 'Special:BlankPage/UserOptions') {
Line 63 ⟶ 80:
node.innerHTML = '<span class="json-key">' + key + ':</span> <span class="json-boolean">' + value + '</span>';
} else if (Array.isArray(value)) {
var toggleId = 'toggle-' + Date.now() + '-' + Math.random().toString().replace('.', '');
var toggle = document.createElement('span');
Line 91 ⟶ 108:
node.appendChild(children);
self.toggleNode(id);
};
})(toggleId);
} else if (typeof value === 'object') {
Line 106 ⟶ 126:
var keySpan = document.createElement('span');
keySpan.className = 'json-key';
keySpan.
var summary = document.createElement('span');
Line 136 ⟶ 156:
toggleNode: function(toggleId) {
var toggle = document.getElementById(toggleId);
if (!toggle) {
console.error('Toggle element not found:', toggleId);
return;
}
var children = toggle.parentNode.querySelector('.json-children');
if (!children) {
console.error('Children element not found for toggle:', toggleId);
return;
}
if (children.classList.contains('hidden')) {
Line 293 ⟶ 322:
};
// Event listeners (only when on the correct page)
$('#fetchBtn').on('click', function() {
UserOptionsAPI.displayUserOptions('jsonResult');
|