mirror of
https://github.com/thelounge/thelounge
synced 2024-11-10 22:54:15 +00:00
Override server provided defaults with parameters passed in the URL if they match the data type
This commit is contained in:
parent
ee5e82fe9a
commit
94f1d8dde0
2 changed files with 35 additions and 43 deletions
|
@ -4,7 +4,6 @@
|
|||
require("jquery-ui/ui/widgets/sortable");
|
||||
const $ = require("jquery");
|
||||
const moment = require("moment");
|
||||
const URI = require("urijs");
|
||||
|
||||
// our libraries
|
||||
require("./libs/jquery/stickyscroll");
|
||||
|
@ -346,48 +345,6 @@ $(function() {
|
|||
callback: (itemData) => closeChan($(`.networks .chan[data-target="${itemData}"]`)),
|
||||
});
|
||||
|
||||
if ($(document.body).hasClass("public") && (window.location.hash === "#connect" || window.location.hash === "")) {
|
||||
$("#connect").one("show", function() {
|
||||
const params = URI(document.location.search).search(true);
|
||||
|
||||
if ("channels" in params) {
|
||||
params.join = params.channels;
|
||||
}
|
||||
|
||||
// Possible parameters: name, host, port, password, tls, nick, username, realname, join
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#Iterating_over_own_properties_only
|
||||
for (let key in params) {
|
||||
if (params.hasOwnProperty(key)) {
|
||||
let value = params[key];
|
||||
|
||||
if (key === "join") {
|
||||
value = value.split(",").map((chan) => {
|
||||
if (!chan.match(/^[#&!+]/)) {
|
||||
return `#${chan}`;
|
||||
}
|
||||
|
||||
return chan;
|
||||
}).join(", ");
|
||||
}
|
||||
|
||||
// \W searches for non-word characters
|
||||
key = key.replace(/\W/g, "");
|
||||
|
||||
const element = $("#connect input[name='" + key + "']");
|
||||
|
||||
// if the element exists, it isn't disabled, and it isn't hidden
|
||||
if (element.length > 0 && !element.is(":disabled") && !element.is(":hidden")) {
|
||||
if (element.is(":checkbox")) {
|
||||
element.prop("checked", (value === "1" || value === "true") ? true : false);
|
||||
} else {
|
||||
element.val(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on("visibilitychange focus click", () => {
|
||||
if (sidebar.find(".highlight").length === 0) {
|
||||
utils.toggleNotificationMarkers(false);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
const $ = require("jquery");
|
||||
const URI = require("urijs");
|
||||
const socket = require("../socket");
|
||||
const templates = require("../../views");
|
||||
const options = require("../options");
|
||||
|
@ -84,4 +85,38 @@ socket.on("configuration", function(data) {
|
|||
$(this).data("lastvalue", nick);
|
||||
});
|
||||
});
|
||||
|
||||
if ($(document.body).hasClass("public")) {
|
||||
const params = URI(document.location.search).search(true);
|
||||
|
||||
for (let key in params) {
|
||||
// Support `channels` as a compatibility alias with other clients
|
||||
if (key === "channels") {
|
||||
key = "join";
|
||||
}
|
||||
|
||||
if (!data.defaults.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let value = params[key];
|
||||
|
||||
if (key === "join") {
|
||||
value = value.split(",").map((chan) => {
|
||||
if (!chan.match(/^[#&!+]/)) {
|
||||
return `#${chan}`;
|
||||
}
|
||||
|
||||
return chan;
|
||||
}).join(", ");
|
||||
}
|
||||
|
||||
// Override server provided defaults with parameters passed in the URL if they match the data type
|
||||
switch (typeof data.defaults[key]) {
|
||||
case "boolean": data.defaults[key] = value === "1" || value === "true"; break;
|
||||
case "number": data.defaults[key] = Number(value); break;
|
||||
case "string": data.defaults[key] = String(value); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue