Logging page created (#279)

This commit is contained in:
nobody 2021-02-21 19:55:31 +01:00
parent 3b3868e0bc
commit 176ddc1305
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
3 changed files with 234 additions and 0 deletions

88
pages/logging/logging.css Normal file
View File

@ -0,0 +1,88 @@
html {
font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif;
}
table {
border-collapse: collapse;
border-spacing: 0;
font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif;
max-width: 100%;
white-space: nowrap;
}
thead, tbody, th, td {
border: 1px solid #a0a0a0;
}
thead {
background-color: #d3d3d3;
}
table td:first-child {
text-align: right;
}
td {
padding: 2px 15px;
}
.button {
background-color: #fafafa;
border: 1px solid #5f5f5f;
border-radius: 5px;
color: #5f5f5f;
cursor: pointer;
font-size: 14px;
margin: 20px 20px 20px 0;
padding: 10px;
}
.button-group {
display: flex;
}
#no-logging-content, #logging-content, #btn-delete {
display: none;
}
#btn-reload:hover {
background-color: #ddd;
}
#btn-delete:hover {
background-color: #dd4b39;
border-color: #d73925;
color: white;
}
.missing {
background-color: #fffbd6;
}
@media (prefers-color-scheme: dark) {
body {
background-color: #202023;
}
body, .title-option {
color: #aeaeae;
}
thead {
background-color: #3c3c3c;
}
.button {
background-color: #3c3c3c;
border-color: #323232;
color: #bbb;
}
#btn-reload:hover {
background-color: #2b2b2b;
}
.missing {
background-color: #535035;
}
}

View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>LocalCDN Logging</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="../base.css">
<link rel="stylesheet" type="text/css" href="logging.css">
<script src="logging.js"></script>
</head>
<body>
<h1>SimpleLog</h1>
<div class="button-group">
<div id="btn-reload" class="button">Refresh</div>
<div id="btn-delete" class="button">Delete</div>
</div>
<p id="no-logging-content">no data</p>
<table id="logging-content">
<thead>
<tr>
<th>#</th>
<th>Initiator</th>
<th>Resource</th>
<th>Redirected to</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>

115
pages/logging/logging.js Normal file
View File

@ -0,0 +1,115 @@
/**
* Logging Page
* Belongs to LocalCDN
*
* @author nobody
* @since 2021-02-19
*
* @license MPL 2.0
*
* 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/.
*/
'use strict';
/**
* Logging Page
*/
var logging = {};
logging._onDocumentLoaded = function () {
logging._getLoggingData()
.then(logging._generateTable);
document.getElementById('btn-delete').addEventListener('click', logging._deleteLogs);
document.getElementById('btn-reload').addEventListener('click', logging._resfresh);
};
logging._generateTable = function () {
let data = logging._data;
if (data.length === 0) {
logging._showTable(false);
return;
}
for (let i = data.length - 1; i >= 0; i--) {
let tbody, row, cell, content, redirect;
tbody = document.getElementById('logging-content').getElementsByTagName('tbody')[0];
row = tbody.insertRow();
if (Object.values(data[i])[3]) {
row.classList.add('missing');
}
cell = row.insertCell();
content = document.createTextNode(i + 1);
cell.appendChild(content);
cell = row.insertCell();
content = document.createTextNode(Object.values(data[i])[0]);
cell.appendChild(content);
cell = row.insertCell();
content = document.createTextNode(Object.values(data[i])[1]);
cell.appendChild(content);
cell = row.insertCell();
if (Object.values(data[i])[2] === '') {
redirect = '-';
} else {
redirect = Object.values(data[i])[2];
}
content = document.createTextNode(redirect);
cell.appendChild(content);
}
logging._showTable(true);
};
logging._deleteLogs = function () {
if (confirm('Are you sure you want to delete these logs?')) {
let message = {
'topic': 'logs:delete',
'value': '',
};
chrome.runtime.sendMessage(message);
logging._resfresh();
}
};
logging._getLoggingData = function () {
return new Promise((resolve) => {
let message = {
'topic': 'logs:get'
};
chrome.runtime.sendMessage(message, function (data) {
logging._data = data['logs'];
resolve();
});
});
};
logging._showTable = function (value) {
let v1, v2;
v1 = value ? 'block' : 'none';
v2 = value ? 'none' : 'block';
document.getElementById('logging-content').style.display = v1;
document.getElementById('btn-delete').style.display = v1;
document.getElementById('no-logging-content').style.display = v2;
};
logging._resfresh = function () {
location.reload();
};
logging._data = [];
document.addEventListener('DOMContentLoaded', logging._onDocumentLoaded);