Greasy Fork

DontSetupLazy

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

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

// ==UserScript==
// @name        DontSetupLazy
// @namespace   https://github.com/segabito/
// @description 動画のロードを待たずに初期化する
// @include     http://www.nicovideo.jp/watch/*
// @version     0.1
// @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.PlayerApp && window.WatchJsApi) {
    addStyle('#nicoSpotAdAds >*:nth-child(2) { display: none !imortant; position: fixed; top: -999px; }');

    window.setTimeout(function() {
      var watchInfoModel = WatchApp.ns.model.WatchInfoModel.getInstance();
      if (!watchInfoModel.initialized) {
        console.log('%cinitialize Immediately', 'background: lightgreen;');
        WatchApp.ns.EmbeddedWatchData.run_ = WatchApp.ns.EmbeddedWatchData.run;
        WatchApp.ns.EmbeddedWatchData.run = function() {
          $('#nicoSpotAdAds >*:nth-child(2)').remove();
        };
        window.setTimeout(function() {
          console.time('initialize Immediately');
          WatchApp.ns.EmbeddedWatchData.run_(JSON.parse($('#configDataContainer').html()));
          console.timeEnd('initialize Immediately');
        }, 0);
      }
    }, 0);
  }
 })();