|
|
| Line 1: |
Line 1: |
| (function () {
| |
| if (mw.config.get('skin') !== 'minerva') return;
| |
|
| |
|
| var injected = false;
| |
|
| |
| function buildList(container) {
| |
| if (injected) return;
| |
| injected = true;
| |
|
| |
| var ul = document.createElement('ul');
| |
| ul.className = 'ic-mobile-menu-links';
| |
|
| |
| var links = [
| |
| { text: 'Home', page: 'Main Page' },
| |
| { text: 'All Agents', page: 'Category:Agent' },
| |
| { text: 'All Incidents', page: 'Category:Incidents' },
| |
| { text: 'All Vehicles', page: 'Category:Vehicles' },
| |
| { text: 'Submit an Incident', page: 'ICE List:Submit incident' },
| |
| { text: 'Submit an Agent', page: 'ICE List:Submit Agent' },
| |
| { text: 'About ICE List', page: 'ICE List Wiki:About' },
| |
| { text: 'Join as a Volunteer', page: 'ICE List Wiki:Volunteer' },
| |
| { text: 'Donate to ICE List', page: 'ICE List Wiki:Donate' }
| |
| ];
| |
|
| |
| links.forEach(function (l) {
| |
| var li = document.createElement('li');
| |
| var a = document.createElement('a');
| |
| a.textContent = l.text;
| |
| a.href = mw.util.getUrl(l.page);
| |
| li.appendChild(a);
| |
| ul.appendChild(li);
| |
| });
| |
|
| |
| container.appendChild(ul);
| |
| }
| |
|
| |
| function findMenuContainer() {
| |
| // Minerva menu panel containers vary by version/config
| |
| return (
| |
| document.querySelector('#mw-mf-page-left .menu') ||
| |
| document.querySelector('#mw-mf-page-left') ||
| |
| document.querySelector('.navigation-drawer__content') ||
| |
| document.querySelector('.menu') ||
| |
| null
| |
| );
| |
| }
| |
|
| |
| function tryInject() {
| |
| var c = findMenuContainer();
| |
| if (!c) return false;
| |
|
| |
| // Prefer an existing list inside the menu if present
| |
| var listHost = c.querySelector('ul') ? c : c;
| |
| buildList(listHost);
| |
| return true;
| |
| }
| |
|
| |
| // Try immediately
| |
| if (tryInject()) return;
| |
|
| |
| // Otherwise observe DOM until the menu exists
| |
| var obs = new MutationObserver(function () {
| |
| tryInject();
| |
| if (injected) obs.disconnect();
| |
| });
| |
|
| |
| obs.observe(document.documentElement, { childList: true, subtree: true });
| |
| })();
| |