Skip to content

Commit ee3b73f

Browse files
committed
Adjust outline to shift and button Cut
1 parent dbe931a commit ee3b73f

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

data/html/popup-button.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ <h6>Commands</h6></li>
119119
<div id="bottom-panel">
120120
<button class="" id="Clear">Clear</button>
121121
<button class="" id="Copy">Copy</button>
122+
<button class="" id="Cut">Cut</button>
122123

123124
<button class="" id="NPM">Guide-Automator</button>
124125
</div>

data/scripts/popup-middleware.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ self.port.on("show", function onShow() {
55
});
66

77
self.port.on("text-received", function onShow(text) {
8-
if(text)
8+
if (text)
99
addText(text);
1010
});
1111

@@ -21,7 +21,7 @@ document.querySelectorAll('#bottom-panel > button')
2121
});
2222

2323
function executeCommandButton(buttonId) {
24-
switch(buttonId) {
24+
switch (buttonId) {
2525
case "Clear":
2626
clearText();
2727
self.port.emit("clear");
@@ -31,6 +31,12 @@ function executeCommandButton(buttonId) {
3131
toast("Code copied to clipboard!");
3232
self.port.emit("CopyMessage", text);
3333
break;
34+
case "Cut":
35+
text = getTextWithTags().toString();
36+
toast("Code copied to clipboard!");
37+
clearText();
38+
self.port.emit("CopyMessage", text);
39+
break;
3440
case "NPM":
3541
window.open('https://www.npmjs.com/package/guide-automator', '_blank');
3642
break;
@@ -47,12 +53,12 @@ document.querySelectorAll('#left-panel > ul > li')
4753
.addEventListener('click', function() {
4854
executeCommandGD(this.id);
4955
});
50-
if(element.id)
56+
if (element.id)
5157
element.style.cursor = 'pointer';
5258
});
5359

5460
function executeCommandGD(commandId) {
55-
switch(commandId) {
61+
switch (commandId) {
5662
case "GDget":
5763
addText("get('http://example.com');");
5864
break;

index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var _outlineElements = [];
2323
//-- EVENT OF ADDON ELEMENT
2424

2525
function onbuttonGuideAutomatorClicked(state) {
26-
if(state.checked) {
26+
if (state.checked) {
2727
popupGuideAutomator.show({
2828
position: button
2929
});
@@ -38,7 +38,7 @@ function onContextGetCssSelector(message) {
3838
function onContextGDFunction(message) {
3939
message = JSON.parse(message);
4040
message = getGDCommand(message);
41-
if(message !== "") {
41+
if (message !== "") {
4242
clipboard.set(message);
4343
popupGuideAutomator.port.emit("text-received", message);
4444
}
@@ -172,7 +172,7 @@ popupGuideAutomator.port.on("hideMessage", function(text) {
172172
});
173173

174174
popupGuideAutomator.port.on("CopyMessage", function(text) {
175-
if(text !== "") {
175+
if (text !== "") {
176176
clipboard.set(text);
177177
}
178178
});
@@ -192,27 +192,27 @@ popupGuideAutomator.port.on("clear", function() {
192192

193193
function getGDCommand(data) {
194194
var result = "";
195-
if(data.pageContext && data.command !== "Outline") {
196-
if(data.pageContext !== _pageContext)
195+
if (data.pageContext && data.command !== "Outline") {
196+
if (data.pageContext !== _pageContext)
197197
result = `pageContext(` + data.pageContext.toString() + `);\n`;
198198
_pageContext = data.pageContext;
199199
} else {
200-
if(_pageContext !== "") {
200+
if (_pageContext !== "") {
201201
_pageContext = "";
202202
result = `pageContext();\n`;
203203
}
204204
}
205205

206206

207-
switch(data.command) {
207+
switch (data.command) {
208208
case "GetUrl":
209209
result += `get(` + data.result[0] + `);`;
210210
break;
211211
case "Click":
212212
result += `click(` + data.result[0] + `);`;
213213
break;
214214
case "TakeScreenshot":
215-
if(_outlineElements.length === 0)
215+
if (_outlineElements.length === 0)
216216
result += `takeScreenshot(` + data.result[0] + `);`;
217217
else {
218218
result += `takeScreenshotOf([` + getAllOutlines() + `],` +
@@ -223,14 +223,14 @@ function getGDCommand(data) {
223223
}
224224
break;
225225
case "TakeScreenshotOf":
226-
if(_outlineElements.length === 0)
226+
if (_outlineElements.length === 0)
227227
result += `takeScreenshotOf(` + data.result[0] + `,` +
228228
data.result[1] + `,` +
229229
data.result[2] + `,` +
230230
data.result[3] +
231231
`);`;
232232
else {
233-
if(data.pageContext)
233+
if (data.pageContext)
234234
_outlineElements.push([data.result[0], data.pageContext]);
235235
else
236236
_outlineElements.push(data.result[0]);
@@ -257,7 +257,7 @@ function getGDCommand(data) {
257257
result += `console.print(` + data.result[0] + `);`;
258258
break;
259259
case "Outline":
260-
if(data.pageContext)
260+
if (data.pageContext)
261261
_outlineElements.push([data.result[0], data.pageContext]);
262262
else
263263
_outlineElements.push(data.result[0]);
@@ -272,13 +272,13 @@ function getGDCommand(data) {
272272

273273
function getAllOutlines() {
274274
var selectors = [];
275-
var nodeOutline = _outlineElements.pop();
276-
while(nodeOutline) {
277-
if(nodeOutline.constructor === Array)
275+
var nodeOutline = _outlineElements.shift();
276+
while (nodeOutline) {
277+
if (nodeOutline.constructor === Array)
278278
selectors.push("[" + nodeOutline + "]");
279279
else
280280
selectors.push(nodeOutline);
281-
nodeOutline = _outlineElements.pop();
281+
nodeOutline = _outlineElements.shift();
282282
}
283283
return selectors;
284284
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"title": "Guide-Automator",
33
"name": "guide-automator",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"description": "Help to build guide-automator(npm) blocks",
66
"main": "index.js",
77
"author": "Welbert Serra",

0 commit comments

Comments
 (0)