Jump to content

User:CanonNi/Scripts/AlertAssistant.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by CanonNi (talk | contribs) at 13:57, 18 June 2024 (add first toggle). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// Partially copied from [[User:Nyakase/Scripts/StatusChanger.js]]
// Work in progress, report bugs as [[User talk:CanonNi]]
// <nowiki>

$(function (){
    //Check if the config is defined
    if (typeof(alertHelperConfig) == 'undefined') {
      alertHelperConfig = {};
    }
   
    if (typeof(alertHelperConfig.topicList) == 'undefined') {
        alertHelperConfig.topicList = {
        	'a-a' : [ 'Armenia, Azerbaijan, or related conflicts' ],
        	'a-i' : [ 'the Arab–Israeli conflict' ],
        	'ab'  : [ 'abortion' ],
        	'acu' : [ 'complementary and alternative medicine' ],
        	'ap'  : [ 'post-1992 politics of the United States and closely related people' ],
        	'at'  : [ 'the English Wikipedia article titles policy and Manual of Style' ],
        	'b'   : [ 'the Balkans or Eastern Europe '],
        	'blp' : [ 'articles about living or recently deceased people, and edits relating to the subject (living or recently deceased) of such biographical articles' ],
        	'cc'  : [ 'climate change' ],
        	'cid' : [' discussions about infoboxes and to edits adding, deleting, collapsing, or removing verifiable information from infoboxes' ],
        	'covid':[ 'COVID-19, broadly construed' ],
        	'fg'  : [ 'Falun Gong' ],
        	'gc'  : [ 'governmental regulation of firearm ownership; the social, historical and political context of such regulation; and the people and organizations associated with these issues' ],
        	'gg'  : [ 'gender-related disputes or controversies or people associated with them' ],
        	'gmo' : [ 'genetically modified organisms, commercially produced agricultural chemicals and the companies that produce them, broadly construed' ],
        	'horn' :[ 'the Horn of Africa (defined as including Ethiopia, Somalia, Eritrea, Djibouti, and adjoining areas if involved in related disputes)' ],
        	'ipa' : [ 'India, Pakistan, and Afghanistan' ],
        	'irp' : [ 'post-1978 Iranian politics' ],
        	'kurd' :[ 'the topics of Kurds and Kurdistan, broadly construed' ],
        	'ps'  : [ 'pseudoscience and fringe science' ],
        	'r-i' : [ 'the intersection of race/ethnicity and human abilities and behaviour' ],
        	'sl'  : [ 'Sri Lanka' ],
        	'tt'  : [ 'The Troubles' ]
        };
    }
      
    mw.util.addPortletLink(
        'p-tb', //target tab - personal links
        '#', //link URL
        'CT Alert', //link text
        'pt-alert', //id of new button
        'Alert about contentious topics', //hover text
    );
   
    $('#pt-alert').click(function (){
        var Window = new Morebits.simpleWindow(600, 500);
        Window.setTitle('Alert about contentious topics');
        Window.setScriptName('alertHelper');
        Window.display();
        var form = new Morebits.quickForm(publish);
        var first = form.append({
            type: 'radio',
            name: 'first',
            label: 'First time? ({{Contentious topics/log|' + mw.config.get('wgTitle') + '}})'
        });
        var categories = form.append({
            type: 'select',
            name: 'topic',
            label: 'Select topic:'
        });
        for (var key in alertHelperConfig.topicList) {
    		if (alertHelperConfig.topicList.hasOwnProperty(key)) {
				categories.append({
            		type: 'option',
            		label: alertHelperConfig.topicList[key][0],
            		value: key
        		});
    		}
		}
        form.append({ type: 'submit' });
        var result = form.render();
        Window.setContent(result);
        Window.display();

        function publish(e){
            var form = e.target;
            var topic = form.topic.value;
            
            Morebits.simpleWindow.setButtonsEnabled(false);
            Morebits.status.init(form);
			Morebits.wiki.actionCompleted.notice = 'Alerted!';
            
            var alertPage = new Morebits.wiki.page(mw.config.get('wgPageName'), 'Processing');
            alertPage.setFollowRedirect(true);
            alertPage.load(function() {
                var text = alertPage.getPageText();
                if (first == false) {
                	text += '\n' + '== Contentious topic alert == \n' + '{{subst:alert|' + topic + '}} ~~~~';
                } else {
                	text += '\n' + '{{subst:alert/first|' + topic + '}} ~~~~';
                }
                alertPage.setEditSummary('Contentious topic alert: ' + topic + ' (using [[User:CanonNi/Scripts/AlertHelper|AlertHelper]])');
                alertPage.setPageText(text);
                alertPage.save();
            });
        }
    });
});

// </nowiki>
// [[Category:Wikipedia scripts]]