MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 86: | Line 86: | ||
(function () { | (function () { | ||
function stripHeaderLines(text) { | |||
return text | |||
// Remove standalone short lines that look like section headers | |||
.replace(/(?:^|\n)\s*[A-Z][A-Za-z0-9'’\- ,()]{0,50}\s*(?=\n)/g, '\n') | |||
// Clean up excess blank lines | |||
.replace(/\n{2,}/g, '\n') | |||
.trim(); | |||
} | |||
function cleanAdarisPopups() { | function cleanAdarisPopups() { | ||
document.querySelectorAll( | document.querySelectorAll( | ||
| Line 94: | Line 103: | ||
} | } | ||
el.textContent = stripHeaderLines(el.textContent); | |||
el.textContent = el.textContent | |||
el.dataset.adarisCleaned = '1'; | el.dataset.adarisCleaned = '1'; | ||
}); | }); | ||
| Line 102: | Line 109: | ||
const observer = new MutationObserver(function () { | const observer = new MutationObserver(function () { | ||
cleanAdarisPopups(); | cleanAdarisPopups(); | ||
setTimeout(cleanAdarisPopups, 100); | setTimeout(cleanAdarisPopups, 100); | ||
| Line 116: | Line 122: | ||
cleanAdarisPopups(); | cleanAdarisPopups(); | ||
})(); | })(); | ||
mw.loader.using('mediawiki.util', function () { | |||
$(function () { | |||
var input = document.getElementById('pixelToMileInput'); | |||
var output = document.getElementById('pixelToMileOutput'); | |||
if (!input || !output) { | |||
return; | |||
} | |||
input.addEventListener('input', function () { | |||
var pixels = parseFloat(input.value); | |||
if (isNaN(pixels)) { | |||
output.textContent = '0 mi'; | |||
return; | |||
} | |||
var miles = (pixels / 1000) * 50; | |||
output.textContent = Math.round(miles) + ' mi'; | |||
}); | |||
}); | |||
}); | |||
$(function () { | |||
var container = document.getElementById('pixel-to-mile-calculator'); | |||
if (!container) { | |||
return; | |||
} | |||
container.className = 'adaris-tool-box'; | |||
container.innerHTML = | |||
'<label for="pixelToMileInput"><strong>Pixels:</strong></label><br>' + | |||
'<input id="pixelToMileInput" type="number" placeholder="Enter pixels">' + | |||
'<p><strong>Distance:</strong> <span id="pixelToMileOutput">0 mi</span></p>'; | |||
var input = document.getElementById('pixelToMileInput'); | |||
var output = document.getElementById('pixelToMileOutput'); | |||
input.addEventListener('input', function () { | |||
var pixels = parseFloat(input.value); | |||
if (isNaN(pixels)) { | |||
output.textContent = '0 mi'; | |||
return; | |||
} | |||
var miles = (pixels / 1000) * 50; | |||
output.textContent = Math.round(miles) + ' mi'; | |||
}); | |||
}); | |||