User:DannyS712/communicator.js

//Copied from User:FR30799386/communicator.js // $.when(mw.loader.using(['mediawiki.util']), $.ready).then(function {   if (mw.config.get('wgNamespaceNumber') < 0) //don't load when on special pages    {        return;    }    var music = function(clickEvent) {        if (clickEvent) {            clickEvent.preventDefault;        }        if (window.Morebits === null) {            importScript('MediaWiki:Gadget-morebits.js');        }        var page = new Morebits.wiki.page(mw.config.get('wgPageName'));        var check = page.lookupCreator(function(page) { var guy = page.getCreator; var preload; if (mw.storage.get('postCreator') !== null) { preload = mw.storage.get('postCreator'); } else { preload = '==' + mw.config.get('wgPageName') + '==\nHello, I\'m ' + mw.config.get('wgUserName') + '. I noticed that a page you started ' + mw.config.get('wgPageName') + ' is ....~'; }           $('#firstHeading').next.before('Comment: ' + '' + preload + ' ' +                ' Edit Summary: ' +                ' ' +                ' ' +                ' ' +                '  '); mw.util.addCSS(".I-empty:empty { display: none; }"); // Event listener for the text area document.getElementById("comment-dialog-field") .addEventListener("input", function {

// If the user has started a comment, ask for a                   // confirmation before closing if (this.value && !window.onbeforeunload) { window.onbeforeunload = function(e) { var txt = "You've started a comment but haven't posted it"; e.returnValue = txt; return txt; };                   } else if (!this.value && window.onbeforeunload) { window.onbeforeunload = null; }               }); // End event listener for the text area

// Event listener for the "comment" button document.getElementById("comment-dialog-button") .addEventListener("click", function {                   var sanitizedCode = document.getElementById("comment-dialog-field").value                        .replace(/&/g, "%26");                     document.getElementById("comment-dialog-button").disabled = true;                    document.getElementById('comment-dialog-summary').disabled = true;                    document.getElementById('comment-dialog-field').disabled = true;                    var text = sanitizedCode;                    mw.storage.set('postCreator', text);                    var guyedit = new Morebits.wiki.page(('User talk:' + guy));                    guyedit.setEditSummary(document.getElementById("comment-dialog-summary").value .replace(/&/g, "%26") + ' (communicator)');                   guyedit.setAppendText('\n' + text);                    guyedit.append(function { $('#comment-dailog-status').html('Done...Reloading page....'); window.onbeforeunload = null; document.location.reload; }, function { $('#comment-dialog-status').html('There was an error in publishing your comment. Please report this to the maintainer\'s talk page. If possible please add the content of the console log to your report'); document.getElementById("comment-dialog-button").disabled = false; });               }); // End event listener for the "comment" button

// Event listener for the "Preview" button document.getElementById("comment-link-preview-button") .addEventListener("click", function {                   var sanitizedCode = document.getElementById("comment-dialog-field").value                        .replace(/&/g, "%26");                         mw.storage.set('postCreator', sanitizedCode);                    $.post("https://en.wikipedia.org/api/rest_v1/transform/wikitext/to/html", "wikitext=" + sanitizedCode + "&body_only=true", function(html) { document.getElementById("comment-link-preview").innerHTML = html; });               });            document.getElementById("comment-link-cancel-button") .addEventListener("click", function {                   $('.comment-ui').remove;                    window.onbeforeunload = null;                }); });   };    mw.util.addPortletLink('p-cactions', '#', 'Communicate with creator', 'ca-communicate', 'Communicate with creator of article', '6');    $('#ca-communicate').click(music); }); //