Skip to content

Commit 06895c2

Browse files
committed
format buttons, fixes
1 parent 596b48a commit 06895c2

File tree

9 files changed

+84
-26
lines changed

9 files changed

+84
-26
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Google chrome extension that improves RabbitMQ web console UI
22

3+
[Web Store link](https://chrome.google.com/webstore/detail/rabbitmq-ui/aojjjccnchdgfojkplokcaikfoighecb)
4+
35
### Features
46
* Saves last message for each queue and restores it when you open queue page
57
* JSON parsing for messages in queue payload
8+
* Buttons to beautify and minify JSON in payload
69

710
### Requirements
811

@@ -11,6 +14,6 @@
1114

1215
## Screenshots
1316

14-
![Interface](screenshot.png)
17+
![Interface](img/screenshot.png)
1518

1619
JSON Formatter by [mohsen1/json-formatter-js](https://github.com/mohsen1/json-formatter-js)

content.js

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
1+
let formatter = new Formatter();
2+
13
function Formatter() {
4+
this.payload = document.getElementsByTagName('textarea')[0];
5+
26
this.parseError = document.createElement("div");
37
this.parseError.id = 'parseError';
8+
49
this.formattedDiv = document.createElement("div");
510
this.formattedDiv.id = 'formattedPayload';
6-
this.payload = document.getElementsByTagName('textarea')[0];
11+
12+
this.beautifyLink = document.createElement('a');
13+
this.beautifyLink.id = 'beautifyPayload';
14+
this.beautifyLink.className = 'payloadBtn';
15+
this.beautifyLink.innerText = 'Beautify';
16+
this.beautifyLink.onclick = function () {
17+
formatter.beautify();
18+
};
19+
20+
this.minifyLink = document.createElement('a');
21+
this.minifyLink.id = 'minifyPayload';
22+
this.minifyLink.className = 'payloadBtn';
23+
this.minifyLink.innerText = 'Minify';
24+
this.minifyLink.onclick = function () {
25+
formatter.minify();
26+
};
27+
28+
// parses new text from payload
729
this.update = function () {
8-
console.log('updated!!');
930
this.formattedDiv.innerHTML = '';
1031
this.hideError();
1132
let raw = this.payload.value;
1233
if ('' === raw) {
13-
return;
34+
return false;
1435
}
1536

1637
let jsonObj;
@@ -19,69 +40,92 @@ function Formatter() {
1940
}
2041
catch (e) {
2142
this.showError(e.toString());
22-
return;
43+
return false;
2344
}
2445

25-
// this.payload.value = JSON.stringify(jsonObj, undefined, 2);
26-
27-
savePayload(this.payload.value);
28-
2946
let formatter = new JSONFormatter(jsonObj, Infinity, {
3047
hoverPreviewEnabled: false,
3148
hoverPreviewArrayCount: 20,
3249
hoverPreviewFieldCount: 20,
33-
theme: 'dark',
3450
animateOpen: true,
3551
animateClose: true,
3652
useToJSON: true
3753
});
3854
this.formattedDiv.appendChild(formatter.render());
55+
return true;
3956
};
57+
4058
this.showError = function (error) {
4159
this.parseError.innerText = error;
4260
};
4361

4462
this.hideError = function () {
4563
this.parseError.innerText = '';
4664
};
65+
66+
this.beautify = function () {
67+
let jsonObj;
68+
try {
69+
jsonObj = JSON.parse(this.payload.value);
70+
}
71+
catch (e) {
72+
this.showError(e.toString());
73+
return;
74+
}
75+
this.payload.value = JSON.stringify(jsonObj, undefined, 2);
76+
};
77+
78+
this.minify = function () {
79+
let jsonObj;
80+
try {
81+
jsonObj = JSON.parse(this.payload.value);
82+
}
83+
catch (e) {
84+
this.showError(e.toString());
85+
return;
86+
}
87+
this.payload.value = JSON.stringify(jsonObj);
88+
}
4789
}
4890

4991
let hash = document.location.hash;
50-
setInterval(updateHash, 500);
92+
setInterval(checkPageChange, 500);
5193

52-
function updateHash() {
94+
function checkPageChange() {
5395
let newHash = document.location.hash;
54-
console.log(newHash);
5596
if (hash !== newHash) {
5697
init();
5798
hash = newHash;
5899
}
59100
}
60101

61-
init();
102+
// we wait a bit for payload element to init
103+
setTimeout(init, 300);
62104

63-
function init() {
64-
let formatter = new Formatter();
105+
async function init() {
106+
formatter = new Formatter();
65107
if (formatter.payload === undefined || formatter.payload === undefined) {
66108
return;
67109
}
68110

69111
formatter.payload.parentElement.append(formatter.parseError);
70112
formatter.payload.closest('div').append(formatter.formattedDiv);
113+
let btnPlace = formatter.payload.closest('tr').children[0];
114+
btnPlace.append(formatter.beautifyLink);
115+
btnPlace.append(document.createElement('br'));
116+
btnPlace.append(formatter.minifyLink);
71117
formatter.update();
72118
let wait = null;
73119
formatter.payload.onkeyup = function () {
74120
window.clearTimeout(wait);
75121
wait = setTimeout(function () {
76-
formatter.update();
122+
if (formatter.update()) {
123+
savePayload(formatter.payload.value);
124+
}
77125
}, 700);
78126
};
79127
getSavedPayload(function (result) {
80-
let key = getKey();
81-
if (!key) {
82-
return;
83-
}
84-
let value = result[key];
128+
let value = result[getKey()];
85129
if (!value) {
86130
return;
87131
}
@@ -90,7 +134,7 @@ function init() {
90134
})
91135
}
92136

93-
137+
// generate key for current queue and host
94138
function getKey() {
95139
const queueExp = /\/queues\/%2F\/(.*)/;
96140

icon.png

-22.7 KB
Binary file not shown.

img/icon128.png

1.88 KB
Loading

img/icon48.png

1.33 KB
Loading

img/screenshot.png

78.5 KB
Loading

manifest.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
{
22
"manifest_version": 2,
33
"name": "RabbitMQ UI",
4+
"short_name": "RabbitMQ UI",
45
"description": "RabbitMQ web console improvements",
5-
"version": "1",
6+
"version": "0.2.0",
7+
"icons": {
8+
"48": "img/icon48.png",
9+
"128": "img/icon128.png"
10+
},
611
"author": "MUlt1mate",
712
"browser_action": {
8-
"default_icon": "icon.png",
13+
"default_icon": "img/icon128.png",
914
"default_title": "RabbitMQ UI"
1015
},
1116
"permissions": [

screenshot.png

-59.4 KB
Binary file not shown.

styles.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
display: inline-block;
1212
}
1313

14-
#parseError{
14+
#parseError {
1515
color: crimson;
16+
}
17+
18+
.payloadBtn {
19+
cursor: pointer;
20+
border-bottom: 1px dotted;
21+
line-height: 30px;
1622
}

0 commit comments

Comments
 (0)