User:01tonythomas/common.js

$(document).ready(function {   // Select all section headings    $('.mw-headline').each(function { var sectionHeading = $(this);

// Find the existing edit link var editLink = sectionHeading.siblings('.mw-editsection');

// Create the "summarize" link as mw-summarysection var summarizeLink = $(' ') .addClass('mw-summarysection') .addClass('mw-editsection') .css('margin-left', '0.5em') // Set left margin to 0.5em .append(               $(' ')                    .addClass('mw-editsection-bracket')                    .text('[')            ) .append(               $('')                    .attr('href', '#')                    .text('summarize')                    .click(function(e) { e.preventDefault;

// Extract the text underneath the section from tags var sectionText = ''; var isH2orHeading2 = sectionHeading.is('h2') || sectionHeading.hasClass('mw-heading2'); debugger sectionHeading.parent.nextUntil(isH2orHeading2 ? 'h2, .mw-heading2' : 'h2, h3, .mw-heading2, h1, h4').each(function {                           if ($(this).is('h2, h3, .mw-heading2, h1, h4')) {                                return false; // Stop extraction at the next h2, h3, .mw-heading2, h1, or h4 element                            }                            if ($(this).is('p')) {                                sectionText += $(this).text.trim + '\n\n';                            }                        });

// Print the extracted text in an alert alert('Section summary:\n\n' + sectionText); })           )            .append(                $(' ')                    .addClass('mw-editsection-bracket')                    .text(']')            );

// Insert the "summarize" link after the edit link editLink.after(summarizeLink); }); });