// ==UserScript==
// @name Multi-Page Viewer Plus
// @namespace Multi-Page Viewer Plus
// @description This script provides a slideshow option for e-hentai.org galleries in MPV (Multi-Page Viewer) and minor improvements.
// @author ku7ab3@gmail.com
// @include https://e*hentai.org/mpv/*
// @version 1.1
// @grant none
// @require https://code.jquery.com/jquery-3.2.1.min.js
// @updateURL https://raw.githubusercontent.com/Kutabe/dotfiles/master/exhentai/mpvp.user.js
// @downloadURL https://raw.githubusercontent.com/Kutabe/dotfiles/master/exhentai/mpvp.user.js
// ==/UserScript==
/*
About:
mpvp (multi page viewer plus) is a dumb user script to add slideshow
option to your MPV so now you can use both of your hands.
License:
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to
*/
// hide old panel
$("#bar3").hide();
// remove thumbnail scrollbar
$("#pane_thumbs").css("overflow", "hidden");
$("#pane_outer").css("background-color", "#34353B");
// add new panel
$("#bar1").append(`
`);
// variables
var playtimer = null;
var fadetimer = null;
var page = currentPage();
var pages = $('.mimg').length;
// INITIAL STATES:
// fullscreen button
if (isFullScreen()) {
$("#fsbtn").prop("title", "Exit fullscreen");
$("#fsreq").hide();
$("#fsexit").show();
} else {
$("#fsbtn").prop("title", "Go fullscreen");
$("#fsexit").hide();
$("#fsreq").show();
}
// thumbnail button
if ($("#bar3 img:nth-child(6)").css("opacity") == 1) {
$("#thumbbtn").prop("title", "Hide thumbnails")
$("#thumbshow").hide();
$("#thumbhide").show();
} else {
$("#thumbbtn").prop("title", "Show thumbnails")
$("#thumbhide").hide();
$("#thumbshow").show();
}
// image alignment
if ($("#bar3 img:nth-child(3)").css("opacity") == 1) {
$("#alsd").prop("onclick", null);
$("#acsd").css("opacity", "0.5");
$("#acsf").css("opacity", "0.5");
} else if ($("#bar3 img:nth-child(4)").css("opacity") == 1) {
$("#acsd").prop("onclick", null);
$("#acsf").css("opacity", "0.5");
$("#alsd").css("opacity", "0.5");
} else if ($("#bar3 img:nth-child(5)").css("opacity") == 1) {
$("#acsf").prop("onclick", null);
$("#acsd").css("opacity", "0.5");
$("#alsd").css("opacity", "0.5");
}
// prev/next image
if (page < 2) {
$("#prevbtn").css("opacity", "0.5");
} else {
$("#prevbtn").css("opacity", "1");
}
if (page >= pages) {
$("#nextbtn").css("opacity", "0.5");
} else {
$("#nextbtn").css("opacity", "1");
}
// is fullscreen enabled?
function isFullScreen() {
return document.fullScreen || document.webkitIsFullScreen || document.mozFullScreen || document.msIsFullScreen;
}
// reset timer on hashchange
$(window).bind("hashchange", function() {
if (playtimer) {
clearTimeout(playtimer);
playtimer = null;
play();
}
});
// hide bar on timeout
$("body").mousemove(function() {
clearTimeout(fadetimer);
$("#mpvp").fadeIn(200);
fadetimer = setTimeout(function() {
if (!$('#mpvp:hover').length != 0) {
$("#mpvp").fadeOut(200);
}
}, 1000);
});
// take actions on fullscreen change
$(document).on('fullscreenchange webkitfullscreenchange mozfullscreenchange msfullscreenchange', function(e) {
if (isFullScreen()) {
$("#fsbtn").prop("title", "Exit fullscreen");
$("#fsreq").hide();
$("#fsexit").show();
} else {
$("#fsbtn").prop("title", "Go fullscreen");
$("#fsexit").hide();
$("#fsreq").show();
}
});
// fullscreen request
$("#fsreq").on("click", function() {
$("#fsreq").hide();
$("#fsexit").show();
var a = document.body.requestFullScreen || document.body.webkitRequestFullScreen || document.body.mozRequestFullScreen || document.body.msRequestFullScreen
if (a) {
a.call(document.body);
}
});
// exit fullscreen
$("#fsexit").on("click", function() {
$("#fsexit").hide();
$("#fsreq").show();
var a = document.exitFullscreen || document.webkitExitFullscreen || document.mozCancelFullScreen || document.msExitFullscreen
if (a) {
a.call(document);
}
});
// play/pause
function currentPage() {
page = parseInt(window.location.hash.substring(5))
if (isNaN(page)) {
page = 1
}
return page
}
function play() {
$("#playpausebox").prop("title", "Pause slideshow");
$("#playbtn").hide();
$("#pausebtn").show();
playtimer = setTimeout(function() {
if (page >= pages) {
pause();
if (confirm("End of archive.\nStart over?")) {
window.location.hash = "#page1";
page = 1;
play();
}
} else {
goNextSlide();
play();
}
}, 1000 * parseInt($("#deltatime").val()));
}
function pause() {
$("#playpausebox").prop("title", "Start slideshow");
$("#pausebtn").hide();
$("#playbtn").show();
if (playtimer) {
clearTimeout(playtimer);
playtimer = null;
}
}
function goNextSlide() {
var nextPage = currentPage();
nextPage++;
page = nextPage;
window.location.hash = "#page" + page;
if (page < 2) {
$("#prevbtn").css("opacity", "0.5");
} else {
$("#prevbtn").css("opacity", "1");
}
if (page >= pages) {
$("#nextbtn").css("opacity", "0.5");
} else {
$("#nextbtn").css("opacity", "1");
}
}
function goPrevSlide() {
var prevPage = currentPage();
prevPage--;
page = prevPage;
window.location.hash = "#page" + page;
if (page < 2) {
$("#prevbtn").css("opacity", "0.5");
} else {
$("#prevbtn").css("opacity", "1");
}
if (page >= pages) {
$("#nextbtn").css("opacity", "0.5");
} else {
$("#nextbtn").css("opacity", "1");
}
}
$("#playbtn").on("click", function() {
play();
});
$("#pausebtn").on("click", function() {
pause();
});
$("#prevbtn").on("click", function() {
if ($("#prevbtn").css("opacity") == "0.5") return;
goPrevSlide();
});
$("#nextbtn").on("click", function() {
if ($("#nextbtn").css("opacity") == "0.5") return;
goNextSlide();
});
// mousewheel events to set delta time
$('#deltatimebox').on('DOMMouseScroll mousewheel', function(event) {
if (event.originalEvent.detail > 0 || event.originalEvent.wheelDelta < 0) {
// mouse wheel down
var a = parseInt($("#deltatime").val());
if (a > 2) {
a--;
$("#deltatime").val(a);
if (playtimer) {
clearTimeout(playtimer);
playtimer = null;
play();
}
}
} else {
// mouse wheel up
var a = parseInt($("#deltatime").val());
if (a < 30) {
a++;
$("#deltatime").val(a);
if (playtimer) {
clearTimeout(playtimer);
playtimer = null;
play();
}
}
}
// prevent page fom scrolling
return false;
});
// decrease delta time
$("#deltaminus").on("click", function() {
var a = parseInt($("#deltatime").val());
if (a > 2) {
a--;
$("#deltatime").val(a);
if (playtimer) {
clearTimeout(playtimer);
playtimer = null;
play();
}
}
});
// increase delta time
$("#deltaplus").on("click", function() {
var a = parseInt($("#deltatime").val());
if (a < 30) {
a++;
$("#deltatime").val(a);
if (playtimer) {
clearTimeout(playtimer);
playtimer = null;
play();
}
}
});