AniDB Year FilterAll productions that occurred before the variable year_min are hidden.
To-Do:Allow the number of rows to bet set by incrementally parsing the anime list table from additional pages.
| // ==UserScript== | |
| // @name AniDB Year Filter | |
| // @namespace http://techexplored.io | |
| // @version 0.1 | |
| // @description Removes rows from the anime show lists based on year. | |
| // @match http://anidb.net/perl-bin/animedb.pl?type.web=1* | |
| // @copyright 2014+, Peter MacDonald | |
| // @run-at document-start | |
| // ==/UserScript== | |
| var year_min = 2004; | |
| var xhr, | |
| returnStatus = 200, | |
| pages = 0, | |
| junctionTable = document.createElement('table'), | |
| junctionBody = document.createElement('tbody'), | |
| junctionStyle = document.createElement('style'), | |
| style = '.animelist2 * { box-sizing: border-box; } table.animelist2 { width: 100%; border-collapse: collapse; } table.animelist2 tr { display: table-row; } table.animelist2 td { display: table-cell; } table.animelist2 tr, table.animelist2 td { height: 70px; } table.animelist2 a { display: block; } table.animelist2 td.awards { display: none !important; } table.animelist2 td.weight { display: none !important; } table.animelist2 td.thumb a, table.animelist2 td.thumb img { display: block; width: 85px; } table.animelist2 .g_odd { background-color: #34394D; }'; | |
| junctionTable.setAttribute('class', 'animelist2'); | |
| junctionStyle.type = 'text/css'; | |
| junctionStyle.appendChild(document.createTextNode(style)); | |
| junctionTable.appendChild(junctionStyle); | |
| function process() { | |
| if (xhr.status == 200 && xhr.readyState == 4) { | |
| pages++; | |
| var parser = new DOMParser(), | |
| response = xhr.responseText, | |
| target = response.substr(response.indexOf('<table class="animelist">'), response.lastIndexOf('</table>')+8); | |
| target = target.substr(0, target.lastIndexOf('</table>')+8); | |
| var doc = parser.parseFromString(target, "text/xml"), | |
| ptable = doc.children[0], | |
| prows = ptable.children; | |
| for(var i=1; i < ptable.children.length; i++) { | |
| var clonedNode = ptable.children[i].cloneNode(true); | |
| junctionBody.appendChild(clonedNode); | |
| } | |
| } | |
| } | |
| var UTIL = { | |
| loadEvents: function() { | |
| var tableParent = document.getElementsByClassName('animelist_table')[0], | |
| animeTable = tableParent.children[0], | |
| arrDeleteRows = []; | |
| //junctionBody.appendChild(animeTable.getElementsByClassName('header')[0]); | |
| var pageNum = 1; | |
| // while(returnStatus == 200) { | |
| while(pageNum < 2) { | |
| xhr = new XMLHttpRequest(); | |
| xhr.onreadystatechange = process; | |
| xhr.open("GET", "http://anidb.net/perl-bin/animedb.pl?type.web=1&type.unknown=1&type.tvspecial=1&type.tvseries=1&type.ova=1&type.other=1&type.musicvideo=1&type.movie=1&show=lexicon&orderby.name=1.1&orderby.average=0.2&noalias=1&lexiconid=140&do.update=update&cleanurl=1&cat.minweight=100&airing=0&page=" + pageNum, false); | |
| xhr.send(); | |
| pageNum++; | |
| } | |
| for(var i=1; i < junctionBody.children.length; i++) { | |
| var row = junctionBody.children[i], | |
| date = row.lastChild.previousSibling.innerHTML, | |
| splitDate = date.split('.')[2]; | |
| if(splitDate < year_min) { | |
| arrDeleteRows.push(i); | |
| } | |
| } | |
| var deleteRowsCount = arrDeleteRows.length; | |
| for(var i=deleteRowsCount-1; i >= 0; i--) { | |
| var rowToRemove = junctionBody.children[arrDeleteRows[i]]; | |
| rowToRemove.parentNode.removeChild(rowToRemove); | |
| } | |
| for(var i=1; i < junctionBody.children.length; i++) { | |
| if(i%2 != 0) { | |
| junctionBody.children[i].setAttribute('class', 'g_odd'); | |
| } else { | |
| junctionBody.children[i].removeAttribute('class'); | |
| } | |
| } | |
| animeTable.parentNode.removeChild(animeTable); | |
| junctionTable.appendChild(junctionBody); | |
| tableParent.appendChild(junctionTable); | |
| } | |
| }; | |
| document.onreadystatechange = function() { | |
| var state = document.readyState; | |
| if (state === 'complete') { | |
| UTIL.loadEvents(); | |
| } | |
| }; |
AniDB Year FilterAll productions that occurred before the variable year_min are hidden.
To-Do:Allow the number of rows to bet set by incrementally parsing the anime list table from additional pages.