// ==UserScript==
// @name           eknigu_downloadr
// @namespace      http://www.eknigu.com
// @description    enables downloading from eknigu without waiting
// @include        http://www.eknigu.org/info/*
// @include        http://eknigu.org/info/*
// @include        http://www.eknigu.com/info/*
// @include        http://eknigu.com/info/*
// ==/UserScript==

var eknigu_baseurl = "http://www.eknigu.org";
var eknigu_geturl = "/get/";
var eknigu_triggerurl = "/info/";

var main_style = "position:absolute; top:0px; left:0px; height:200px; width:100%; margin:0 10 0 0px; padding:10px; border-bottom: 2px solid #001133; background-color: rgba(160, 130, 130, 0.5);";

function getFileURL() {
	if(document.URL.indexOf(eknigu_triggerurl) > -1) {
		return document.URL.split(eknigu_triggerurl)[1];
	} else {
		return "";
	}
}

function addDownloadBar() {
	var myparent, div, heading, paragraph_display, form, input_hidden, input_submit, small_hint, url_file, killdiv;
	url_file = getFileURL();
	myparent = document.activeElement;
	div = document.createElement("div");
	div.setAttribute("style",main_style);
	heading = document.createElement("h2");
	heading.setAttribute("style","color:#FF0000;");
	heading.innerHTML = "Eknigu Downloadr";
	div.appendChild(heading);
	paragraph_display = document.createElement("p");
	if(url_file == "") {
		paragraph_display.innerHTML = "no file found. (missing '"+eknigu_triggerurl+"' - try to navigate to a specific book)";
	} else {
		form = document.createElement("form");
		form.setAttribute("method","post");
		form.setAttribute("action",eknigu_baseurl+eknigu_geturl+url_file);
		form.setAttribute("style","float:left;");
		input_hidden = document.createElement("input");
		input_hidden.setAttribute("type","hidden");
		input_hidden.setAttribute("name","id");
		input_hidden.setAttribute("value","go");
		input_submit = document.createElement("input");
		input_submit.setAttribute("type","submit");
		input_submit.setAttribute("value","Download:");
		input_submit.setAttribute("style","float:left; height:36px; color:#000000; background-color:rgba(200, 60, 60, 0.5);");
		form.appendChild(input_hidden);
		form.appendChild(input_submit);
		div.appendChild(form);
		paragraph_display.innerHTML = url_file;
		paragraph_display.setAttribute("style","display:inline; color:#FFFFFF;");
	}
	div.appendChild(paragraph_display);
	myparent.appendChild(div);
}

addDownloadBar();

