Skip to content

Instantly share code, notes, and snippets.

@drojf
Forked from akrolsmir/batoto_follows_to_mangadex.js
Last active January 25, 2018 01:13
Show Gist options
  • Save drojf/6c37a3cc058517b5f91a334fa7a79d7e to your computer and use it in GitHub Desktop.
Save drojf/6c37a3cc058517b5f91a334fa7a79d7e to your computer and use it in GitHub Desktop.
Import your manga from Batoto to Mangadex
/*
Instructions:
1) Go to https://mangadex.com on Chrome.
2) Open the Chrome console (Ctrl+Shift+J on Windows).
3) Copy + paste the code in this file.
If using JSON export, use (A).
If using raw CSV Text (copy from a text editor), use (B).
If using exel/newline separated values, use (C).
4) Hit Enter.
The script should take care of leading/trailing whitespace for you, so don't worry about it.
(A) If you are using the JSON export, copy and paste the raw json text output into the "` `" section
Example:
var user_csv_json_text = `
[{"like_id":"8554eb3bd19282d080c8d1dd0501ac1c","comic_id":"16752","title":"", .... }]
`;
(B) TODO: If you are using CSV export, copy and paste the raw csv output from either a text editor or Exel (both will work)
Example:
var user_csv_json_text = `
like_id,comic_id,title,image,url
d7a64fb869b8c196e14ade63532a87a4,5002,,,
e4cc3722bcf06d4d9bf467363f7eb100,8880,,,
`;
(C) TODO: Manual Exel/CSV Column Copy (One number per line. Do not use commas). Copy a column into the "` `" section
Example:
var user_csv_json_text = `
1970
1987
16281
`;
*/
//------------------------------------------ USER TO MAKE CHANGES HERE ---------------------------------
//TODO: User to copy format of their choice inside the "` `". Blank rows are acceptable.
var user_csv_json_text = `
`;
//------------------------------------------ Do not change below this point ----------------------------
if(!user_csv_json_text.trim())
{
alert("You need to edit the script and paste something in user_csv_json_text between the ` `");
}
else if(user_csv_json_text.trim()[0] == '[')
{
console.log('>>> using JSON method');
var batoto_ids = JSON.parse(user_csv_json_text).map(z => z['comic_id']);
}
else if(user_csv_json_text.indexOf('like_id') != -1)
{
console.log('>>> Using CSV method');
var splitted=user_csv_json_text.trim().split('\n');
var batoto_ids = new Array();
for( i = 1 ; i < splitted.length ; i++ ) //Skip the first line with column names
{
var arr2 = splitted[ i ].split(/[\s,]+/).filter(Boolean) ;
if (!isNaN(arr2[1].trim())) {
batoto_ids.push(arr2[1].trim());
}
}
batoto_ids=batoto_ids.map(Number);
}
else
{
console.log('>>> Using Newline method');
var batoto_ids = user_csv_json_text.split('\n').filter(x => x.trim()).map(Number);
}
var successes = [], failures = [];
function follow_manga(index) {
// Follow this manga by making an AJAX call.
var id = batoto_ids[index];
$.ajax({
url: `/ajax/actions.ajax.php?function=manga_follow&id=${id}`,
type: "GET",
success: () => {successes.push(id)},
error: () => {failures.push(id)},
})
.then(() => {
console.log(`Processed #${index + 1}: ${id}.`);
// Wait 300ms, then follow the next manga in the list.
index++;
if (0 < index && index < batoto_ids.length) {
setTimeout(() => {follow_manga(index)}, 300);
} else {
// Finished processing all manga.
console.log(`Followed ${successes}. Could not follow ${failures}.`);
}
});
}
follow_manga(0);
@MammothJerk
Copy link

i got this error while trying to use the JSON method
>>> using JSON method VM193:1 Uncaught SyntaxError: Unexpected token A in JSON at position 13062 at JSON.parse (<anonymous>) at <anonymous>:52:27 (anonymous) @ VM192:52

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment