User:Polygnotus/Scripts/Bullets.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump.
This code will be executed when previewing this page.
This code will be executed when previewing this page.
Documentation for this user script can be added at User:Polygnotus/Scripts/Bullets.
// <nowiki>
// Real-time accessibility checker for list markup in comments
// https://en.wikipedia.org/wiki/User:Isaacl/On_wikitext_list_markup
// https://en.wikipedia.org/wiki/Wikipedia:Manual_of_Style/Accessibility
// https://en.wikipedia.org/wiki/User_talk:Polygnotus#talk_page_comment_conventions
(function() {
'use strict';
// Only run on edit pages
if (mw.config.get('wgAction') !== 'edit' && mw.config.get('wgAction') !== 'submit') {
return;
}
var lastContent = '';
var warningBox = null;
function createWarningBox() {
warningBox = $('<div>')
.css({
'background-color': '#fef6e7',
'border': '2px solid #fc3',
'padding': '10px',
'margin': '10px 0',
'border-radius': '3px',
'display': 'none'
})
.html('<strong>List markup accessibility issue detected:</strong> You are switching between different list types (changing from * to : or : to * at the same nesting level). This causes screen readers to announce extra list end/start pairs. Consider using {{pb}} template for paragraph breaks instead, or maintain consistent list markup.');
$('#wpTextbox1').before(warningBox);
}
function getListPrefix(line) {
// Extract the prefix characters (*, :, #) from start of line
var match = line.match(/^([*:#]+)/);
return match ? match[1] : '';
}
function checkForListIssues(content) {
var lines = content.split('\n');
var hasIssue = false;
for (var i = 0; i < lines.length - 1; i++) {
var currentLine = lines[i].trim();
var nextLine = lines[i + 1].trim();
var currentPrefix = getListPrefix(currentLine);
var nextPrefix = getListPrefix(nextLine);
// Skip if either line isn't a list item
if (!currentPrefix || !nextPrefix) continue;
// Check if we're at the same nesting level
if (currentPrefix.length === nextPrefix.length) {
// Get the last character of each prefix (the actual list type at this level)
var currentType = currentPrefix.charAt(currentPrefix.length - 1);
var nextType = nextPrefix.charAt(nextPrefix.length - 1);
// Problem: switching types at same level
if (currentType !== nextType) {
hasIssue = true;
break;
}
}
}
if (hasIssue) {
warningBox.slideDown(200);
} else {
warningBox.slideUp(200);
}
}
function monitorEditBox() {
var textbox = $('#wpTextbox1');
if (textbox.length === 0) return;
createWarningBox();
// Check initially
lastContent = textbox.val();
checkForListIssues(lastContent);
// Check every second
setInterval(function() {
var currentContent = textbox.val();
if (currentContent !== lastContent) {
lastContent = currentContent;
checkForListIssues(currentContent);
}
}, 1000);
}
// Wait for the edit box to be ready
$(document).ready(function() {
monitorEditBox();
});
})();
// </nowiki>