Skip to content

Instantly share code, notes, and snippets.

@MarvNC
Last active November 15, 2023 03:48
Show Gist options
  • Save MarvNC/5f5bbae05c0c1a639cdba291b5c3ee96 to your computer and use it in GitHub Desktop.
Save MarvNC/5f5bbae05c0c1a639cdba291b5c3ee96 to your computer and use it in GitHub Desktop.
ttu Reader Improvements for Android Devices

ttu Reader improvements

Use Volume Keys with Kiwi Browser and ttu Reader on Android

  • Install Key Mapper and follow all the instructions within the app to set it up with Shizuku (needs adb debugging).

  • Add a trigger for a volume key, set the action to input KEYCODE_PAGE_UP or KEYCODE_PAGE_DOWN as you prefer, and set the constraint to be that it only works when Kiwi Browser is in the foreground. Repeat for the other volume key.

    Example Image: click to expand

    image

  • Open ttu reader in Kiwi Browser and use the volume keys to navigate.

Use Boox Side Buttons to Navigate ttu Reader

  • Enable the option that uses hardware keys to swipe vertically.

    • Long press on Kiwi Browser, press optimize, and you can adjust the settings as such:
    Example Image: click to expand

    image

  • Install a userscript manager like Violentmonkey and click here to install: swipe-to-pageturn.user.js.

  • Open ttu reader in Kiwi Browser and use the side buttons to navigate.

  • You can access the menu option to change the swipe direction by tapping the three dots and going to the Violentmonkey submenu, where there will be the swipe direction option.

  • If you're having issues with Yomichan being triggered on swipes, please check the instructions on setting up Yomichan for mobile here.

Restore ttu Reader Fullscreen Mode on Tap

Note

This is no longer necessary as Kiwi Browser supports extensions in PWAs now so you can just install ttu as a pwa and won't have to deal with the address bar.

One of the most annoying things about using ttu Reader on Kiwi Browser is that it exits fullscreen when the screen is turned off. While there is no way to automatically restore fullscreen, this userscript makes it so any tap on the page will restore fullscreen.

Install Userscript (I recommend using Violentmonkey).

// ==UserScript==
// @name Fix Android Keycodes for ttu
// @namespace https://github.com/MarvNC
// @match https://reader.ttsu.app/b*
// @grant none
// @version 1.0
// @author Marv
// @description Fixes the keycode event for android so you can use volume buttons with kiwi on Android.
// ==/UserScript==
document.addEventListener('keydown', (event) => {
// Check if the code is blank
if (event.code === '') {
const fixedEvent = new KeyboardEvent('keydown', { code: event.key });
// thanks RenjiXD
window.dispatchEvent(fixedEvent);
}
});
// ==UserScript==
// @name Fullscreen ttu reader
// @namespace https://github.com/MarvNC
// @match https://reader.ttsu.app/b
// @grant none
// @version 1.0
// @author -
// @description Fullscreens ttu reader on any tap.
// ==/UserScript==
document.documentElement.addEventListener('click', () => {
document.documentElement.webkitRequestFullscreen();
});
// ==UserScript==
// @name ttu Swipes to Pageturns
// @namespace https://github.com/MarvNC
// @match https://reader.ttsu.app/b*
// @grant none
// @version 1.2
// @author Marv
// @description Detects swipes and turns pages in ttu reader
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// ==/UserScript==
const swipeSensitivity = 50;
(function () {
let startY;
let currentlyMoving = false;
let reverseDirection = GM_getValue('reverseDirection', false);
document.addEventListener('touchstart', function (event) {
startY = event.touches[0].clientY;
currentlyMoving = true;
});
document.addEventListener('touchmove', function (event) {
if (!currentlyMoving) {
return;
}
let endY = event.changedTouches[0].clientY;
// If the swipe is too short, ignore it
if (Math.abs(startY - endY) < swipeSensitivity) {
return;
}
let swipeUp = startY > endY;
if (reverseDirection) {
swipeUp = !swipeUp;
}
sendKey(swipeUp ? 'PageUp' : 'PageDown');
currentlyMoving = false;
});
document.addEventListener('touchend', function (event) {
currentlyMoving = false;
});
// Add menu command to reverse direction
GM_registerMenuCommand('Reverse direction', function () {
reverseDirection = !reverseDirection;
GM_setValue('reverseDirection', reverseDirection);
alert(
`Swipe direction is now ${
reverseDirection ? 'reversed' : 'normal'
}: swiping up will go to the ${reverseDirection ? 'next' : 'previous'} page.`
);
});
})();
function sendKey(key) {
const event = new KeyboardEvent('keydown', { code: key });
window.dispatchEvent(event);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment