first commit
This commit is contained in:
53
init.js
Normal file
53
init.js
Normal file
@@ -0,0 +1,53 @@
|
||||
require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
|
||||
ready(function () {
|
||||
PluginHost.register(PluginHost.HOOK_INIT_COMPLETE, () => {
|
||||
|
||||
App.hotkey_actions["toggle_night_mode"] = function () {
|
||||
App.toggleNightMode()
|
||||
};
|
||||
|
||||
App.toggleNightMode = function () {
|
||||
const link = App.byId("theme_css");
|
||||
if (!link) return;
|
||||
|
||||
let user_css = false;
|
||||
let href = link.getAttribute("href").split("?")[0];
|
||||
let userCSS = function(url, or = false) {
|
||||
dojo.xhrGet({
|
||||
url: url,
|
||||
handleAs: 'text',
|
||||
sync: true,
|
||||
preventCache: true,
|
||||
load: function() { user_css = url },
|
||||
error: function() { user_css = or }
|
||||
});
|
||||
}
|
||||
|
||||
if (href.indexOf("themes.local/") > -1) {
|
||||
if (href.indexOf("_night.css") > -1)
|
||||
userCSS(href.replace("_night.css", ".css"));
|
||||
else
|
||||
userCSS(href.replace(".css", "_night.css"));
|
||||
} else if (href.indexOf("/night.css") > -1)
|
||||
userCSS("themes/light.css", "css/default.css");
|
||||
else
|
||||
userCSS("themes/night.css");
|
||||
|
||||
if (user_css) {
|
||||
App.byId("main").fadeOut();
|
||||
setTimeout(() => {
|
||||
link.setAttribute("href", user_css);
|
||||
xhrPost("backend.php", {
|
||||
op: "rpc",
|
||||
method: "setpref",
|
||||
key: "USER_CSS_THEME",
|
||||
value: user_css.split("/")[1]
|
||||
});
|
||||
setTimeout(() => { App.byId("main").fadeIn() }, 200);
|
||||
}, 300);
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
27
init.php
Normal file
27
init.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
class Toggle_Night_Mode extends Plugin {
|
||||
|
||||
function about() {
|
||||
return array(2.2,
|
||||
"Allow night mode toggle with [a N] for custom themes (use yourtheme_night.css as filename)",
|
||||
"ltGuillaume");
|
||||
}
|
||||
|
||||
function init($host) {
|
||||
$host->add_hook($host::HOOK_HOTKEY_MAP, $this);
|
||||
}
|
||||
|
||||
function hook_hotkey_map($hotkeys) {
|
||||
$hotkeys["a N"] = "toggle_night_mode";
|
||||
return $hotkeys;
|
||||
}
|
||||
|
||||
function get_js() {
|
||||
return file_get_contents(__DIR__ . "/init.js");
|
||||
}
|
||||
|
||||
function api_version() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user