Jump to content

User:Evano1van/CustomAdvisor.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>
// Check javascript regexes at http://www.cyber-reality.com/regexy.html
// Dependency http://en.wikipedia.org/wiki/User:Cameltrader/Advisor
// Read http://en.wikipedia.org/wiki/User:Cameltrader/Advisor#Contributors
// To add more India specific rules that you want, please ping me at [[User_talk:Evano1van]]

var ct = ct || {};
if(typeof ct.rules=='undefined'){
ct.rules = [];
}
ct.rules.push(function (s) {
    var suggestions = [];
    var replacement_dicts = [];

    replacement_dicts.push({
             'pattern' : /(((\s)*(-|—|–)?(\&#124;)?(\s)*(The\s)?Time(s)* of India(\s)*)?\|(\s)*publisher(\s)*=(\s)*(articles\.)?timesofindia\.indiatimes\.com(\s)*)/gi,
             'replacement':'|publisher=The Times of India',
             'description':'Replace ToI publisher'
              }
    );
    replacement_dicts.push({
             'pattern' : /((\s)*(-|—|–)(\s)*((Tamil)|(Kannada)|(Telugu)|(Malayalam|Hindi))(\s)*Movie News(\s))*\|(\s)*publisher(\s)*=(\s)*Indiaglitz\.com/gi,
             'replacement':'|publisher=IndiaGlitz',
             'description':'Replace IndiaGlitz publisher'
              }
    );
    replacement_dicts.push({
             'pattern' : /((\s)*(-|—|–)*(\s)*((Tamil)|(Kannada)|(Telugu)|(Malayalam|Hindi))(\s)*Movie News(\s))*\|(\s)*publisher(\s)*=(\s)*Behindwoods\.com/gi,
             'replacement':'|publisher=Behindwoods',
             'description':'Replace Behindwoods publisher'
              }
    );
    replacement_dicts.push({
             'pattern' : /(\s)*\|(\s)*publisher(\s)*=(\s)*(S|s)ify\.com/gi,
             'replacement':'|publisher=Sify',
             'description':'Replace Sify publisher'
              }
    );
    replacement_dicts.push({
             'pattern' : /(\s)*\|date=(\s)*\|/g,
             'replacement':null,
             'description':'Try adding date if its in cite template'
              }
    );
    replacement_dicts.push({
             'pattern' : /(\&(#124;)?(-|—|–)?(\s)*DNA(\s)*India)?(\s)*\|(\s)*publisher(\s)*=(\s)*(www\.)?dnaindia\.com(\s)*/gi,
             'replacement':'|publisher=DNA India',
             'description':'Replace DNA publisher'
              }
    );
    replacement_dicts.push({
             'pattern' : /((\s)*(-|—|–)*(\s)*ibnlive(\s)*)?\|(\s)*publisher(\s)*=(\s)*Ibnlive\.in\.com/gi,
             'replacement':'|publisher=CNN IBN',
             'description':'Replace CNNIBN publisher'
              }
    );
    replacement_dicts.push({
             'pattern' : /((\s)*(-|—|–)*(\s)*Rediff\.com(\s)*Movies(\s)*)?\|(\s)*publisher(\s)*=(\s)*(Rediff\.com)(\s)*/gi,
             'replacement':'|publisher=Rediff',
             'description':'Replace Rediff publisher'
              }
    );
    replacement_dicts.push({
             'pattern' : /(\s)*(-|—|–)*(\s)*cinema(\s)preview(\s)stills(\s)gallery(\s)trailer(\s)video(\s)clips(\s)showtimes/gi,
             'replacement':'',
             'description':'Remove junk'
              }
    );
    replacement_dicts.push({
             'pattern' : /((\s)*(-|—|–)*(\s)*India Today)?(\s)*\|(\s)*publisher(\s)*=(\s)*Indiatoday\.intoday\.in(\s)*/gi,
             'replacement':'|publisher=India Today',
             'description':'Replace India Today publisher'
              }
    );
    replacement_dicts.push({
             'pattern' : /((\s)*(-|—|–)*(\s)*Outlook)?(\s)*\|(\s)*publisher(\s)*=(\s)*news\.outlookindia\.com(\s)*/gi,
             'replacement':'|publisher=[[Outlook (magazine)|Outlook]]',
             'description':'Replace Outlook publisher'
              }
    );
    replacement_dicts.push({
             'pattern' : /(\|author=)?TNN(\s)(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(\s)[1-3]?[0-9]\,(\s)(1|2)(0|9|1){2}[0-9]\,(\s)[0-2][0-9]\.[0-9]{2}(A|P)M(\s)IST/g,
             'replacement':'|agency=TNN',
             'description':'Replace TNN agency'
              }
    );
    replacement_dicts.push({
             'pattern' : /((\s)*(-|—|–)*(\s)*OneIndia Entertainment(\s))?\|(\s)*publisher(\s)*=(\s)*Entertainment\.oneindia\.in/gi,
             'replacement':'|publisher=OneIndia',
             'description':'Replace One India publisher'
              }
    );
    for (var j = 0; j < replacement_dicts.length; j++) {
      var re = replacement_dicts[j]['pattern']
      var matches = ct.getAllMatches(re, s);
      for (var i = 0; i < matches.length; i++) {
         var match = matches[i];
         suggestions.push({
                start: match.start,
                end: match.end,
                replacement: replacement_dicts[j]['replacement'],
                description: replacement_dicts[j]['description'],
                name: 'Cite-fix'
         });
      }
     }
     return suggestions;
 });

ct.rules.push(function (s) {
    var re = /({{lang\-(as|bn|gu|hi|kn|ml|mr|ne|or|pa|sa|sd|ta|te|ur)(\s)*\|[^}]*}})/g;
    var matches = ct.getAllMatches(re, s);
    var suggestions = [];
     for (var i = 0; i < matches.length; i++) {
        var match = matches[i];
        suggestions.push({
                start: match.start,
                end: match.end,
                replacement: "",
                name: "LANG-TAG",
                description: "INDIC SCRIPT. Remove if found in lead of India articles."
        });
    }
     return suggestions;
 });
// </nowiki>