Nico User Ads Hider

ニコニコ動画からニコニ広告による動画への装飾を削除

Fra 24.12.2015. Se den seneste versjonen.

// ==UserScript==
// @name        Nico User Ads Hider
// @namespace   http://userscripts.org/users/121129
// @description ニコニコ動画からニコニ広告による動画への装飾を削除
// @match       http://www.nicovideo.jp/*
// @version     4
// @grant       none
// @run-at      document-idle
// ==/UserScript==

;(function() {
  'use strict'
  var observeForAllPage = function() {
    var isAdClassAdded = function(mutationRecord) {
      var r = mutationRecord
      return r.attributeName === 'class'
          && r.target.className.includes('uadlevel')
    }
    var containsClass = function(target) {
      return function(classItem) {
        return target.classList.contains(classItem)
      }
    }
    var isBalloonShown = function(mutationRecord) {
      var r = mutationRecord
      return r.attributeName === 'style'
          && r.target.style.display !== 'none'
          && ['balloon', 'recent', 'active'].every(containsClass(r.target))
    }
    new MutationObserver(function(mutationRecords) {
      for (var r of mutationRecords) {
        if (isAdClassAdded(r)) {
          r.target.className = r.oldValue
        } else if (isBalloonShown(r)) {
          r.target.style.display = 'none'
        }
      }
    }).observe(document.body, {
      attributes: true,
      subtree: true,
      attributeOldValue: true,
      attributeFilter: ['class', 'style'],
    })
  }
  var isListRankingPage = function() {
    var p = location.pathname
    return p.startsWith('/ranking/') && p !== '/ranking/'
  }
  var observeForListRankingPage = function() {
    var isVideoCommentsShown = function(target) {
      return target.hasAttribute('data-video-comments')
          && target.style.display !== 'none'
    }
    new MutationObserver(function(mutationRecords) {
      for (var r of mutationRecords) {
        if (isVideoCommentsShown(r.target)) {
          r.target.style.display = 'none'
        }
      }
    }).observe(document.body, {
      attributes: true,
      subtree: true,
      attributeFilter: ['style'],
    })
  }

  observeForAllPage()
  if (isListRankingPage()) observeForListRankingPage()
})()