Trello - Thenow Trello Extend

Extend trello.com

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// Generated by CoffeeScript 1.12.2

/*
// ==UserScript==
// @name              Trello - Thenow Trello Extend
// @namespace         http://ejiasoft.com/
// @version           1.1.7
// @description       Extend trello.com
// @description:zh-CN 扩展trello.com看板的功能
// @homepageurl       https://github.com/thenow/ThenowTrelloExtend
// @author            thenow
// @run-at            document-end
// @license           MIT license
// @match             http*://*trello.com
// @match             http*://*trello.com/*
// @grant             none
// ==/UserScript==
 */

(function() {
  var addBgBtn, addBoardBtn, addImgSwitchBtn, addMemberToggleBtn, boardId, boardInit, btnClass, btnTextClass, cardLabelCss, curUrl, listCardFormat, listFormatInit, listTitleFormat, listToggle, pageRegex;

  pageRegex = {
    CardLimit: /\[\d+\]/,
    Category: /\{.+\}/g,
    User: /`\S+`/g,
    CardCount: /^\d+/,
    Number: /\d+/,
    CardNum: /^#\d+/,
    HomePage: /com[\/]$/,
    BoardId: /\/b\/.{8}\/-$/
  };

  curUrl = window.location.href;

  boardId = pageRegex.BoardId.exec(curUrl);

  cardLabelCss = "<style type=\"text/css\">\n    .card-short-id {\n        display: inline;\n        font-weight: bold;\n    }\n    .card-short-id:after {\n        content:\" \";\n    }\n    .column-list{padding:5px 15px 10px;}\n    .column-list li{height:30px;width:100%;display:block;}\n    .column-list li a{display:block;height:100%;line-height:30px;position:relative;}\n    .column-list li a:before{font-family: trellicons;content:\"\\e910\";display:block;position:absolute;right:5px;top:2px;color:#333;}\n    .column-list li a.false:before{content:\"-\";color:#DDD;}\n    .card-label.mod-card-front {\n        width: auto;\n        height: 12px;\n        line-height: 12px;\n        font-size: 12px;\n        text-shadow: none;\n        padding: 3px 6px;\n        font-family: Microsoft Yahei;\n        font-weight: 400;\n    }\n    .list-card-title .card-short-id {\n        display: inline;\n        margin-right: 4px;\n        color: #0079bf;\n    }\n    .list .list-header-num-cards {\n        display: block;\n        font-size: 12px;\n        line-height: 18px;\n    }\n</style>";

  listCardFormat = function(objCard) {
    var listCardTitle;
    return listCardTitle = objCard.find('div.list-card-details>a.list-card-title').each(function() {
      var cardCate, cardCategoryArray, cardTitle, cardUser, cardUserArray, curCardTitle, i, j, len, len1, results;
      curCardTitle = $(this);
      cardTitle = curCardTitle.html();
      cardUserArray = cardTitle.match(pageRegex.User);
      cardCategoryArray = cardTitle.match(pageRegex.Category);
      if (cardUserArray !== null) {
        for (i = 0, len = cardUserArray.length; i < len; i++) {
          cardUser = cardUserArray[i];
          cardTitle = cardTitle.replace(cardUser, "<code>" + (cardUser.substring(1, cardUser.length - 1)) + "</code>");
          curCardTitle.html(cardTitle);
        }
      }
      if (cardCategoryArray !== null) {
        results = [];
        for (j = 0, len1 = cardCategoryArray.length; j < len1; j++) {
          cardCate = cardCategoryArray[j];
          cardTitle = cardTitle.replace(cardCate, "<code style=\"color:#0f9598\">" + (cardCate.substring(1, cardCate.length - 1)) + "</code>");
          results.push(curCardTitle.html(cardTitle));
        }
        return results;
      }
    });
  };

  listTitleFormat = function(objList) {
    var cardCount, cardLimit, cardLimitInfo, curCardCountP, curListHeader, curListTitle;
    curListHeader = objList.find('div.list-header');
    curListTitle = curListHeader.find('textarea.list-header-name').val();
    cardLimitInfo = pageRegex.CardLimit.exec(curListTitle);
    if (cardLimitInfo === null) {
      return false;
    }
    curCardCountP = curListHeader.find('p.list-header-num-cards');
    cardCount = pageRegex.CardCount.exec(curCardCountP.text())[0];
    cardLimit = pageRegex.Number.exec(cardLimitInfo[0])[0];
    if (cardCount > cardLimit) {
      return objList.css('background', '#903');
    } else if (cardCount === cardLimit) {
      return objList.css('background', '#c93');
    } else {
      return objList.css('background', '#e2e4e6');
    }
  };

  listToggle = function(objList) {
    var listMenu, toggleBtn;
    if (objList.find('.toggleBtn').length > 0) {
      return;
    }
    listMenu = objList.find('div.list-header-extras');
    toggleBtn = $('<a class="toggleBtn list-header-extras-menu dark-hover"><span class="icon-sm">隐</span></a>');
    toggleBtn.click(function() {
      var base;
      base = objList.parent();
      if (base.width() === 30) {
        base.css('width', '');
      } else {
        base.width(30);
      }
      objList.find('.js-open-list-menu').toggle();
      objList.find('div.list-cards').toggle();
      return objList.find('.open-card-composer').toggle();
    });
    return listMenu.append(toggleBtn);
  };

  listFormatInit = function() {
    return $('div.list').each(function() {
      listTitleFormat($(this));
      listToggle($(this));
      return $(this).find('div.list-card').each(function() {
        return listCardFormat($(this));
      });
    });
  };

  btnClass = 'board-header-btn board-header-btn-org-name board-header-btn-without-icon';

  btnTextClass = 'board-header-btn-text';

  addBoardBtn = function(id, text, eventAction, eventName) {
    var newBtn;
    if (eventName == null) {
      eventName = 'click';
    }
    if ($("#" + id).length > 0) {
      return $("#" + id);
    }
    newBtn = $("<a id=\"" + id + "\" class=\"" + btnClass + "\"><span class=\"" + btnTextClass + "\">" + text + "</span></a>");
    $('div.board-header').append(newBtn);
    if (eventAction !== null) {
      newBtn.bind(eventName, eventAction);
    }
    return newBtn;
  };

  addImgSwitchBtn = function() {
    return addBoardBtn('btnImgSwitch', '隐藏/显示图片', function() {
      return $('div.list-card-cover').slideToggle();
    });
  };

  addBgBtn = function() {
    return addBoardBtn('setBgBtn', '设置背景图片', function() {
      var newBgUrl, oldBgUrl;
      oldBgUrl = localStorage[boardId[0]];
      newBgUrl = prompt('请输入背景图片地址', oldBgUrl);
      if (newBgUrl === oldBgUrl) {
        return;
      }
      if (newBgUrl === null || newBgUrl === '') {
        localStorage.removeItem(boardId[0]);
        $('body').css('background-image', '');
        return;
      }
      return localStorage[boardId[0]] = newBgUrl;
    });
  };

  addMemberToggleBtn = function() {
    return addBoardBtn('memberSwitchBtn', '隐藏/显示成员', function() {
      return $('div.list-card-members').slideToggle();
    });
  };

  boardInit = function() {
    var bgUrl, localBgUrl;
    if (pageRegex.HomePage.exec(curUrl) !== null) {
      return;
    }
    bgUrl = $('body').css('background-image');
    localBgUrl = localStorage[boardId[0]];
    if (localBgUrl !== void 0 && bgUrl !== localBgUrl) {
      $('body').css('background-image', "url(\"" + localBgUrl + "\")");
    }
    $('p.list-header-num-cards').show();
    listFormatInit();
    addImgSwitchBtn();
    addBgBtn();
    return addMemberToggleBtn();
  };

  $(function() {
    $('head').append(cardLabelCss);
    return setInterval((function() {
      curUrl = window.location.href;
      boardId = pageRegex.BoardId.exec(curUrl);
      return boardInit();
    }), 1000);
  });

}).call(this);