/*jslint indent: 2 plusplus: true*/
/*global $: false, togglbutton: false*/

'use strict';

togglbutton.render('.task_item .content:not(.toggl)', {observe: true}, function (elem) {
  var link, descFunc, projectFunc, container = $('.text', elem);

  descFunc = function () {
    var desc = container.textContent;
    return desc.substr(0, desc.length - 10).replace("  ", " ").trim();
  };

  projectFunc = function () {
    var projectElem, projectLabel;
    projectElem = $('.project_link');
    if (projectElem) {
      return projectElem.textContent.trim();
    }
    projectLabel = $('.pname', elem.parentNode.parentNode);
    if (projectLabel) {
      return projectLabel.textContent.trim();
    }
  };

  link = togglbutton.createTimerLink({
    className: 'todoist',
    description: descFunc,
    projectName: projectFunc
  });

  container.insertBefore(link, container.lastChild);
});

/*jslint indent: 2 plusplus: true*/
/*global $: false, togglbutton: false*/

'use strict';

togglbutton.render('.task_item .content:not(.toggl)', {observe: true}, function (elem) {
  var link, descFunc, projectFunc, container = $('.text', elem);

  descFunc = function () {
    var clone = container.cloneNode(true),
      i = 0,
      child = null;

    while (clone.children.length > i) {
      child = clone.children[i];
      if (child.tagName === "B"
          || child.tagName === "I") {
        i++;
      } else if (child.tagName === "A") {
        if (child.classList.contains("ex_link")
            || child.getAttribute("href").indexOf("mailto:") === 0) {
          i++;
        } else {
          child.remove();
        }
      } else {
        child.remove();
      }
    }

    return clone.textContent.trim();
  };

  projectFunc = function () {
    var projectElem, projectLabel;
    projectElem = $('.project_link');
    if (projectElem) {
      return projectElem.textContent.trim();
    }
    projectLabel = $('.pname', elem.parentNode.parentNode);
    if (projectLabel) {
      return projectLabel.textContent.trim();
    }
  };

  link = togglbutton.createTimerLink({
    className: 'todoist',
    description: descFunc,
    projectName: projectFunc
  });

  container.insertBefore(link, container.lastChild);
});

Revert "Improved Todoist description text fetching"
Revert "Improved Todoist description text fetching"

This reverts commit c923a871b60ed04771052910ede9513a9f6e5afe.
