User:Jellby/quick proofread.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

// From: https://en.wikisource.org/wiki/Wikisource:Scriptorium/Archives/2017-07#Marking_multiple_pages_as_proofread
// Quick proofread tool for preloaded proofread text

"use strict";

var quick_proofread = {
    
    init: function() {
        var self = this;
  
        // only care for editing in the Page: namespace
        if ( !(mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' )
            || mw.config.get( 'wgNamespaceNumber' ) !== 104 ) {
            return;
        }

        console.log("Installing Quick PR tool");

        $.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {

            // Add tool to sidebar
            pathoschild.TemplateScript.add(
                [
                    {   name: 'Quick proofread', 
                        position: 'cursor',
                        accessKey: 'o', // was 'q', but conflicts with "Special pages"
                        script: function(editor) {
                            self.mark_proofread();
                            self.save_page();
                        },
                    },
                ],
                { category:'page', forNamespaces:'page' }
            );
        }); // end ajax
    },
    
    mark_proofread: function() {
        $('span.quality3 input').click();
    },
    
    save_page: function() {
        var summary_text = "Quick proofread from offline proofreading";
        $('#wpSummary').val(summary_text);
        $('#wpSave').click();
    },
};

quick_proofread.init();