mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Tidy comments and declaration order
Declare functions before the function that uses it
This commit is contained in:
@ -76,6 +76,7 @@
|
|||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
<script>
|
<script>
|
||||||
|
// ##### Log Filter Block #####
|
||||||
var lines = [];
|
var lines = [];
|
||||||
var words = [];
|
var words = [];
|
||||||
if (localStorage.getItem("words")) {
|
if (localStorage.getItem("words")) {
|
||||||
@ -86,42 +87,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const serverId = new URLSearchParams(document.location.search).get('id')
|
|
||||||
function get_server_log() {
|
|
||||||
if (!$("#stop_scroll").is(':checked')) {
|
|
||||||
$.ajax({
|
|
||||||
type: 'GET',
|
|
||||||
url: '/ajax/server_log?id=' + serverId + '&full=1',
|
|
||||||
dataType: 'text',
|
|
||||||
success: function (data) {
|
|
||||||
console.log('Got Log From Server')
|
|
||||||
$('#virt_console').html(data);
|
|
||||||
scroll();
|
|
||||||
lines = document.querySelectorAll('.box');
|
|
||||||
liveSearch();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security
|
|
||||||
function getCookie(name) {
|
|
||||||
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
|
|
||||||
return r ? r[1] : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
$(document).ready(function () {
|
|
||||||
console.log("ready!");
|
|
||||||
get_server_log();
|
|
||||||
populateWords();
|
|
||||||
});
|
|
||||||
|
|
||||||
function scroll() {
|
|
||||||
var logview = $('#virt_console');
|
|
||||||
if (logview.length)
|
|
||||||
logview.scrollTop(logview[0].scrollHeight - logview.height());
|
|
||||||
}
|
|
||||||
|
|
||||||
function liveSearch() {
|
function liveSearch() {
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
// Reinitialise line visibility
|
// Reinitialise line visibility
|
||||||
@ -137,15 +102,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//A little delay
|
|
||||||
let typingTimer;
|
|
||||||
let typeInterval = 500;
|
|
||||||
let searchInput = document.getElementById('searchbox');
|
|
||||||
|
|
||||||
function sanitize(string) {
|
function sanitize(string) {
|
||||||
return string.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
|
return string.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteItem(item) {
|
||||||
|
let safe_item = sanitize(item);
|
||||||
|
words.splice(words.indexOf(item), 1);
|
||||||
|
if (safe_item) $("#" + safe_item.replaceAll(" ", "-")).remove();
|
||||||
|
|
||||||
|
liveSearch();
|
||||||
|
localStorage.setItem("words", JSON.stringify(words));
|
||||||
|
}
|
||||||
|
|
||||||
|
//A little delay
|
||||||
|
let typingTimer;
|
||||||
|
let typeInterval = 500;
|
||||||
|
let searchInput = document.getElementById('searchbox');
|
||||||
searchInput.addEventListener('keyup', (e) => {
|
searchInput.addEventListener('keyup', (e) => {
|
||||||
clearTimeout(typingTimer);
|
clearTimeout(typingTimer);
|
||||||
typingTimer = setTimeout(liveSearch, typeInterval);
|
typingTimer = setTimeout(liveSearch, typeInterval);
|
||||||
@ -188,15 +161,6 @@
|
|||||||
localStorage.setItem("words", JSON.stringify(words));
|
localStorage.setItem("words", JSON.stringify(words));
|
||||||
});
|
});
|
||||||
|
|
||||||
function deleteItem(item) {
|
|
||||||
let safe_item = sanitize(item);
|
|
||||||
words.splice(words.indexOf(item), 1);
|
|
||||||
if (safe_item) $("#" + safe_item.replaceAll(" ", "-")).remove();
|
|
||||||
|
|
||||||
liveSearch();
|
|
||||||
localStorage.setItem("words", JSON.stringify(words));
|
|
||||||
}
|
|
||||||
|
|
||||||
function populateWords() {
|
function populateWords() {
|
||||||
for (let i = 0; i < words.length; i++) {
|
for (let i = 0; i < words.length; i++) {
|
||||||
let safe_word = sanitize(words[i]);
|
let safe_word = sanitize(words[i]);
|
||||||
@ -209,5 +173,45 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ##### End Log Filter Block #####
|
||||||
|
|
||||||
|
// Used to get cookies from browser - this is part of tornados xsrf protection
|
||||||
|
// (it's for extra security)
|
||||||
|
function getCookie(name) {
|
||||||
|
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
|
||||||
|
return r ? r[1] : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset Scroll
|
||||||
|
function scroll() {
|
||||||
|
var logview = $('#virt_console');
|
||||||
|
if (logview.length)
|
||||||
|
logview.scrollTop(logview[0].scrollHeight - logview.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate logs and filter if present
|
||||||
|
const serverId = new URLSearchParams(document.location.search).get('id')
|
||||||
|
function get_server_log() {
|
||||||
|
if (!$("#stop_scroll").is(':checked')) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: '/ajax/server_log?id=' + serverId + '&full=1',
|
||||||
|
dataType: 'text',
|
||||||
|
success: function (data) {
|
||||||
|
console.log('Got Log From Server')
|
||||||
|
$('#virt_console').html(data);
|
||||||
|
scroll();
|
||||||
|
lines = document.querySelectorAll('.box');
|
||||||
|
liveSearch();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
console.log("ready!");
|
||||||
|
get_server_log();
|
||||||
|
populateWords();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
{% end %}
|
{% end %}
|
||||||
|
Reference in New Issue
Block a user