+
+// document.ready()
+document.addEventListener('DOMContentLoaded', function(event) {
+    // Search for all datetime fields and convert the time to local timezone
+    convertAllDatetimeFields();
+});
+
+// Add copy event listeners
+function copyLinkToClipboard(link_id) {
+    var focus = document.activeElement;
+    var e = document.getElementById(link_id);
+
+    var tmp = document.createElement("textarea");
+    document.body.appendChild(tmp);
+    tmp.textContent = e.href;
+    tmp.focus();
+    tmp.setSelectionRange(0, tmp.value.length);
+    document.execCommand("copy");
+    document.body.removeChild(tmp);
+
+    focus.focus();
+}
+
+function addCopyListener(button_id, link_id) {
+    if(document.getElementById(button_id)){
+        document.getElementById(button_id)
+            .addEventListener("click", function() {
+                copyLinkToClipboard(link_id);});
+    }
+}
+
+function copyTextToClipboard(text_id){
+    var copyText = document.getElementById(text_id);
+    copyText.select();
+    copyText.setSelectionRange(0, 99999); 
+    navigator.clipboard.writeText(copyText.value);
+}
+
+function addTextCopyListener(button_id, text_id) {
+    if(document.getElementById(button_id)){
+        document.getElementById(button_id)
+            .addEventListener("click", function() {
+                copyTextToClipboard(text_id);});
+    }
+}
+
+function set_dark_mode() {
+    let steel_sheet = "<?php echo 'media/' . $cfg['dark_style'] . '/style.css.php'; ?>";
+    let shortcut_icon = "<?php echo 'media/' . $cfg['dark_style'] . '/favicon.ico'; ?>";
+    document.getElementById('stylesheet').href = steel_sheet;
+    document.getElementById('shortcut_icon').href = shortcut_icon;
+}
+
+function set_light_mode() {
+    let steel_sheet = "<?php echo 'media/' . $cfg['style'] . '/style.css.php'; ?>";
+    let shortcut_icon = "<?php echo 'media/' . $cfg['style'] . '/favicon.ico'; ?>";
+    document.getElementById('stylesheet').href = steel_sheet;
+    document.getElementById('shortcut_icon').href = shortcut_icon;
+}
+
+function color_scheme_preferences() {
+
+    let dark_mode_steel_sheet = "<?php echo 'media/' . $cfg['dark_style'] . '/style.css.php'; ?>"
+    if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
+        set_dark_mode();
+    } else {
+        set_light_mode();
+    }
+
+    // When user change its preference
+    window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', lightMode => {
+        lightMode.matches ? set_dark_mode() : set_light_mode();
+    });
+}
+
+// @license-end