Filler or not

It's a script for the site AnimeTake that adds a tag in parenthesis to indicate if the episode is a filler or not.

当前为 2015-03-13 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Filler or not
// @author      One Shade
// @namespace   http://lifenanime.blogspot.ca/
// @include     http://www.animetake.com/*
// @description It's a script for the site AnimeTake that adds a tag in parenthesis to indicate if the episode is a filler or not.
// @version     1
// @grant       GM_xmlhttpRequest
// ==/UserScript==
function findFirstDescendant(parent, tagname)
{
  ancestor = document.getElementById(parent);
  var descendants = ancestor.getElementsByTagName(tagname);
  if (descendants.length)
  return descendants[0];
  return null;
}
var header = findFirstDescendant('content', 'h1');
//Get anime name from tags and cut it
var animeName = header.innerHTML;
var firstToCut = animeName.indexOf('>') + 1;
var lastToCut = animeName.indexOf('</a>');
animeName = animeName.substr(firstToCut, lastToCut - firstToCut);
//Seperate the anime name and number
var urlName = animeName.split(' Episode ') [0];
var episodeNum = animeName.split(' Episode ') [1];
//Prepare url name for web format
urlName = urlName.replace(/ /g, '-');
urlName = urlName.replace(/!/g, '');
urlName = urlName.replace(/Shippuuden/g, 'shippuden');
urlName = urlName.toLowerCase();
//Open request for page source code
var filler = false;
var sourceCode = '';
var url = 'http://www.fillerguide.com/episode-list/' + urlName + '/';
var ret = GM_xmlhttpRequest({
  method: 'GET',
  url: url,
  onload: function (response) {
    sourceCode = response.responseText;
    //If the anime does not have a page for fillers
    var indexName = sourceCode.indexOf('column first');
    if (indexName != - 1)
    {
      //Skim through code to get the status of filler or not for the episode number
      var episodeNum = animeName.split(' Episode ') [1];
      firstToCut = sourceCode.indexOf('tablesWrapper');
      lastToCut = sourceCode.indexOf('footer-divider');
      var sourceCode = sourceCode.substr(firstToCut, lastToCut - firstToCut);
      episodeNum = episodeNum.split(' Final') [0];
      episodeNum = episodeNum.split('-') [0];
      lastToCut = sourceCode.indexOf("r"+episodeNum);
      firstToCut = sourceCode.lastIndexOf("column first", lastToCut);
      sourceCode = sourceCode.substr(firstToCut, lastToCut - firstToCut);
      //If filler mark as true
      if (sourceCode.indexOf('filler') != - 1)
      {
        filler = true;
      }
      var textToAdd = '';
      if (filler == true)
      {
        textToAdd = 'Filler';
      }
      //Add the tag in parenthesis

      if (textToAdd != '')
      {
        header.innerHTML += ' ' + '(' + textToAdd + ')';
      }
    }
  }
});