From 4628a1d4f78bf35e3670b64975afc54ecce9a2f8 Mon Sep 17 00:00:00 2001 From: mkiol Date: Tue, 10 May 2022 18:07:02 +0200 Subject: [PATCH] missing js files --- scripts/night_mode.js | 84 +++++++++++++++++++++++++++++++++++++++++++ scripts/zoom.js | 32 +++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 scripts/night_mode.js create mode 100644 scripts/zoom.js diff --git a/scripts/night_mode.js b/scripts/night_mode.js new file mode 100644 index 0000000..12afbfb --- /dev/null +++ b/scripts/night_mode.js @@ -0,0 +1,84 @@ +/* Copyright (C) 2022 Michal Kosciesza + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +function _night_mode_init() { + var head = document.head + var css1 = ` +html._nightmode1_class { +background-color: white !important; +filter: contrast(68%) brightness(108%) invert(100%) !important; } +html._nightmode1_class iframe { filter: invert(100%) !important; } +html._nightmode1_class object { filter: invert(100%) !important; } +html._nightmode1_class embed { filter: invert(100%) !important; } +html._nightmode1_class video { filter: invert(100%) !important; } +html._nightmode1_class img { filter: invert(100%) !important; }` + var style1 = document.getElementById('_nightmode1_style') + if (style1) { + style1.innerHTML = css1 + window._night_mode_possible = true + return true + } + style1 = document.createElement('style') + style1.id = '_nightmode1_style' + style1.type = 'text/css' + style1.appendChild(document.createTextNode(css1)) + if (head) head.appendChild(style1) + + var css2 = ` +html._nightmode2_class { +background-color: white !important; +filter: invert(100%) !important; } +html._nightmode2_class iframe { filter: invert(100%) !important; } +html._nightmode2_class object { filter: invert(100%) !important; } +html._nightmode2_class embed { filter: invert(100%) !important; } +html._nightmode2_class video { filter: invert(100%) !important; } +html._nightmode2_class img { filter: invert(100%) !important; }` + var style2 = document.getElementById('_nightmode2_style') + if (style2) { + style2.innerHTML = css2 + window._night_mode_possible = true + return true + } + style2 = document.createElement('style') + style2.id = '_nightmode2_style' + style2.type = 'text/css' + style2.appendChild(document.createTextNode(css2)) + if (head) head.appendChild(style2) + + window._night_mode_possible = true + return true +} + +function _night_mode_set(type) { + if (!window._night_mode_possible) return false + var html = document.documentElement + if (type === 0) { + if (html) { + html.className = html.className.replace(/_nightmode1_class/g, '') + html.className = html.className.replace(/_nightmode2_class/g, '') + } + return true + } + if (type === 1) { + if (html) { + html.className += ' _nightmode1_class' + html.className = html.className.replace(/_nightmode2_class/g, '') + } + return true + } + if (type === 2) { + if (html) { + html.className += ' _nightmode2_class' + html.className = html.className.replace(/_nightmode1_class/g, '') + } + return true + } + return false +} + +window._night_mode_possible = false +window._night_mode_set = _night_mode_set diff --git a/scripts/zoom.js b/scripts/zoom.js new file mode 100644 index 0000000..1bb4545 --- /dev/null +++ b/scripts/zoom.js @@ -0,0 +1,32 @@ +/* Copyright (C) 2022 Michal Kosciesza + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +function _zoom_init() { + window._zoom_possible = true + return true +} + +function _zoom_set(zoom) { + if (!window._zoom_possible) return false + + var style = document.documentElement.getElementsByClassName('_zoom_class').item(0) + var css = 'html *:not(h1) { font-size: ' + zoom + ' !important; }' + if (style) { + style.innerHTML = css + } else { + style = document.createElement('style') + style.className = '_zoom_class' + style.type = 'text/css' + style.appendChild(document.createTextNode(css)) + var head = document.head + if (head) head.appendChild(style) + } + return true +} + +window._zoom_possible = false +window._zoom_set = _zoom_set