Greasy Fork

DontSetupLazy

動画のロードを待たずに初期化する

当前为 2014-10-16 提交的版本,查看 最新版本

// ==UserScript==
// @name        DontSetupLazy
// @namespace   https://github.com/segabito/
// @description 動画のロードを待たずに初期化する
// @include     http://www.nicovideo.jp/watch/*
// @version     0.2
// @grant       none
// ==/UserScript==

(function() {
  var addStyle = function(styles, id) {
    var elm = document.createElement('style');
    window.setTimeout(function() {
      elm.type = 'text/css';
      if (id) { elm.id = id; }

      var text = styles.toString();
      text = document.createTextNode(text);
      elm.appendChild(text);
      var head = document.getElementsByTagName('head');
      head = head[0];
      head.appendChild(elm);
    }, 0);
    return elm;
  };

  if (window.WatchJsApi) {
    addStyle('#nicoSpotAdAds >*:nth-child(2) { display: none !imortant; position: fixed; top: -999px; }');
    require(['EmbeddedWatchData', 'watchapp/model/WatchInfoModel'], function(EmbeddedWatchData, WatchInfoModel) {
      var watchInfoModel = WatchInfoModel.getInstance();
      if (!watchInfoModel.initialized) {
        console.log('%cinitialize Immediately', 'background: lightgreen;');
        EmbeddedWatchData.run_ = EmbeddedWatchData.run;
        EmbeddedWatchData.run = function() {
          $('#nicoSpotAdAds >*:nth-child(2)').remove();
        };
        window.setTimeout(function() {
          console.time('initialize Immediately');
          EmbeddedWatchData.run_(
            JSON.parse($('#configDataContainer').html()),
            JSON.parse($('#watchAPIDataContainer').text())
          );
          console.timeEnd('initialize Immediately');
        }, 0);
      }
    });
  }
 })();