MediaWiki:Gadget-edittools-velikost.js

Iz Wikinavedka, proste zbirke navedkov in pregovorov

Opomba: Da bodo spremembe prišle do veljave, po objavi izpraznite predpomnilnik svojega brskalnika.

  • Firefox/Safari: Držite Shift in kliknite Znova naloži (Reload) ali pritisnite Ctrl + Shift + R ali Ctrl + R (⌘ + R v sistemu Mac)
  • Internet Explorer/Edge: Držite Ctrl + F5 in kliknite Osveži (Refresh) ali pritisnite Ctrl + F5
  • Google Chrome: Pritisnite Ctrl + Shift + R (⌘ + Shift + R v sistemu Mac)
  • Opera: Pritisnite Ctrl + F5.
 jQuery(document).ready(function() {

   if (document.URL.indexOf("action=edit") == -1 && document.URL.indexOf("action=submit") == -1) { return; }
   var wikitext;
   {
     var editbox = document.getElementById('wpTextbox1');
     if (editbox == null) { return; }
     wikitext = editbox.defaultValue;
   }

   function outputWeight1000(outputtext) {
     var box = document.getElementById('editpage-specialchars');
     if(!box) { return; }
     var box2 = document.createElement("div");
     box2.appendChild(document.createTextNode(outputtext));
     box2.setAttribute("id", "weight1000");
     box.appendChild(box2);
   }

   function getCommentLength(article) {
     var comment_len   = 0;
     var comment_last  = 0;
     var comment_first = article.indexOf('<!--', comment_last);
     while (comment_first > -1) {
       comment_last = article.indexOf('-->', comment_first);
         if (comment_last == -1) {
           comment_last = comment_first + 4;
         }
       comment_len += (comment_last - comment_first) - 4;
       comment_first = article.indexOf('<!--', comment_last);
     }
     return comment_len;
   }

   var raw_article_size = wikitext.length;
   var comment_len      = getCommentLength(wikitext);
   var article_size     = (raw_article_size - comment_len);

   var lang_weight      = 1.2;

   var weighted_size    = Math.round(article_size * lang_weight * 10)/10;

   outputWeight1000("Velikost: " + (weighted_size) + " (število znakov: " + (article_size) + ")");

 });