Skip to content

Commit 596b48a

Browse files
committed
first version
0 parents  commit 596b48a

File tree

8 files changed

+1167
-0
lines changed

8 files changed

+1167
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 MUlt1mate
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Google chrome extension that improves RabbitMQ web console UI
2+
3+
### Features
4+
* Saves last message for each queue and restores it when you open queue page
5+
* JSON parsing for messages in queue payload
6+
7+
### Requirements
8+
9+
* Tested on RabbitMQ 3.6.10
10+
* Currently requires url to match expression http://*:15672/*
11+
12+
## Screenshots
13+
14+
![Interface](screenshot.png)
15+
16+
JSON Formatter by [mohsen1/json-formatter-js](https://github.com/mohsen1/json-formatter-js)

content.js

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
function Formatter() {
2+
this.parseError = document.createElement("div");
3+
this.parseError.id = 'parseError';
4+
this.formattedDiv = document.createElement("div");
5+
this.formattedDiv.id = 'formattedPayload';
6+
this.payload = document.getElementsByTagName('textarea')[0];
7+
this.update = function () {
8+
console.log('updated!!');
9+
this.formattedDiv.innerHTML = '';
10+
this.hideError();
11+
let raw = this.payload.value;
12+
if ('' === raw) {
13+
return;
14+
}
15+
16+
let jsonObj;
17+
try {
18+
jsonObj = JSON.parse(raw);
19+
}
20+
catch (e) {
21+
this.showError(e.toString());
22+
return;
23+
}
24+
25+
// this.payload.value = JSON.stringify(jsonObj, undefined, 2);
26+
27+
savePayload(this.payload.value);
28+
29+
let formatter = new JSONFormatter(jsonObj, Infinity, {
30+
hoverPreviewEnabled: false,
31+
hoverPreviewArrayCount: 20,
32+
hoverPreviewFieldCount: 20,
33+
theme: 'dark',
34+
animateOpen: true,
35+
animateClose: true,
36+
useToJSON: true
37+
});
38+
this.formattedDiv.appendChild(formatter.render());
39+
};
40+
this.showError = function (error) {
41+
this.parseError.innerText = error;
42+
};
43+
44+
this.hideError = function () {
45+
this.parseError.innerText = '';
46+
};
47+
}
48+
49+
let hash = document.location.hash;
50+
setInterval(updateHash, 500);
51+
52+
function updateHash() {
53+
let newHash = document.location.hash;
54+
console.log(newHash);
55+
if (hash !== newHash) {
56+
init();
57+
hash = newHash;
58+
}
59+
}
60+
61+
init();
62+
63+
function init() {
64+
let formatter = new Formatter();
65+
if (formatter.payload === undefined || formatter.payload === undefined) {
66+
return;
67+
}
68+
69+
formatter.payload.parentElement.append(formatter.parseError);
70+
formatter.payload.closest('div').append(formatter.formattedDiv);
71+
formatter.update();
72+
let wait = null;
73+
formatter.payload.onkeyup = function () {
74+
window.clearTimeout(wait);
75+
wait = setTimeout(function () {
76+
formatter.update();
77+
}, 700);
78+
};
79+
getSavedPayload(function (result) {
80+
let key = getKey();
81+
if (!key) {
82+
return;
83+
}
84+
let value = result[key];
85+
if (!value) {
86+
return;
87+
}
88+
formatter.payload.value = value;
89+
formatter.update();
90+
})
91+
}
92+
93+
94+
function getKey() {
95+
const queueExp = /\/queues\/%2F\/(.*)/;
96+
97+
let found = window.location.hash.match(queueExp);
98+
if (null === found) {
99+
return found;
100+
}
101+
return 'rmq_q_payload_' + window.location.hostname + found[1];
102+
}
103+
104+
function savePayload(payload) {
105+
let key = getKey();
106+
if (!key) {
107+
return;
108+
}
109+
let obj = {};
110+
obj[key] = payload;
111+
chrome.storage.local.set(obj);
112+
}
113+
114+
function getSavedPayload(callback) {
115+
let key = getKey();
116+
if (!key) {
117+
return;
118+
}
119+
chrome.storage.local.get([key], callback);
120+
}

icon.png

22.7 KB
Loading

0 commit comments

Comments
 (0)