Trello 只看关注

给 Trello 看板添加只看关注功能

  1. // ==UserScript==
  2. // @name Trello Only see Subscribed
  3. // @name:zh-CN Trello 只看关注
  4. // @namespace http://www.qs5.org/?trello_only_see
  5. // @version 0.1
  6. // @description Add watch-only features to Trello kanbans
  7. // @description:zh-CN 给 Trello 看板添加只看关注功能
  8. // @author ImDong
  9. // @match https://trello.com/b/*
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16.  
  17. // 添加只看关注按钮
  18. $('.board-header-btns .js-board-header-subscribed').before('<a class="board-header-btn sub-btn js-board-header-only-subscribed" href="#"><span class="icon-sm icon-subscribe board-header-btn-icon"></span><span class="board-header-btn-text u-text-underline">只看关注</span></a>');
  19.  
  20. // 绑定事件
  21. $('.board-header-btns').on('click', '.js-board-header-only-subscribed', function (e) {
  22. // 判断查看状态 为 true 则只看关注
  23. var subscribedStatus = GM_getValue('subscribedStatus', false);
  24. $(this).find('.board-header-btn-text').text(subscribedStatus ? '只看关注' : '查看全部');
  25. GM_setValue('subscribedStatus', !subscribedStatus);
  26.  
  27. if (subscribedStatus) {
  28. $('#board .js-list').each(function (key, item) {
  29. item.classList.remove('hide');
  30. });
  31. } else {
  32. $('#board .js-list').each(function (key, item) {
  33. var subscribed = $(item).find('.list-header-extras .js-list-subscribed');
  34. if (subscribed.hasClass('hide')) {
  35. item.classList.add('hide');
  36. }
  37. });
  38. }
  39. });
  40.  
  41. // 打开时页面判断
  42. if (GM_getValue('subscribedStatus', false)) {
  43. GM_setValue('subscribedStatus', false);
  44. $('.board-header-btns .js-board-header-only-subscribed').click();
  45. }
  46. })();