2019-07-18 05:27:39 +02:00
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
|
|
handleSubmitButtons();
|
2018-07-06 07:18:51 +02:00
|
|
|
|
2019-07-18 05:27:39 +02:00
|
|
|
if (!document.querySelector("body[data-disable-keyboard-shortcuts=true]")) {
|
2019-04-29 03:20:46 +02:00
|
|
|
let keyboardHandler = new KeyboardHandler();
|
2019-07-18 05:27:39 +02:00
|
|
|
keyboardHandler.on("g u", () => goToPage("unread"));
|
|
|
|
keyboardHandler.on("g b", () => goToPage("starred"));
|
|
|
|
keyboardHandler.on("g h", () => goToPage("history"));
|
|
|
|
keyboardHandler.on("g f", () => goToFeedOrFeeds());
|
|
|
|
keyboardHandler.on("g c", () => goToPage("categories"));
|
|
|
|
keyboardHandler.on("g s", () => goToPage("settings"));
|
|
|
|
keyboardHandler.on("ArrowLeft", () => goToPrevious());
|
|
|
|
keyboardHandler.on("ArrowRight", () => goToNext());
|
|
|
|
keyboardHandler.on("k", () => goToPrevious());
|
|
|
|
keyboardHandler.on("p", () => goToPrevious());
|
|
|
|
keyboardHandler.on("j", () => goToNext());
|
|
|
|
keyboardHandler.on("n", () => goToNext());
|
|
|
|
keyboardHandler.on("h", () => goToPage("previous"));
|
|
|
|
keyboardHandler.on("l", () => goToPage("next"));
|
2020-10-17 00:44:03 +02:00
|
|
|
keyboardHandler.on("z t", () => scrollToCurrentItem());
|
2019-07-18 05:27:39 +02:00
|
|
|
keyboardHandler.on("o", () => openSelectedItem());
|
|
|
|
keyboardHandler.on("v", () => openOriginalLink());
|
2019-11-29 22:48:56 +01:00
|
|
|
keyboardHandler.on("V", () => openOriginalLink(true));
|
2020-01-07 07:02:02 +01:00
|
|
|
keyboardHandler.on("c", () => openCommentLink());
|
|
|
|
keyboardHandler.on("C", () => openCommentLink(true));
|
2022-02-01 04:57:14 +01:00
|
|
|
keyboardHandler.on("m", () => handleEntryStatus("next"));
|
|
|
|
keyboardHandler.on("M", () => handleEntryStatus("previous"));
|
2019-07-18 05:27:39 +02:00
|
|
|
keyboardHandler.on("A", () => markPageAsRead());
|
|
|
|
keyboardHandler.on("s", () => handleSaveEntry());
|
|
|
|
keyboardHandler.on("d", () => handleFetchOriginalContent());
|
|
|
|
keyboardHandler.on("f", () => handleBookmark());
|
2020-10-07 03:06:12 +02:00
|
|
|
keyboardHandler.on("F", () => goToFeed());
|
2020-05-27 06:35:44 +02:00
|
|
|
keyboardHandler.on("R", () => handleRefreshAllFeeds());
|
2019-07-18 05:27:39 +02:00
|
|
|
keyboardHandler.on("?", () => showKeyboardShortcuts());
|
|
|
|
keyboardHandler.on("#", () => unsubscribeFromFeed());
|
|
|
|
keyboardHandler.on("/", (e) => setFocusToSearchInput(e));
|
2019-04-29 03:20:46 +02:00
|
|
|
keyboardHandler.on("Escape", () => ModalHandler.close());
|
|
|
|
keyboardHandler.listen();
|
|
|
|
}
|
2018-07-06 07:18:51 +02:00
|
|
|
|
2019-07-18 05:27:39 +02:00
|
|
|
let touchHandler = new TouchHandler();
|
2019-03-09 14:00:26 +01:00
|
|
|
touchHandler.listen();
|
|
|
|
|
2019-07-26 04:02:39 +02:00
|
|
|
onClick("a[data-save-entry]", (event) => handleSaveEntry(event.target));
|
|
|
|
onClick("a[data-toggle-bookmark]", (event) => handleBookmark(event.target));
|
2019-07-18 05:27:39 +02:00
|
|
|
onClick("a[data-fetch-content-entry]", () => handleFetchOriginalContent());
|
|
|
|
onClick("a[data-action=search]", (event) => setFocusToSearchInput(event));
|
2022-02-01 00:18:10 +01:00
|
|
|
onClick("a[data-action=markPageAsRead]", (event) => handleConfirmationMessage(event.target, () => markPageAsRead()));
|
2022-02-01 04:57:14 +01:00
|
|
|
onClick("a[data-toggle-status]", (event) => handleEntryStatus("next", event.target));
|
2018-07-06 07:18:51 +02:00
|
|
|
|
2019-07-18 06:07:29 +02:00
|
|
|
onClick("a[data-confirm]", (event) => handleConfirmationMessage(event.target, (url, redirectURL) => {
|
|
|
|
let request = new RequestBuilder(url);
|
|
|
|
|
|
|
|
request.withCallback(() => {
|
|
|
|
if (redirectURL) {
|
|
|
|
window.location.href = redirectURL;
|
|
|
|
} else {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
request.execute();
|
|
|
|
}));
|
2018-07-06 07:18:51 +02:00
|
|
|
|
2021-04-27 14:45:05 +02:00
|
|
|
onClick("a[data-original-link]", (event) => {
|
2022-02-01 04:57:14 +01:00
|
|
|
handleEntryStatus("next", event.target, true);
|
2021-04-27 14:45:05 +02:00
|
|
|
}, true);
|
|
|
|
onAuxClick("a[data-original-link]", (event) => {
|
|
|
|
if (event.button == 1) {
|
2022-02-01 04:57:14 +01:00
|
|
|
handleEntryStatus("next", event.target, true);
|
2021-04-27 14:45:05 +02:00
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
2018-07-06 07:18:51 +02:00
|
|
|
if (document.documentElement.clientWidth < 600) {
|
2019-07-18 05:27:39 +02:00
|
|
|
onClick(".logo", () => toggleMainMenu());
|
|
|
|
onClick(".header nav li", (event) => onClickMainMenuListItem(event));
|
2018-07-06 07:18:51 +02:00
|
|
|
}
|
2018-07-16 06:51:09 +02:00
|
|
|
|
|
|
|
if ("serviceWorker" in navigator) {
|
|
|
|
let scriptElement = document.getElementById("service-worker-script");
|
|
|
|
if (scriptElement) {
|
|
|
|
navigator.serviceWorker.register(scriptElement.src);
|
|
|
|
}
|
|
|
|
}
|
2020-02-09 20:41:00 +01:00
|
|
|
|
|
|
|
window.addEventListener('beforeinstallprompt', (e) => {
|
|
|
|
// Prevent Chrome 67 and earlier from automatically showing the prompt.
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
let deferredPrompt = e;
|
|
|
|
const promptHomeScreen = document.getElementById('prompt-home-screen');
|
|
|
|
if (promptHomeScreen) {
|
|
|
|
promptHomeScreen.style.display = "block";
|
|
|
|
|
|
|
|
const btnAddToHomeScreen = document.getElementById('btn-add-to-home-screen');
|
|
|
|
if (btnAddToHomeScreen) {
|
|
|
|
btnAddToHomeScreen.addEventListener('click', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
deferredPrompt.prompt();
|
|
|
|
deferredPrompt.userChoice.then(() => {
|
|
|
|
deferredPrompt = null;
|
|
|
|
promptHomeScreen.style.display = "none";
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-05-27 06:35:44 +02:00
|
|
|
});
|
2018-07-06 07:18:51 +02:00
|
|
|
});
|