User:DannyS712/EFFPRH/sandbox.js: Difference between revisions

Content deleted Content added
m fix typo
links for sections
Line 15:
EFFPRH.run = function () {
console.log( 'EFFPRH - running' );
// Add links to each section to open a dialog
$('span.mw-headline').each( function () {
const sectionNum = EFFPRH.getHeadingSectionNum( $( this ).parent() );
if ( sectionNum !== -1 ) {
console.log( $( this ), sectionNum );
}
} );
};
 
/**
* Get the section number for a response, given the <h2> or similar element
* that should contain an edit section link. Returns -1 on failure.
*/
EFFPRH.getHeadingSectionNum = function ( $heading ) {
const editSectionUrl = $heading.find( '.mw-editsection a:first' ).attr( 'href' );
if ( editSectionUrl === undefined ) {
return -1;
}
const sectionMatch = editSectionUrl.match( /&section=(\d+)(?:$|&)/ );
if ( sectionMatch === null ) {
return -1;
}
return parseInt( sectionMatch[1] );
};