User:PC-XT/Advisor

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
Advisor
Description Provides suggestions of minor improvements to articles while editing
Author Cameltrader, updated by PC-XT
Status updated
Updated August 2, 2014; 3 years ago (2014-08-02)
Source User:PC-XT/Advisor.js (original: User:Cameltrader/Advisor.js)

This script is based on User:Cameltrader/Advisor.js, which has documentation at User:Cameltrader/Advisor.

Usage[edit]

I made this for my own usage, but I don't mind if others use it. This tool only makes suggestions. It is not intelligent enough to tell if the suggestions are actually appropriate. As with any tool, editors are responsible to make this determination for each individual fix before applying it, and cleaning up as necessary before saving the page. If a fix doesn't work as you think it should, please report it on the talk page. Installation instructions are at User:Cameltrader/Advisor. These tell how to install the original. If you don't have problems using that one, you probably won't need this fork. If you do care, you can switch to this fork by changing

importScript('User:Cameltrader/Advisor.js');

to

importScript('User:PC-XT/Advisor.js'); // [[User:PC-XT/Advisor]]

in your personal js. (The added wikilink lets me check WhatLinksHere to know how others are using this before I make a change.) The differences between this fork and the original are listed below.

Problem? Report it here[edit]

Make report

I changed this fork to link here in edit summaries, instead of to User:Cameltrader#Advisor, so you would know to please report any script errors here, instead of trying to contact that missing user. This way, I can try to fix the problem. Cheers!

Difference from original[edit]

I originally forked this to add custom rules. Then, I made further changes.

Summary of all changes: (actual diff from original)

  • Allow custom rules and settings in ct object before calling the script
  • Add ct.noscroll option for those of us who have trouble with the custom scrolling feature
  • {{Please check ISBN}} tagging of incorrect ISBN checksums which were only detected in the original
  • edit summary tweaks: no semicolon after sections, link to this page as explained above
  • add ct.noDefaultRules to allow entirely custom rulesets, even outside of wikicode

I don't expect to make any more changes unless something comes up, which does happen.

Custom rules[edit]

Custom rules and other options are controlled by the ct object, named after User:Cameltrader. This object has the following properties that may be set before the line installing the script:

ct={ // start ct object for Advisor.js fork
  noscroll:false, // change to true if your browser's built-in scrolling interferes with the script's scrolling when clicking on a suggestion
  rules:[ // begin custom rules
    // A ``rule'' is a JavaScript function that accepts a string as a
    // parameter (the wikitext of the page being edited) and returns an array
    // of ``suggestion'' objects.

    function (s) { // example suggestion to replace "int he" with "in the"
      var matches = ct.getAllMatches(/int he/g, s);
      // getAllMatches() is a custom utility function, you are not required to use it

      var suggestions = [];
      // A ``suggestion'' object must have the following properties:
      //     * start---the 0-based inclusive index of the first character to be replaced
      //     * end---analogous to start, but exclusive
      //     * (optional) replacement---the proposed wikitext, if any
      //     * name---this is what appears at the top of the page
      //     * description---used as a tooltip for the name of the suggestion
      //     * (optional) help---an HTML fragment as a string, it will appear in a yellow
      //                         box when a suggestion is double-clicked

      for (var i = 0; i < matches.length; i++) {
        var match = matches[i];
        suggestions.push({
                start: match.start,
                end: match.end,
                replacement: "in the",
                name: "spelling-example",
                description: "You probably meant ``in the'' instead of ``int he''."
        });
      }
      return suggestions;
    },
    function(s){ // example of function to provide a hint, without a suggested fix
      var matches=ct.getAllMatches( /* regular expression to search for */ ,s);
      var suggestions=[];
      for ( var i = 0 ; i < matches.length ; i++ ) suggestions.push( {
        start:       matches[i].start,
        end:         matches[i].end,
        name:        "example",
        description: "example description",
        help:        "example help text <i>can use HTML</i>", //optional
      } );
      return suggestions;
    }
  ] // end rules
}; // end ct object
importScript('User:PC-XT/Advisor.js'); // [[User:PC-XT/Advisor]]

This is similar to the method explained at User:Cameltrader/Advisor#Contributors.