MediaWiki:Common.js: Difference between revisions
From Artifacts of Capitalism
No edit summary |
No edit summary |
||
| Line 58: | Line 58: | ||
$('a.external').attr('target', '_blank'); | $('a.external').attr('target', '_blank'); | ||
}); | }); | ||
mw. | // Wait for the Chameleon layout to finish before inserting fields | ||
mw.loader.using('mediawiki.util').then(function () { | |||
if (mw.config.get('wgCanonicalSpecialPageName') !== 'CreateAccount') return; | if (mw.config.get('wgCanonicalSpecialPageName') !== 'CreateAccount') return; | ||
// | // Observe the page until the form appears | ||
const realNameInput = document.getElementById('wpRealName'); | const observer = new MutationObserver(() => { | ||
const realNameInput = document.getElementById('wpRealName'); | |||
if (!realNameInput) return; // Not yet loaded | |||
const form = realNameInput.closest('form'); | |||
if (!form) return; | |||
// Prevent duplicate injection | |||
if (document.getElementById('wpAffiliation')) return; | |||
// --- Affiliation field --- | |||
const affDiv = document.createElement('div'); | |||
affDiv.className = 'mw-input'; | |||
affDiv.innerHTML = ` | |||
<label for="wpAffiliation">Affiliation</label> | |||
<input type="text" id="wpAffiliation" name="wpAffiliation" | |||
required class="mw-ui-input form-control"/> | |||
`; | |||
// --- Institutional Email field --- | |||
const instDiv = document.createElement('div'); | |||
instDiv.className = 'mw-input'; | |||
instDiv.innerHTML = ` | |||
<label for="wpInstitutionalEmail">Institutional Email</label> | |||
<input type="email" id="wpInstitutionalEmail" name="wpInstitutionalEmail" | |||
required class="mw-ui-input form-control"/> | |||
`; | |||
// Insert right after Real Name | |||
const realNameDiv = | |||
realNameInput.closest('.mw-input, .form-group, p') || realNameInput.parentNode; | |||
realNameDiv.insertAdjacentElement('afterend', instDiv); | |||
realNameDiv.insertAdjacentElement('afterend', affDiv); | |||
// Once inserted, stop observing | |||
observer.disconnect(); | |||
}); | |||
// Start watching the body for when the form arrives | |||
observer.observe(document.body, { childList: true, subtree: true }); | |||
}); | }); | ||
Revision as of 16:02, 11 November 2025
// Ensure viewport meta exists (iOS layout fix)
(function () {
if (!document.querySelector('meta[name="viewport"]')) {
var m = document.createElement('meta');
m.name = 'viewport';
m.content = 'width=device-width, initial-scale=1, shrink-to-fit=no';
document.head.appendChild(m);
}
})();
mw.hook('wikipage.content').add(function ($c) {
var groups = mw.config.get('wgUserGroups') || [];
if (groups.indexOf('approver') !== -1) return; // approvers keep the checkbox
// Hide the Draft namespace checkbox in the advanced search pane
$c.find('input[name="ns' + 3000 + '"]').closest('label, .mw-advancedSearch-ns_option').hide();
});
// Load Google CSE only on Advanced_search page
mw.loader.using('mediawiki.util').then(function () {
var page = mw.config.get('wgPageName');
if (page !== 'Artifacts_of_Capitalism:Advanced_search') return;
console.log('[CSE] Loading on:', page);
// Ensure CSE callback setup exists before script load
window.__gcse = {
searchCallbacks: {
ready: function () {
try {
var params = new URLSearchParams(window.location.search);
var q = params.get('q');
if (q) {
var hash = 'gsc.tab=0&gsc.q=' + encodeURIComponent(q);
if (!window.location.hash.includes('gsc.q=')) {
window.location.hash = hash;
console.log('[CSE] Applied query:', q);
}
}
} catch (err) {
console.warn('[CSE] Query error:', err);
}
}
}
};
// Inject Google CSE script
var script = document.createElement('script');
script.async = true;
script.src = 'https://cse.google.com/cse.js?cx=b194aa5e4d64344ad';
script.onload = function () {
console.log('[CSE] Script loaded successfully');
};
script.onerror = function () {
console.error('[CSE] Failed to load cse.js');
};
document.body.appendChild(script);
});
// Open all external links in a new window or tab
$(document).ready(function() {
$('a.external').attr('target', '_blank');
});
// Wait for the Chameleon layout to finish before inserting fields
mw.loader.using('mediawiki.util').then(function () {
if (mw.config.get('wgCanonicalSpecialPageName') !== 'CreateAccount') return;
// Observe the page until the form appears
const observer = new MutationObserver(() => {
const realNameInput = document.getElementById('wpRealName');
if (!realNameInput) return; // Not yet loaded
const form = realNameInput.closest('form');
if (!form) return;
// Prevent duplicate injection
if (document.getElementById('wpAffiliation')) return;
// --- Affiliation field ---
const affDiv = document.createElement('div');
affDiv.className = 'mw-input';
affDiv.innerHTML = `
<label for="wpAffiliation">Affiliation</label>
<input type="text" id="wpAffiliation" name="wpAffiliation"
required class="mw-ui-input form-control"/>
`;
// --- Institutional Email field ---
const instDiv = document.createElement('div');
instDiv.className = 'mw-input';
instDiv.innerHTML = `
<label for="wpInstitutionalEmail">Institutional Email</label>
<input type="email" id="wpInstitutionalEmail" name="wpInstitutionalEmail"
required class="mw-ui-input form-control"/>
`;
// Insert right after Real Name
const realNameDiv =
realNameInput.closest('.mw-input, .form-group, p') || realNameInput.parentNode;
realNameDiv.insertAdjacentElement('afterend', instDiv);
realNameDiv.insertAdjacentElement('afterend', affDiv);
// Once inserted, stop observing
observer.disconnect();
});
// Start watching the body for when the form arrives
observer.observe(document.body, { childList: true, subtree: true });
});