ব্যবহারকারী:Bodhisattwa/common.js/typoscan.js

উইকিসংকলন থেকে
টীকা: সংরক্ষণ করার পর, পরিবর্তনসমূহ তৎক্ষণাৎ নাও দেখাতে পারে। আপনার ব্রাউজারের ক্যাশ কিভাবে এড়াবেন তা জানতে এখানে ক্লিক করুন।
  • ফায়ারফক্স / সাফারি: Shift ধরে রাখা অবস্থায়পুনঃলোড করুন-এ ক্লিক করুন, অথবা Ctrl-F5 বা Ctrl-R (ম্যাক-এ ⌘-R) চাপুন
  • গুগল ক্রোম: Ctrl-Shift-R (ম্যাক-এ ⌘-Shift-R) চাপুন
  • ইন্টারনেট এক্সপ্লোরার: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 চাপুন
  • অপেরা: মেনু → ব্যবস্থাপনাসমূহ-এ যান (ম্যাকে অপেরা → পছন্দসমূহ) এবং এরপর গোপনীয়তা ও সুরক্ষা → ব্রাউজিং-এর তথ্য পরিষ্কার করুন → ক্যাশে করা ছবি ও ফাইলগুলি

অন্যান্য ব্রাউজার সম্পর্কে বিশদ নির্দেশাবলীর জন্য, উইকিপিডিয়া:আপনার ক্যাশে বাইপাস করুন দেখুন।

//  

// main namespace excluded version

var typoFuse;  // overriden by actions.limit
 
function HighlightTyposUnder( node, actions ){
    if( typoFuse >= 0 && node ){
    if( node.nodeType == 3 /* TEXT_NODE */ ){
      for( var I = 0; I < actions.patterns.length; I++ ){
        var pattern = actions.patterns[ I ];
 
        if( node.nodeValue.match( pattern ) ){
          if( node.parentNode ){
            node.parentNode.innerHTML = node.parentNode.innerHTML.replace( pattern, '<span style="' + actions.styling + '">$&</span>' );
            typoFuse--;
          }
        }
      }
    }
 
    if( node.childNodes.length ){
      for( var subnode=0; subnode < node.childNodes.length; subnode++ ){
        if( node.childNodes[ subnode ].getAttribute ){
          if( !/pagenumber/.test( node.childNodes[ subnode ].getAttribute( "class" ) ) ){
            HighlightTyposUnder( node.childNodes[ subnode ], actions );
          }
        } else {
          HighlightTyposUnder( node.childNodes[ subnode ], actions );
        }
      }
    }
  }
}
 
function HighlightTyposLike( actions ){
  self.typoscan = self.typoscan || { exclude: true };
 
  if( !( actions.exclude ) ){       //don't bother scanning historical, edit-in-progress or given ns pages.
 
    var content=document.getElementById('wikiPreview'); //presume currently editing page (must not touch unsafe structures like wpEditToken!)
 
    if( !content ){
                content=document.getElementById('mw-content-text'); //user not currently editing: assume safe to address entire display region
          }
 
    typoFuse = actions.limit;

    for( var N=0; N<actions.groups.length; N++ ){
      if( actions.groups[ N ].include ){
        HighlightTyposUnder( content, actions.groups[ N ] );
      }
    }
  }
}
 

self.typoscan={
  exclude:
    /(action=history|(diff|oldid|search)=|(author|category|extension|file|help|index|mediawiki|meta|module|special|talk|template|topic|user|wiki([mp]edia|source))(:|%3A))/i.test( location.href ),
  limit:
    40,
  groups: [
    {
      include:
        document.evaluate(
          "//body[contains(@class,'ns-0')]",
          document,
          null,
          XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
          null
        ).snapshotLength===0, // skip pages in main name-space...
      patterns: [
        /\\\S/g,                                    // back-slash escape?
        /;[.,:]/g,                                  // chained punctuation, semicolon-led
        /,[.,;:]/g,                                 // chained punctuation, comma-led
        /:[.,;]/g,                                  // chained punctuation, colon-led
        /\|[-+]?/g,                                 // wikicode leaking into HTML  (yes the '?' is dodgy but enlarges the match for table caption/row)
        /\s["'`;:,!?$%*()=+~]\s/g,                  // floating punctuation mark: WARNING: modern style: floating "=" OK
        /\w&/g,                                     // embedded or trailing "&"
        /&(?!c\.)\w/g,                              // leading "&" ("&c." O.K.)
        /(^|\W)[a-z]+[A-Z]+[A-Za-z]+(\W|$)/g,       // upper case embedded within lower case word
        /(^|\W)[A-Z]{2,}[a-z]+[A-Za-z]+(\W|$)/g,    // lower case embedded within upper case word
        /(^|\W)[a-zA-Z]+\d+[a-zA-Z]*(\W|$)/g,       // digit embedded within word
        /(^|\W)\d+[a-zA-Z]+\d+(\W|$)/g,             // alphabetic embedded within digits
        /(^|\W)[a-zA-Z]+ \.[a-zA-Z]+(\W|$)/g,       // period surrounded by letters
        /\^/g,                                      // standalone "^"?
        /{[[\]]}{1,}/g,                             // mis-terminated template, link or standalone "^"?
        /{[(\)}^]{1,}/g                             // plagiarised parenthesis
      ],
      styling:
        'background:LightSalmon;'
    },
// end of add
  ]
};

jQuery( document ).ready(
  HighlightTyposLike( self.typoscan )
);

//