// ==UserScript==
// @name Batoto MyFollows
// @description Enhancements for batoto.net
// @include http://www.batoto.net/*
// @include http://www.mangaupdates.com/series.html?*
// @include https://www.mangaupdates.com/series.html?*
// @version 14.04.11.01
// @namespace https://greasyfork.org/users/168
// ==/UserScript==
// <@updateURL http://userscripts.org/scripts/source/184671.meta.js
// <@installURL http://userscripts.org/scripts/source/184671.user.js
// <@downloadURL http://userscripts.org/scripts/source/184671.user.js
var timeI = Date.now();
//Batoto site
function myfollows(table) {
var rows = document.getElementsByClassName("ipb_table chapters_list")[table].getElementsByTagName("a");
for (var current, e = 1; e < rows.length ; e = e + 2) {
current = rows[e].textContent.trim();
if (follows.indexOf(current) != -1) {
row = document.getElementById("comic_search_results").getElementsByClassName("ipb_table chapters_list")[table].getElementsByTagName("tr")[e];
rows[e].insertBefore(icon.cloneNode(), rows[e].firstChild.nextSibling);
found.push(row);
if (document.getElementById("exclude_follows").checked) {
row.hide();
row.nextSibling.nextSibling.hide();
}
}
}
page = page + 1;
try {
document.getElementById("show_more_row").getElementsByTagName("input")[0].onclick = function() {
update_comic_search('comic_search_form', true, page - 1);
var checking = setInterval(function() {
if (document.getElementById("ajax_loading").style.display == "none") {
clearInterval(checking);
myfollows(table+1);
}
}, 50);
};
} catch(er){}
}
function show_follows_info(zEvent) {
var t = this;
var divid = this.getAttribute("cId");
if ($('cId_'+divid).visible()) {
Effect.SlideUp('cId_'+divid, {duration: 0.2});
} else if ($('cId_'+divid).innerHTML != "") {
Effect.SlideDown('cId_'+divid, {duration: 0.2});
} else {
new Ajax.Updater('cId_'+divid, ipb.vars['home_url']+'/comic_pop', {
parameters: { id: divid },
method: 'get',
onSuccess: function () {
if (blood) {
setTimeout(function() {
if (t.parentNode.parentNode.getAttribute("class") == "row1") {
$('cId_'+divid).firstChild.nextSibling.style.background = "rgba(0,0,0,0.8)";
}
else {
$('cId_'+divid).firstChild.nextSibling.style.background = "white";
}
},25);
}
setTimeout(function() {
new Effect.SlideDown('cId_'+divid, {duration: 0.2});
},50);
}
});
}
}
function defineIcon() {
icon = document.createElement("img");
icon.src = "http://www.batoto.net/forums/public/style_images/master/star.png";
icon.alt = "fIcon";
icon.title = "Following";
icon.style.verticalAlign = "top";
}
var url = document.URL;
if (url.indexOf("http://www.batoto.net/") !=-1) {
//Check if using Blood Theme
if (ipb.vars['img_url'] == "http://www.batoto.net/forums/public/style_images/Blood_Images") {
var blood = true;
// if you are, hides top bar when scrolling down, if you don't like it just delete this line below
document.getElementById("branding").style.position = "absolute";
}
//HomePage: Add icon next to comic titles meaning they are in your follows's list
if (url == "http://www.batoto.net/" || url.indexOf("http://www.batoto.net/?p=") == 0) {
var row,
comic,
icon,
rowI = 1,
rowSl = "comic_row_1",
follows = JSON.parse(localStorage.follow_list);
defineIcon();
while (document.getElementById(rowSl)) {
row = document.getElementById(rowSl).parentNode;
comic = row.getElementsByTagName("a")[1].textContent;
if (follows.indexOf(comic) != -1) {
row.insertBefore(icon.cloneNode(),row.childNodes[2]);
}
rowI = rowI + 1;
rowSl = "comic_row_" + rowI.toString();
}
}
//Follows Page: updates the local follows's list
else if (url.indexOf("http://www.batoto.net/follows_comics") == 0) {
var rows = Array.prototype.slice.call(document.getElementById("content").getElementsByTagName("strong"),0),
follows = [],
info = document.createElement("a"),
tRow = document.createElement("tr"),
rows0 = Array.prototype.slice.call(document.getElementsByClassName("ipb_table")[0].getElementsByTagName("tr"),0),
tbody = rows0[0].parentNode,
comicId;
rows.pop();rows.pop();rows.pop();
info.href = "javascript:void(0)";
info.innerHTML = "<img src=\"/forums/public/style_images/master/information.png\" style=\"margin-right:4px\">";
tRow.innerHTML = "<td colspan=\"2\" style=\"padding:0px;border-bottom:none\"><div style=\"display:none\"></div></td>";
rows.forEach(function(e,i) {
comicId=e.parentNode.href.substring(e.parentNode.href.lastIndexOf("r")+1);
follows.push(e.textContent);
e.parentNode.parentNode.previousSibling.previousSibling.setAttribute("rowspan","3");
tRow.firstChild.firstChild.id = "cId_" + comicId;
tbody.insertBefore(tRow.cloneNode(true),rows0[i*2+1]);
info.setAttribute("cId",comicId);
e.parentNode.parentNode.insertBefore(info.cloneNode(true),e.parentNode);
e.parentNode.previousSibling.addEventListener("click", show_follows_info, false);
});
localStorage.follow_list = JSON.stringify(follows);
//Shows you when it's done updating
var upList = document.createElement("span");
upList.textContent = "You are following " + follows.length + " comics!";
upList.style.fontSize = "65%";
upList.style.paddingLeft = "8px";
upList.style.color = "LightSeaGreen";
document.getElementById("content").getElementsByClassName("maintitle")[0].appendChild(upList);
}
//Button in comic page that links you to the page in MangaUpdates through Google's I'm feeling lucky option
else if (url.indexOf("http://www.batoto.net/comic/_/comics/") == 0) {
var ddr = document.getElementById("content").children[3].children[0].children[12].children[0],
link = document.createElement("a"),
icon = document.createElement("img");
link.href = "http://www.google.com/webhp?#q=" + ddr.innerHTML.trim().replace(/\W/g,"+") + "&sitesearch=mangaupdates.com/series.html?&btnI=I&nfpr=1";
icon.src = "http://www.batoto.net/forums/public/style_images/Sylo/search_icon.png";
icon.alt = "";
icon.title = "Search in MangaUpdates";
icon.style.backgroundColor = "CadetBlue";
icon.style.padding = "3px";
icon.style.marginRight = "3px";
icon.style.verticalAlign = "5%";
link.appendChild(icon);
ddr.innerHTML= ddr.outerHTML.slice(0,30) + link.outerHTML + ddr.outerHTML.slice(30);
}
//Add icon next to comic title and option to hide them if they are in your follows's list
else if (url.indexOf("http://www.batoto.net/search") == 0) {
var row,
icon,
page = url.search("&p="),
found = [],
follows = JSON.parse(localStorage.follow_list);
if ( page!= -1) {
page = parseInt(url.slice(page+3),10);
}
else {
page = 1;
}
defineIcon();
var optionButton = document.createElement("tr");
optionButton.innerHTML = "<td style=\"text-align: right; font-weight: bold;\">Include MyFollows:</td><td style=\"text-align: left; vertical-align: top; padding: 8px 0;\"><label><input id=\"include_follows\" type=\"radio\" name=\"follows\" value=\"y\" checked=\"checked\"> Yes</label><label><input id=\"exclude_follows\" type=\"radio\" style=\"margin-left: 4px\" name=\"follows\" value=\"n\"> No</label></td>";
document.getElementById("advanced_options").getElementsByTagName("tbody")[0].insertBefore(optionButton, document.getElementById("advanced_options").getElementsByTagName("tr")[6]);
document.getElementById("include_follows").onclick = function() {
$(found).each(function(element){
element.show();}
);
};
document.getElementById("exclude_follows").onclick = function() {
$(found).each(function(element){
element.hide();
element.nextSibling.nextSibling.hide();}
);
};
document.getElementById("comic_search_form").getElementsByTagName("input")[1].onclick = document.getElementById("advanced_options").getElementsByTagName("tr")[9].getElementsByTagName("input")[0].onclick = function() {
var checking = setInterval(function() {
if (document.getElementById("ajax_loading").style.display == "none") {
clearInterval(checking);
page = 1;
myfollows(0);
}
}, 50);
};
myfollows(0);
}
}
// MangaUpdates site: add button to search the comic in batoto, doesn't work always as the titles sometimes don't match
else {
var comic = document.getElementById("listContainer").parentNode.getElementsByTagName("span")[0];
if (comic.textContent.indexOf("(Novel)") == -1) {
var link = document.createElement("a"),
icon = document.createElement("img");
try {
var author = document.getElementById("listContainer").parentNode.children[3].children[0].children[16].getElementsByTagName("a")[0].textContent;
author = author.substr(0,author.indexOf(" "));
link.href = " http://www.batoto.net/search?name=" + comic.textContent + "&name_cond=s&artist_name=" + author + "&artist_name_cond=c";
}
catch (e) {
link.href = " http://www.batoto.net/search?name=" + comic.textContent;
}
icon.src = "http://www.batoto.net/forums/public/style_images/Sylo/search_icon.png";
icon.alt = "";
icon.title = "Search in Batoto";
icon.style.backgroundColor = "SlateGray";
icon.style.padding = "3px";
icon.style.marginRight = "3px";
icon.style.verticalAlign = "0%";
link.appendChild(icon);
comic.parentNode.insertBefore(link,comic);
}
}
var timeF = Date.now()-timeI;
console.log("Took " + timeF + "ms to run MyFollows script");