WFcount Code

Version 1.4

javascript:(function(){
var version = "v1.4";
var timeFormat = 0;
var br = '<br>';
if(location.href.indexOf('workflowy.com') == -1) {
  return;
}
var projectSelected = document.title.replace(/ - WorkFlowy$/, '');
var bullets = document.getElementsByClassName("bullet").length;
var parents = document.getElementsByClassName("parent").length;
var children = bullets - parents;
var tags = document.getElementsByClassName("project selected")[0].getElementsByClassName(
  "contentTag");
var completed = document.getElementsByClassName("project selected")[0]
  .getElementsByClassName("done").length;
if(document.getElementsByClassName("showCompleted").length == 0) {
  var completed = 'Hidden';
}
var finalCount = '';
var totalHours = '';
if(tags.length > 0) {
  var i;
  var tagList = [];
  for(i = 0; i < tags.length; i++) {
    tagList.push(tags[i].textContent.toLowerCase());
  }
  tagList.sort();
  var tagCount = {};
  tagList.forEach(function(x) {
    tagCount[x] = (tagCount[x] || 0) + 1;
  });
  for(var tagTitle in tagCount) {
    finalCount += tagTitle + " = " + tagCount[tagTitle] + br;
  }
  var tagNames = finalCount.match(/=/g).length;
  var timeTags = finalCount.match(/(#)(\d+)(m|h)( = )(\d+)/g);
  if(timeTags !== null) {
    var final = 0;
    for(i = 0; i < timeTags.length; i++) {
      findTime = /(#)(\d+)(m|h)( = )(\d+)/;
      total = (timeTags[i].match(findTime)[2]) * (timeTags[i].match(
        findTime)[5]);
      if(timeTags[i].indexOf("h") !== -1) {
        total = total * 60;
      }
      final += total;
    }
    var totalHours = br + 'Total Time = ' + Math.floor(final / 60) +
      'h ' + final % 60 + 'm';
    if(timeFormat !== 0) {
      var totalHours = br + 'Total Hours = ' + (Math.round((final /
        60) * 100) / 100);
    }
  }
} else {
  var tagNames = 0;
}
var WFcount = window.open("", version,
  "width=320, height=600,left=20,top=144,scrollbars=yes,toolbar=no"
);
WFcount.document.write('<span style="font-family:monospace;"><h3>' +
  projectSelected + '</h3>Parents = ' + parents + br +
  'Children = ' + children + br + 'Completed = ' + completed + br +
  br + 'Tag Count = ' + tags.length + br + 'Tag Names = ' +
  tagNames + totalHours + br + br + finalCount + br + '</span>');
})();
//v1.4 added time tag calculations
//v1.3 restructure for tag calculations
//v1.2: Fixed display bug when no tags are present
//v1.1: Tags with colons now display properly
//v1.0: Initial Release
Advertisements