MediaWiki:IWB.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
mw.hook('wikipage.content').add(($c) => {
const nagito = $c.find('.iwb-download-btns span.wds-button');
if (!nagito.length) return;
const ua = navigator.userAgent;
const cws = 'https://chromewebstore.google.com/detail/indie-wiki-buddy/fkagelmloambgokoeokbpihmgpkbgbfm';
const amo = `https://addons.mozilla.org/${/Android/.test(ua) ? 'android' : 'firefox'}/addon/indie-wiki-buddy/`;
const browsers = [
{ test: /iPhone|iPad|iPod/, info: null },
{ test: /Firefox\//, info: ['Firefox', 'i-browser-firefox', amo] },
{ test: /Android/, info: null },
{ test: /Edg\//, info: ['Edge', 'i-browser-edge', cws] },
{ test: /OPR\//, info: ['Opera', 'i-download', cws] },
{ test: /Chrome\//, info: ['Chrome', 'i-browser-chrome', cws] }
];
const found = browsers.find(({ test }) => test.test(ua));
const match = found ? found.info : null;
if (match) {
const [name, icon, url] = match;
nagito.replaceWith(
$('<a>', { class: 'wds-button', href: url, target: '_blank', rel: 'noopener' }).append(
$('<i>', { class: `ego-i ${icon}`, 'aria-hidden': 'true' }),
`Download for ${name}`
)
);
} else {
nagito.replaceWith(
$('<p>').append(
'Indie Wiki Buddy is not available for this browser. It works on Chrome, Edge, Opera and Firefox, including ',
$('<a>', { href: 'https://addons.mozilla.org/android/addon/indie-wiki-buddy/', text: 'Firefox for Android', target: '_blank', rel: 'noopener' }),
'.'
)
);
}
});