Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Count Diff
- // @version 1
- // @grant none
- // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
- // ==/UserScript==
- $(document).ready(function(){
- var wordCount = 0;
- if ($('td.diff-addedline').length > 0) {
- $('td.diff-addedline').each(function( index ) {
- if ($(this).find("ins").length > 0) {
- $(this).find("ins").each(function() {
- wordCount += countWords(this);
- });
- } else {
- wordCount += countWords(this);
- }
- });
- alert("Number of added words: "+wordCount);
- }
- });
- function countWords(el) {
- var cont = $(el).html();
- cont = cont.replace(/<[^>]*>/g," ");
- cont = cont.replace(/\s+/g, ' ');
- cont = cont.trim();
- var n = cont.split(" ").length;
- return n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement