SHARE
TWEET

CountDiff

a guest Feb 18th, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name     Count Diff
  3. // @version  1
  4. // @grant    none
  5. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
  6. // ==/UserScript==
  7.  
  8. $(document).ready(function(){
  9.  
  10.   var wordCount = 0;
  11.  
  12.  
  13.   if ($('td.diff-addedline').length > 0) {
  14.    
  15.      
  16.       $('td.diff-addedline').each(function( index ) {
  17.        
  18.        
  19.          if ($(this).find("ins").length > 0) {
  20.            
  21.            
  22.            $(this).find("ins").each(function() {
  23.              
  24.              wordCount += countWords(this);
  25.            
  26.            });
  27.    
  28.  
  29.                  } else {
  30.            
  31.           wordCount += countWords(this);
  32.          
  33.                 }
  34.      
  35.     });
  36.    
  37.      alert("Number of added words: "+wordCount);
  38.   }
  39.  
  40.  
  41.  });
  42.  
  43. function countWords(el) {
  44.  
  45.   var cont = $(el).html();
  46.   cont = cont.replace(/<[^>]*>/g," ");
  47.   cont = cont.replace(/\s+/g, ' ');
  48.   cont = cont.trim();
  49.   var n = cont.split(" ").length;
  50.  
  51.   return n;
  52.  
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top