# nlフィルタ定義(文字コード判定用なのでこの行は削除しないこと)
# 17/06/01

#----------------------------------------------------------------------------------------
[Script]
Name = MutationObserverHooks (ニコレポ)
URL = www\.nicovideo\.jp/(?:my|user/\d+)(?:/?(?:\?|$)|/top)
ContentType = text/html
Append<
window.NicoCache_nl.moHooks = {
  _earlyHooks: [],
  _lazyHooks: [],
  addEarly: function(f, options) {
    if (options == null) options = {};
    this._earlyHooks.push({f: f, all: options.all});
  },
  addLazy: function(f, options) {
    this._lazyHooks.push({f: f});
  },
};
document.addEventListener("DOMContentLoaded", function(){
"use strict";

const
  invokeLazyHooks = function(item) {
    if (item._moHooksLazy) return;
    item._moHooksLazy = true;
    
    var img = item.querySelector(".log-target-video img");
    if (img == null) return;
    var m = img.src.match(/http:\/\/tn-skr.*?\/smile\?i=(\d+)/);
    if (m == null) return;
    var id = m[1];
    
    NicoCache_nl.get("/cache/info/v2?" + id, function(resp) {
      if (resp.status != 200) return;
      NicoCache_nl.moHooks._lazyHooks.forEach(function(hook) {
        hook.f(item, JSON.parse(resp.responseText)[id]);
      });
    });
  },
  invokeEarlyHooks = function(items) {
    var allItems = [], videoItems = [];
    for (var i = 0; i < items.length; i++) {
      if (items[i]._moHooksEarly) continue;
      items[i]._moHooksEarly = true;
      allItems.push(items[i]);
      if (items[i].getElementsByClassName("log-target-video").length > 0) {
        videoItems.push(items[i]);
      }
    }
    
    NicoCache_nl.moHooks._earlyHooks.forEach(function(hook) {
      if (hook.all)
        allItems.forEach(function(item) { hook.f(item) });
      else
        videoItems.forEach(function(item) { hook.f(item) });
    });
  },
  lazyObserver = function(item, lazyContainer) {
    if (item == null || lazyContainer == null) {
      console.log("lazyObserver: item == null || lazyContainer == null");
      return;
    }
    if (item._moHooksLazy) return;
    var
      F1 = function (mutation) {
        if (!lazyContainer.classList.contains("is-visible")) return;
        observer.disconnect();
        invokeLazyHooks(item);
      },
      observer = new MutationObserver(F1);
    observer.observe(lazyContainer, {attributes: true});
    F1();
  },
  timelineObserver = function(timeline) {
    var
      F1 = function (mutation) {
        var items = timeline.getElementsByClassName("NicorepoTimelineItem");
        invokeEarlyHooks(items);
        for (var i = 0; i < items.length; i++) {
          lazyObserver(items[i], items[i].querySelector(".log-target-thumbnail.LazyLoad"));
        }
      },
      observer = new MutationObserver(F1);
    observer.observe(timeline, {childList: true});
    F1();
  },
  setup = function() {
    var
      NicorepoApp = document.querySelector("#MyPageNicorepoApp, #UserPageNicorepoApp"),
      F1 = function (mutation) {
        if (NicorepoApp == null) return;
        var NicorepoTimelines = NicorepoApp.getElementsByClassName("NicorepoTimeline");
        if (NicorepoTimelines.length > 0) {
          observer.disconnect();
          timelineObserver(NicorepoTimelines[0]);
          return true;
        }
        return false;
      },
      observer = new MutationObserver(F1);
    if (!F1()) {
      observer.observe(NicorepoApp, {childList: true, subtree: true});
    }
  };
setup();

});

>

#----------------------------------------------------------------------------------------
[Script]
Name = MutationObserverHooks (タグレポ)
URL = www\.nicovideo\.jp/my/tagrepo/
ContentType = text/html
Append<
window.NicoCache_nl.moHooks = {
  _earlyHooks: [],
  _lazyHooks: [],
  addEarly: function(f, options) {
    if (options == null) options = {};
    this._earlyHooks.push({f: f, all: options.all});
  },
  addLazy: function(f, options) {
    this._lazyHooks.push({f: f});
  },
};
document.addEventListener("DOMContentLoaded", function(){
"use strict";

const
  invokeLazyHooks = function(items) {
    var videoItems = {};
    for (var i = 0; i < items.length; i++) {
      var item = items[i];
      if (item._moHooksLazy) continue;
      item._moHooksLazy = true;
      
      if (!item.classList.contains("video")) continue;
      
      var img = item.querySelector(".contents-thumbnail-box img");
      if (img == null) continue;
      var src = img.getAttribute("data-original");
      if (!src) src = img.src;
      var m = src.match(/http:\/\/tn-skr.*?\/smile\?i=(\d+)/);
      if (m == null) continue;
      var id = m[1];
      videoItems[id] = item;
    }
    if (Object.keys(videoItems).length == 0) return;
    
    NicoCache_nl.get("/cache/info/v2?" + Object.keys(videoItems).join(","), function(resp) {
      if (resp.status != 200) return;
      var json = JSON.parse(resp.responseText);
      NicoCache_nl.moHooks._lazyHooks.forEach(function(hook) {
        for (var id in videoItems) {
          hook.f(videoItems[id], json[id]);
        }
      });
    });
  },
  invokeEarlyHooks = function(items) {
    var allItems = [], videoItems = [];
    for (var i = 0; i < items.length; i++) {
      if (items[i]._moHooksEarly) continue;
      items[i]._moHooksEarly = true;
      allItems.push(items[i]);
      if (items[i].classList.contains("video")) {
        videoItems.push(items[i]);
      }
    }
    
    NicoCache_nl.moHooks._earlyHooks.forEach(function(hook) {
      if (hook.all)
        allItems.forEach(function(item) { hook.f(item) });
      else
        videoItems.forEach(function(item) { hook.f(item) });
    });
  },
  timelineObserver = function(timeline) {
    var
      F1 = function (mutation) {
        var items = timeline.querySelectorAll(".feed-item");
        invokeEarlyHooks(items);
        invokeLazyHooks(items);
      },
      observer = new MutationObserver(F1);
    observer.observe(timeline, {childList: true});
    F1();
  },
  setup = function() {
    var tagrepoTimeline = document.querySelector("#tagrepoTimeline");
    if (tagrepoTimeline == null) return;
    timelineObserver(tagrepoTimeline);
  };
setup();

});

//NicoCache_nl.moHooks.addEarly(function(item) { console.log("Early: " + item) });
//NicoCache_nl.moHooks.addLazy(function(item, info) { console.log("Lazy: " + item + JSON.stringify(info)) });

>


