User:Clearfrienda/Scripts/fastsummary.js

From Wikipedia, the free encyclopedia
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.
// <nowiki>
// From User:TheJJJunk/FastSummary.js
var FastSummary = FastSummary || {};

$(document).ready(function() 
{
    //initialize Constants
    FastSummary.Constants = getFastSummaryConstants();

    //only execute on the edit page
    if (!FastSummary.Constants.IS_EDIT_PAGE || FastSummary.Constants.IS_JS_PAGE || FastSummary.Constants.ARTICLE_TEXT_BOX_ELEMENT == null)
        return;

    let btnStyle      = "box-shadow:inset 0px 1px 0px 0px #ffffff;background:linear-gradient(to bottom, #f9f9f9 5%, #e9e9e9 100%);background-color:#f9f9f9;border-radius:6px;border:1px solid #ccc;display:inline-block;cursor:pointer;color:#666666;font-family:Arial;font-size:12px;font-weight:bold;padding:3px 6px;text-decoration:none;text-shadow:0px 1px 0px #ffffff;margin-bottom:5px;";
    let linkStartText = "javascript:FastSummary.addToSummary('";
    let linkEndText   = " ([[User:TheJJJunk/FastSummary|FS]])');";
    
    //init UI
    let link1 = $("<a>", {
        "href":linkStartText + "Maintenance: Added missing [[Template:Notelist|notelist]]" + linkEndText, 
        "style":btnStyle
    });
    link1.text("NOTEL");
    
    //init UI
    let link2 = $("<a>", {
        "href":linkStartText + "Maintenance: Fixed [[Category:Pages with URL errors|URL error]]" + linkEndText, 
        "style":btnStyle
    });
    link2.text("URLERR");
    
    //init UI
    let link3 = $("<a>", {
        "href":linkStartText + "Categorization: [[Category:Stubs|Sorted uncategorized stub]]:" + linkEndText, 
        "style":btnStyle
    });
    link3.text("STUB");
    
    //init UI
    let link4 = $("<a>", {
        "href":linkStartText + "CS1 error: [[Category:CS1 errors: extra text: edition|Extra text (edition)]]" + linkEndText, 
        "style":btnStyle
    });
    link4.text("CS1:ED");
    
    //init UI
    let link5 = $("<a>", {
        "href":linkStartText + "CS1 error: [[Category:CS1 errors: extra text: pages|Extra text (pages)]]" + linkEndText, 
        "style":btnStyle
    });
    link5.text("CS1:PGE");
    
    //init UI
    let link6 = $("<a>", {
        "href":linkStartText + "CS1 error: [[Category:CS1 errors: invalid parameter value|Invalid parameter value]]" + linkEndText, 
        "style":btnStyle
    });
    link6.text("CS1:INVAL");
    
    //init UI
    let link7 = $("<a>", {
        "href":linkStartText + "CS1 error: [[Category:CS1 errors: missing name|Missing name]]" + linkEndText, 
        "style":btnStyle
    });
    link7.text("CS1:NME");
    
    //init UI
    let link8 = $("<a>", {
        "href":linkStartText + "CS1 error: [[Category:CS1 errors: redundant parameter|Redundant parameter]" + linkEndText, 
        "style":btnStyle
    });
    link8.text("CS1:REDUN");
   
    //init UI
    let link9 = $("<a>", {
        "href":linkStartText + "CS1 error: [[Category:CS1 errors: archive-url|archive-url error]]" + linkEndText, 
        "style":btnStyle
    });
    link9.text("CS1:ARCH");
   
    //init UI
    let link10 = $("<a>", {
        "href":linkStartText + "CS1 error: [[Category:CS1 errors: date|Dates]]" + linkEndText, 
        "style":btnStyle
    });
    link10.text("CS1:DTE");
    
    //init UI
    let link11 = $("<a>", {
        "href":linkStartText + "CS1 error: [[Category:CS1 errors: invisible characters|Invisible character]]" + linkEndText, 
        "style":btnStyle
    });
    link11.text("CS1:INVIS");
    
    //init UI
    let link12 = $("<a>", {
        "href":linkStartText + "CS1 error: [[Category:CS1 errors: markup|Markup]]" + linkEndText, 
        "style":btnStyle
    });
    link12.text("CS1:MRKP");
    
    //init UI
    let link13 = $("<a>", {
        "href":linkStartText + "CS1 error: [[Category:CS1 errors: unsupported parameter|Unknown/unsupported parameter]]" + linkEndText, 
        "style":btnStyle
    });
    link13.text("CS1:UNKN");
    
    //init UI
    let link14 = $("<a>", {
        "href":linkStartText + "Biography: Added [[Category:Biography articles without living parameter|living]], [[Category:Biography articles without listas parameter|listas]] parameters" + linkEndText, 
        "style":btnStyle
    });
    link14.text("BIO_LL");
    
    //init UI
    let link15 = $("<a>", {
        "href":linkStartText + "Biography: Added [[Category:Biography articles without living parameter|living]] parameter" + linkEndText, 
        "style":btnStyle
    });
    link15.text("BIO_LIV");
        //init UI
    let link16 = $("<a>", {
        "href":linkStartText + "Biography: Added [[Category:Biography articles without listas parameter|listas]] parameter" + linkEndText, 
        "style":btnStyle
    });
    link16.text("BIO_LIST");
        //init UI
    let link17 = $("<a>", {
        "href":linkStartText + "Maintenance: Added missing [[Template:Reflist|reflist]]" + linkEndText, 
        "style":btnStyle
    });
    link17.text("REFL");
    let link18 = $("<a>", {
        "href":linkStartText + "Maintenance: [[Category:Articles with bare URLs for citations from November 2021|Filling & cleaning citaitons with bare URLs from November 2021]]" + linkEndText, 
        "style":btnStyle
    });
    link18.text("BARE-NOV21");
    
    $('#wpSummaryLabel').prepend(link18).prepend("&nbsp;").prepend(link17).prepend("&nbsp;").prepend(link16).prepend("&nbsp;").prepend(link15).prepend("&nbsp;").prepend(link14).prepend("&nbsp;").prepend(link13).prepend("&nbsp;").prepend(link12).prepend("&nbsp;").prepend(link11).prepend("&nbsp;").prepend(link10).prepend("&nbsp;").prepend(link9).prepend("&nbsp;").prepend(link8).prepend("&nbsp;").prepend(link7).prepend("&nbsp;").prepend(link6).prepend("&nbsp;").prepend(link5).prepend("&nbsp;").prepend(link4).prepend("&nbsp;").prepend(link3).prepend("&nbsp;").prepend(link2).prepend("&nbsp;").prepend(link1);
});

FastSummary.addToSummary = function(summary) {
	var wpSummary = document.getElementById('wpSummary');
	if (wpSummary.value !== '') {
		summary = wpSummary.value + '; ' + summary;
	}
	if ((wpSummary.maxLength > 0) && (summary.length > wpSummary.maxLength)) {
		alert('Error: If the proposed text is added to the summary, its length will exceed the character limit.');
		return;
	}
	wpSummary.value = summary;
}

function getFastSummaryConstants()
{
	var ARA_Constants = ARA_Constants || {};

	//article text box element
	ARA_Constants.ARTICLE_TEXT_BOX_ELEMENT = $("#wpTextbox1");
	
	//are we on an Edit page?
	ARA_Constants.IS_EDIT_PAGE = mw.config.get('wgAction') === 'edit' || mw.config.get('wgAction') === 'submit';
	
	//are we on a JS page?
	ARA_Constants.IS_JS_PAGE = mw.config.get('wgRelevantPageName').endsWith('.js');
	
	//the ARA Suggestion box, which appears above the editing section
	ARA_Constants.SUGGESTION_BOX_DIV = $('<div>', {'id':'suggestionBox.ARA', 'style':'border:dashed #ccc 1px;color:#888;'});
	
	//the Add to Summary box, which appears near the edit summary
	ARA_Constants.ADD_TO_SUMMARY_DIV = $('<div>', {'id':'addToSummaryBox.ARA', 'style':'border:dashed #ccc 1px;color:#888;display:none;'});
	
	ARA_Constants.DEFAULT_MAX_SUGGESTIONS = 8;
	ARA_Constants.maxSuggestions = ARA_Constants.DEFAULT_MAX_SUGGESTIONS;
	ARA_Constants.suggestions; // : Suggestion[]
	ARA_Constants.appliedSuggestions = {}; // : Map<String, int>
	
	ARA_Constants.scannedText = null; // remember what we scan, to check if it is
	                       // still the same when we try to fix it
	
	ARA_Constants.BIG_THRESHOLD = 100 * 1024;
	ARA_Constants.isBigScanConfirmed = false; // is the warning about a big article confirmed
	ARA_Constants.isTalkPageScanConfirmed = false;
	
	ARA_Constants.scanTimeoutId = null; // a timeout is set after a keystroke and before
	                         // a scan, this variable tracks its id
	                         
	return ARA_Constants;
}
// </nowiki>