summaryrefslogtreecommitdiff
path: root/js/common.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-04-21 08:34:24 +0300
committerAndrew Dolgov <[email protected]>2020-04-21 08:34:24 +0300
commit0a80c7a89cbe092d4ec6591b1ce0ab68479323d6 (patch)
tree0da476cbacdb3c33b86ccd078d863c6bde2a7b2b /js/common.js
parentbb0bbfb1ed76bb9c429b92d3769c19adef553e43 (diff)
combine index-related JS code into one App object
Diffstat (limited to 'js/common.js')
-rw-r--r--js/common.js75
1 files changed, 0 insertions, 75 deletions
diff --git a/js/common.js b/js/common.js
deleted file mode 100644
index 45851a7..0000000
--- a/js/common.js
+++ /dev/null
@@ -1,75 +0,0 @@
-'use strict';
-
-$.urlParam = function(name){
- try {
- const results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
- return decodeURIComponent(results[1].replace(/\+/g, " ")) || 0;
- } catch (e) {
- return 0;
- }
-}
-
-function offline_remove(id, callback) {
-
- if (confirm("Remove download?")) {
-
- const cacheId = "epube-book." + id;
- const promises = [];
-
- console.log("offline remove: " + id);
-
- localforage.iterate(function(value, key, i) {
- if (key.match(cacheId)) {
- promises.push(localforage.removeItem(key));
- }
- });
-
- Promise.all(promises).then(function() {
- window.setTimeout(function() {
- callback();
- }, 500);
- });
- }
-}
-
-function init_night_mode() {
- if (window.matchMedia) {
- const mql = window.matchMedia('(prefers-color-scheme: dark)');
-
- mql.addEventListener("change", () => {
- apply_night_mode(mql.matches);
- });
-
- apply_night_mode(mql.matches);
- }
-}
-
-function apply_night_mode(is_night) {
- console.log("night mode changed to", is_night);
-
- $("#theme_css").attr("href",
- "lib/bootstrap/v3/css/" + (is_night ? "theme-dark.min.css" : "bootstrap-theme.min.css"));
-}
-
-const Cookie = {
- set: function (name, value, lifetime) {
- const d = new Date();
- d.setTime(d.getTime() + lifetime * 1000);
- const expires = "expires=" + d.toUTCString();
- document.cookie = name + "=" + encodeURIComponent(value) + "; " + expires;
- },
- get: function (name) {
- name = name + "=";
- const ca = document.cookie.split(';');
- for (let i=0; i < ca.length; i++) {
- let c = ca[i];
- while (c.charAt(0) == ' ') c = c.substring(1);
- if (c.indexOf(name) == 0) return decodeURIComponent(c.substring(name.length, c.length));
- }
- return "";
- },
- delete: function(name) {
- const expires = "expires=Thu, 01-Jan-1970 00:00:01 GMT";
- document.cookie = name + "=" + "" + "; " + expires;
- }
-};