hide douban feeds

I dont care.

当前为 2014-08-27 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name       hide douban feeds
// @namespace  http://houkanshan.github.io/
// @version    0.3
// @description  I dont care.
// @match      http://www.douban.com/*
// @require     http://libs.baidu.com/underscore/1.3.3/underscore-min.js
// @require    http://libs.baidu.com/jquery/2.0.3/jquery.min.js
// @copyright  2012+, You
// ==/UserScript==

var blockedCSS = (function () {/*
.blocked-feed .mod {
  height: 54px;
  overflow: hidden;
  opacity: 0.1;
  margin-bottom: 14px;
}
.blocked-feed .action-block:before {
  content: '+';
}
.action-block:before {
  content: '×';
  float: right;
  color: #eee;
  margin-top: -16px;
  height: 12px;
  width: 12px;
  line-height: 12px;
  vertical-align: middle;
  display: block;
  cursor: pointer;
}
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
insertCSS(blockedCSS)


var blockWords = ['月饼', '发工资']
var blockIdKey = 'blocked_feed_ids'
var blockIds = localStorage[blockIdKey] ? JSON.parse(localStorage[blockIdKey]) : []

var listSel = '.stream-items'
var feedSel = '[data-sid]'
var idBlockedSel = '[data-sid="' + blockIds.join('"], [data-sid="') + '"]'

console.info(idBlockedSel)

var list = $(listSel)
var feeds = list.find(feedSel)
var blockedFeeds = list.find(idBlockedSel)


blockedFeeds.add(feeds.filter(function(i, el) {
  return _.some(blockWords, function(word) {
    return el.textContent.match(word)
  })
}))

blockedFeeds.addClass('blocked-feed')
feeds.prepend('<span class="action-block">')

list.on('click', '.action-block', function(e){
  var el = $(e.currentTarget)
  var feed = el.closest(feedSel)
  var sid = feed.data('sid')
  var hasBlocked = feed.is('.blocked-feed')

  if (hasBlocked) {
    blockIds = _.without(blockIds, sid)
    localStorage[blockIdKey] = JSON.stringify(blockIds)
    feed.removeClass('blocked-feed')
  } else {
    blockIds.push(sid)
    localStorage[blockIdKey] = JSON.stringify(blockIds)
    feed.addClass('blocked-feed')
  }
})

list.on('click', '.blocked-feed', function(e) {
  var el = $(e.currentTarget)
  el.removeClass('blocked-feed')
})



function insertCSS(css, options) {

    var elem = document.createElement('style');
    elem.setAttribute('type', 'text/css');

    if ('textContent' in elem) {
      elem.textContent = css;
    } else {
      elem.styleSheet.cssText = css;
    }

    var head = document.getElementsByTagName('head')[0];
    if (options && options.prepend) {
        head.insertBefore(elem, head.childNodes[0]);
    } else {
        head.appendChild(elem);
    }
};