It's a script for the site AnimeTake that adds a tag in parenthesis to indicate if the episode is a filler or not.
目前為
// ==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 + ')';
}
}
}
});