hide douban feeds

I dont care.

当前为 2014-09-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name hide douban feeds
  3. // @namespace http://houkanshan.github.io/
  4. // @version 0.5.1
  5. // @description I dont care.
  6. // @match http://www.douban.com/*
  7. // @require http://libs.baidu.com/underscore/1.3.3/underscore-min.js
  8. // @require http://libs.baidu.com/jquery/2.0.3/jquery.min.js
  9. // @copyright 2014+, Houkanshan
  10. // ==/UserScript==
  11. //
  12. // GistID: 3a48bf702e115e1ae966
  13.  
  14. var blockedCSS = (function () {/*
  15. .blocked-feed .mod {
  16. height: 54px;
  17. overflow: hidden;
  18. opacity: 0.2;
  19. margin-bottom: 14px;
  20. }
  21. .blocked-feed .action-block:before {
  22. content: '+';
  23. }
  24. .action-block:before {
  25. content: '×';
  26. float: right;
  27. color: #ebebeb;
  28. margin-top: -16px;
  29. height: 12px;
  30. width: 12px;
  31. line-height: 12px;
  32. vertical-align: middle;
  33. display: block;
  34. cursor: pointer;
  35. }
  36. */}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
  37. insertCSS(blockedCSS)
  38.  
  39.  
  40. var blockWords = ['月饼', '发工资', '某荚', '贵荚', '豌豆荚', '要参加线上活动', '宋冬野']
  41. var blockIdKey = 'blocked_feed_ids'
  42. var blockIds = localStorage[blockIdKey] ? JSON.parse(localStorage[blockIdKey]) : []
  43.  
  44. var listSel = '.stream-items'
  45. var feedSel = '[data-sid]'
  46. var idBlockedSel = '[data-sid="' + blockIds.join('"], [data-sid="') + '"]'
  47.  
  48. var list = $(listSel)
  49. var feeds = list.find(feedSel)
  50. var blockedFeeds = list.find(idBlockedSel)
  51.  
  52.  
  53. blockedFeeds = blockedFeeds.add(feeds.filter(function(i, el) {
  54. return _.some(blockWords, function(word) {
  55. return el.textContent.match(word)
  56. })
  57. }))
  58.  
  59. blockedFeeds.addClass('blocked-feed')
  60. feeds.prepend('<span class="action-block">')
  61.  
  62. list.on('click', '.action-block', function(e){
  63. var el = $(e.currentTarget)
  64. var feed = el.closest(feedSel)
  65. var sid = feed.data('sid')
  66. var hasBlocked = feed.is('.blocked-feed')
  67.  
  68. if (hasBlocked) {
  69. blockIds = _.without(blockIds, sid)
  70. localStorage[blockIdKey] = JSON.stringify(blockIds)
  71. feed.removeClass('blocked-feed')
  72. } else {
  73. blockIds.push(sid)
  74. localStorage[blockIdKey] = JSON.stringify(blockIds)
  75. feed.addClass('blocked-feed')
  76. }
  77. })
  78.  
  79. list.on('click', '.blocked-feed', function(e) {
  80. var el = $(e.currentTarget)
  81. el.removeClass('blocked-feed')
  82. })
  83.  
  84.  
  85.  
  86. function insertCSS(css, options) {
  87.  
  88. var elem = document.createElement('style');
  89. elem.setAttribute('type', 'text/css');
  90.  
  91. if ('textContent' in elem) {
  92. elem.textContent = css;
  93. } else {
  94. elem.styleSheet.cssText = css;
  95. }
  96.  
  97. var head = document.getElementsByTagName('head')[0];
  98. if (options && options.prepend) {
  99. head.insertBefore(elem, head.childNodes[0]);
  100. } else {
  101. head.appendChild(elem);
  102. }
  103. };