Skip to content

Instantly share code, notes, and snippets.

@InNoobWeTrust
Last active March 11, 2017 10:56
Show Gist options
  • Save InNoobWeTrust/27aaac7cfcab4aaf6effc897efacd191 to your computer and use it in GitHub Desktop.
Save InNoobWeTrust/27aaac7cfcab4aaf6effc897efacd191 to your computer and use it in GitHub Desktop.
Just a links getter for truyen.academyvn.com manga site. This is useful to reduce mobile data usage of yours. Just install termux and DroidScript, run the python script in termux to get the chapter and view it with DroidScript by the example JS script below (no backward page turning as I'm too lazy to care about looking back :] ). After running …
var links = [];
var viewIndex = 0;
var loadIndex = 0;
//Called when application is started.
function OnStart()
{
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
//Scroller
scroll = app.CreateScroller( 1.0, 1.0 );
lay.AddChild( scroll );
layScroll = app.CreateLayout( "Linear", "Center" );
scroll.AddChild( layScroll );
//Manga page, touch to go to next page (no backward at this time)
img = app.CreateImage( "/Sys/Img/Droid1.png", 1.0, 0.9 );
img.SetOnTouchUp( img_OnTouch );
layScroll.AddChild( img );
//Input block
layInput = app.CreateLayout('Linear', 'Horizontal,FillXY');
layScroll.AddChild(layInput);
//Input link to chapter here.
edt = app.CreateTextEdit( "", 0.8 );
edt.SetTextSize(9);
layInput.AddChild(edt);
//Click to get links of images
btn = app.CreateButton("Get links");
btn.SetOnTouch( btn_OnTouch );
layInput.AddChild(btn);
//Add layout to app.
app.AddLayout( lay );
dload = app.CreateDownloader( );
}
function img_OnTouch()
{
if (loadIndex == links.length - 1) {
SetImage();
}
}
function SetImage()
{
arr = String(links[viewIndex]).split('/');
path = "/sdcard/Download/academyvn/" + arr[arr.length - 1];
img.SetImage(path);
img.Update();
viewIndex++;
}
//Called when user touches our button.
function btn_OnTouch()
{
SendRequest(edt.GetText());
}
//Send an http get request.
function SendRequest( url )
{
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() { HandleReply(httpRequest); };
httpRequest.open("GET", url, true);
httpRequest.send(null);
app.ShowProgress( "Loading..." );
}
function CheckPageCount()
{
loadIndex++;
if (loadIndex < links.length - 1) {
dload.SetOnComplete(CheckPageCount);
dload.Download( links[loadIndex], '/sdcard/Download/academyvn' );
} else {
viewIndex = 0;
SetImage();
}
}
//Handle the server's reply (a json object).
function HandleReply( httpRequest )
{
if( httpRequest.readyState==4 )
{
//If we got a valid response.
if( httpRequest.status==200 )
{
el = document.createElement( 'html' );
el.innerHTML = httpRequest.responseText;
objectHTMLCollection = el.getElementsByClassName("manga-container")[0];
objectHTMLCollection = objectHTMLCollection.getElementsByTagName("img");
links = [].map.call( objectHTMLCollection, function(node){
return node.src;
});
index = 0;
app.MakeFolder('/sdcard/Download/academyvn');
dload.SetOnComplete(CheckPageCount);
dload.Download( links[0], '/sdcard/Download/academyvn' );
// app.ShowPopup( "Response: \n" + links);
}
//An error occurred
else
app.ShowPopup( "Error: \n" + httpRequest.responseText);
}
app.HideProgress();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment