User:Polygnotus/Scripts/Bullets.js

// <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>

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.