Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if (node == null)
        node = document;
    if (tag == null)
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)" searchClass "(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i  ) {
        if (pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j  ;
        }
    }
    return classElements;
}

// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
    twinkleConfig = {};
}

if( typeof( TwinkleConfig.summaryRatedAd ) == 'undefined' ) {
    TwinkleConfig.summaryRatedAd = " (script assisted)";
}

if( typeof( TwinkleConfig.watchResolvePages ) == 'undefined' ) {
    TwinkleConfig.watchResolvePages = true;
}

function twinkleresolve() {
    var links = getElementsByClass('editsection', document, 'span');
    var editLinks = new Array();
    for ( var i = 0; i < links.length; i  ) {
        editLinks.push(links[i].getElementsByTagName('a')[0]);
    }
    links = editLinks;
  
    for (var i = 0; i < links.length; i  ) {
        var resolveLink = document.createElement('a');
        resolveLink.title = "Resolve";
        resolveLink.onclick = makeCallback(i   1); 

        resolveLink.appendChild(document.createTextNode("unwatch"));
        links[i].parentNode.insertBefore(resolveLink, links[i]);
        
        var delim = document.createTextNode(" · ");
        links[i].parentNode.insertBefore(delim, links[i]);
    }

}

addOnloadHook(twinkleresolve);

function makeCallback(num) { 
    function twinkleResolveCallback() {
        var Window = new SimpleWindow( 600, 250 );
    Window.setTitle( "Resolve section" );
    var form = new QuickForm( twinkleresolve.evaluate );
        form.append( { 
            type: 'hidden',
            name: 'secnum',
            value: num
        } );

    var field = form.append( {
            type: 'field',
            label: 'Message: '
        } );
    field.append( {
            type: 'textarea',
            name: 'reason',
            label: 'Reason:'
        } );
    form.append( { type:'submit' } );

    var result = form.render();
    Window.setContent( result );
    Window.display();
  }

  return twinkleResolveCallback;
}


twinkleresolve.callbacks = {

main: function( self ) {
    var form = self.responseXML.getElementById('editform');
    var text = form.wpTextbox1.value;
    if(  text.search(/\{\{[mM]ath(s)? rating/) != -1 ) {
        self.statelem.warn('Removing previous rating templates');        
        text =  text.replace(/\{\{[mM]aths? rating([a-zA-Z |=])*\}\}/g,  '');  
        if(  text.search(/\{\{[mM]ath(s)? rating/) != -1 ) {
            self.statelem.warn('Failed to remove previous templates, aborting');        
            alert(text);
            return;
        }
    }

    var postData = {
        'wpMinoredit': undefined, // Per memo
        'wpWatchthis': TwinkleConfig.watchRatedMathPages ? 'true' : undefined,
        'wpStarttime': form.wpStarttime.value,
        'wpEdittime': form.wpEdittime.value,
        'wpAutoSummary': form.wpAutoSummary.value,
        'wpEditToken': form.wpEditToken.value,
        'wpSummary': "Rating article for WikiProject Mathematics. Quality: " 
                                         self.params.quality 
                                         " Priority: "   self.params.priority
                                         " Field: "  self.params.field   " " 
                                         TwinkleConfig.summaryRatedAd,
            'wpTextbox1': "\{\{maths rating|class="   self.params.quality 
                                         "|priority="   self.params.priority
                                         "|field="  self.params.field   "}}\n"   text
        };

    self.post( postData );
    },
}

twinkleresolve.evaluate = function twinkleresolveCallbackEvaluate(e) {
    var form = e.target;
    var secnum = form.secnum.value;
    var reason = form.reason.value;

    alert(secnum);
    alert(reason);
    return;

    wgPageName = wgPageName.replace(/_/g, ' ');

    if ( wgNamespaceNumber == 0){ 
        wgPageName = 'Talk:'   wgPageName;
    }

    Status.init( form );

    var query = { 
        'title': wgPageName, 
        'action': 'submit'
    };

    Wikipedia.actionCompleted.redirect = wgPageName;
    Wikipedia.actionCompleted.notice = "Tagging complete, reloading talk page";
    var wikipedia_wiki = new Wikipedia.wiki('Tagging page', query,  
            twinklerate.callbacks.main);
    wikipedia_wiki.params = { quality: quality, priority: priority, field: field};
    wikipedia_wiki.followRedirect = false;
    wikipedia_wiki.get();
}