Skip to content

Instantly share code, notes, and snippets.

@j4c3
Last active January 4, 2022 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j4c3/fa5b983cd36afce56e35c1dd52059334 to your computer and use it in GitHub Desktop.
Save j4c3/fa5b983cd36afce56e35c1dd52059334 to your computer and use it in GitHub Desktop.
Ubooquity Currently Reading
// Anonymous "self-invoking" function
(function() {
var startingTime = new Date().getTime();
// Load the script
var script = document.createElement("SCRIPT");
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js';
script.type = 'text/javascript';
document.getElementsByTagName("head")[0].appendChild(script);
// Poll for jQuery to come into existance
var checkReady = function(callback) {
if (window.jQuery) {
callback(jQuery);
} else {
window.setTimeout(function() { checkReady(callback); }, 20);
}
};
// Start polling...
checkReady(function($) {
//////////////////////////////////
//Add currently reading condition to comic
//////////////////////////////////
$('.thumb a img').each(function(){
raw_src = $(this).attr('src')
page_num = '0';
//sort comics from folders
if (raw_src.search("folder") >= 0){
//console.log("raw_src: "+raw_src);
} else {
//extract Comic ID
thing = $(this);
src = $(this).attr('src'); //console.log("source: "+src);
$(this).closest('.thumb').append('');
var comicid = src.split('/'); //console.log("Comic ID: "+comicid[2]);
//get comic meta from server
json_url = window.location.origin+"/user-api/bookmark?docId="+comicid[2]; //console.log("url: "+json_url);
$.getJSON( json_url, function() {
//console.log( "json_url success" );
}).done(function( data ) {
current_this = thing;
if (data != null){
var items = [];
var c_id = '';
var c_pages = '';
var page_num = '';
$.each( data, function( key, val ) {
if (key == 'docId'){ c_id = val;}
if (key == 'mark'){ page_num = val;}
});
if (page_num != '0'){
// get total pages from server
content_url = window.location.origin+"/comicdetails/"+c_id; //console.log("url: "+content_url);
$.get( content_url, function() {
//console.log( "content_url success" );
}).done(function( data ) {
details = $('<details>').append($.parseHTML(data));
size_div = $('#details_size', details).html();
c_pages = size_div.match(/\d+/)[0];
thumb = $("img[src*='"+c_id+"']").closest('.thumb');
thumb.css({ 'display' : 'flex',
'justify-content' : 'flex-end',
'flex-direction' : 'column'});
base_thumb_content = thumb.html();
// set reading if page_num < total_pages
if (page_num >= (c_pages - 1)) {
progress_percent = 100;
progress_string = "Completed";
} else {
progress_percent = ((page_num/c_pages) * 100);
page_int = Number(page_num);
progress_string = (page_int++) + " of " + c_pages;
}
modified_thumb_content = "<div class='progress-container' style='position: absolute; z-index: 9; width: -webkit-fill-available; background: rgba(00, 00, 00, 0.6)' >" +
"<div class='progress_percent' style='bottom: 0px; left: 0px; background: rgba(50, 200, 50, 0.7); width: " + progress_percent + "%;'>&nbsp;</div>" +
"<div class='progress_string' style='bottom: 0px; left: 0px; position: absolute; color: #FFF; width: 100%; height: 100%;'>" + progress_string + "</div>" +
"</div>" + base_thumb_content;
console.log(modified_thumb_content);
thumb.html(modified_thumb_content);
});
}
//console.log("page_num "+page_num);
}
}).fail(function(){});
}
//console.log("triggered");
});
});
})();
// end Anonymous "self-invoking" function
@TheSKArkitekt
Copy link

HI, is there any chance to modify this script for ebooks (epub)? I have been looking for API specifications, but cannot find anything... I am using Material theme (as you do, i recon)..
Thanks in advance!

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