Skip to content

Commit 4e8ca29

Browse files
committed
Merge branch 'v0.6.0'
2 parents f7f9130 + 003c2f8 commit 4e8ca29

File tree

11 files changed

+92
-21
lines changed

11 files changed

+92
-21
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ The list of actions possible to attach to mouse gestures:
2222
- Reopen Tab
2323
- Duplicate Tab
2424
- Open New Window
25+
- Search Highlighted Text
26+
- Close Tabs to the Right
2527

2628
Other settings:
2729

2830
- Line color
2931
- Line width
3032

33+
It works only in Windows operating system.
34+
3135
## Dependencies
3236

3337
It uses [Coloris v0.22.0](https://github.com/mdbassit/Coloris) to choose a line color in settings.

content-scripts/content-event-handler.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
class ContentEventHandler {
22
#gesturesHandler;
33
#canvasHandler;
4+
#selectedTextHandler;
45

56
#mouseDownHandler;
67
#mouseUpHandler;
78
#contextMenuHandler;
89

910
#blockDefaultContextMenu = false;
1011

11-
constructor(gesturesHandler, canvasHandler) {
12+
constructor(gesturesHandler, canvasHandler, selectedTextHandler) {
1213
this.#gesturesHandler = gesturesHandler;
1314
this.#canvasHandler = canvasHandler;
15+
this.#selectedTextHandler = selectedTextHandler;
1416
this.#mouseDownHandler = this.#createMouseDownHandler();
1517
this.#mouseUpHandler = this.#createMouseUpHandler();
1618
this.#contextMenuHandler = this.#createContextMenuHandler();
@@ -25,25 +27,26 @@ class ContentEventHandler {
2527

2628
#createMouseDownHandler() {
2729
return (event) => {
28-
this.#handleMouseDown(event, this.#gesturesHandler);
30+
this.#handleMouseDown(event, this.#gesturesHandler, this.#selectedTextHandler);
2931
};
3032
}
3133

32-
#handleMouseDown(event, gesturesHandler) {
34+
#handleMouseDown(event, gesturesHandler, selectedTextHandler) {
3335
if (event.button !== Consts.rightButton) {
3436
return;
3537
}
3638

39+
selectedTextHandler.saveSelectedText();
3740
gesturesHandler.initPosition(event);
3841
}
3942

4043
#createMouseUpHandler() {
4144
return (event) => {
42-
this.#handleMouseUp(event, this.#canvasHandler, this.#gesturesHandler);
45+
this.#handleMouseUp(event, this.#canvasHandler, this.#gesturesHandler, this.#selectedTextHandler);
4346
};
4447
}
4548

46-
#handleMouseUp(event, canvasHandler, gesturesHandler) {
49+
#handleMouseUp(event, canvasHandler, gesturesHandler, selectedTextHandler) {
4750
if (event.button !== Consts.rightButton) {
4851
return;
4952
}
@@ -64,6 +67,7 @@ class ContentEventHandler {
6467
chrome.runtime.sendMessage({
6568
gestures,
6669
type: Consts.messageTypes.gestures,
70+
selectedText: selectedTextHandler.getSelectedText(),
6771
});
6872
}
6973

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class SelectedTextHandler {
2+
#selectedText = '';
3+
4+
saveSelectedText() {
5+
this.#selectedText = window?.getSelection()?.toString()?.trim() ?? '';
6+
}
7+
8+
getSelectedText() {
9+
return this.#selectedText;
10+
}
11+
}

content.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ const storage = new SettingsStorage();
55
const canvasEventHandler = new CanvasEventHandler(canvas, storage);
66
canvasEventHandler.registerEvent();
77
const canvasHandler = new CanvasHandler(canvasEventHandler, canvas);
8-
const contentEventHandler = new ContentEventHandler(gesturesHandler, canvasHandler);
8+
const selectedTextHandler = new SelectedTextHandler();
9+
const contentEventHandler = new ContentEventHandler(gesturesHandler, canvasHandler, selectedTextHandler);
910
contentEventHandler.registerEvents();

manifest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"manifest_version": 3,
33
"name": "Simple Mouse Gestures",
44
"description": "Extension that provides the ability to define mouse gestures that will run specific actions in your Google Chrome browser",
5-
"version": "0.5.0",
6-
"version_name": "0.5.0 beta",
5+
"version": "0.6.0",
6+
"version_name": "0.6.0 beta",
77
"icons": {
88
"16": "images/icon-16.png",
99
"32": "images/icon-32.png",
@@ -19,6 +19,7 @@
1919
"content-scripts/canvas-builder.js",
2020
"content-scripts/canvas-event-handler.js",
2121
"content-scripts/canvas-handler.js",
22+
"content-scripts/selected-text-handler.js",
2223
"content-scripts/settings-storage.js",
2324
"content-scripts/content-event-handler.js",
2425
"content.js"

popup/popup.css

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
* {
2-
font-family:
3-
Open Sans,
4-
-apple-system,
5-
BlinkMacSystemFont,
6-
Segoe UI,
7-
Roboto,
8-
Helvetica Neue,
9-
Arial,
10-
sans-serif;
2+
font-family: Open Sans, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif;
113
font-size: 13px;
124
}
135
button {
@@ -72,6 +64,9 @@ select {
7264
display: none;
7365
min-height: 300px;
7466
}
67+
.tab #operation-select {
68+
width: 220px;
69+
}
7570
.tab.active {
7671
display: block;
7772
padding-top: 10px;

service-worker-scripts/context.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class Context {
2+
gestures = [];
3+
selectedText = '';
4+
5+
constructor(gestures, selectedText) {
6+
this.gestures = gestures;
7+
this.selectedText = selectedText;
8+
}
9+
}

service-worker-scripts/operation-resolver.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { ScrollToBottomOperation } from '/service-worker-scripts/operations/scro
1212
import { ReopenTabOperation } from '/service-worker-scripts/operations/reopen-tab-operation.js';
1313
import { DuplicateTabOperation } from '/service-worker-scripts/operations/duplicate-tab-operation.js';
1414
import { OpenNewWindowOperation } from '/service-worker-scripts/operations/open-new-window-operation.js';
15+
import { SearchHighlightedTextOperation } from '/service-worker-scripts/operations/search-highlighted-text-operation.js';
16+
import { CloseTabsToRightOperation } from '/service-worker-scripts/operations/close-tabs-to-right-operation.js';
1517

1618
export class OperationResolver {
1719
#storage;
@@ -73,14 +75,26 @@ export class OperationResolver {
7375
operation: new OpenNewWindowOperation(),
7476
label: 'Open New Window',
7577
},
78+
searchHighlightedTextInActiveTab: {
79+
operation: new SearchHighlightedTextOperation(true),
80+
label: 'Search Highlighted Text in Active Tab',
81+
},
82+
searchHighlightedTextInInactiveTab: {
83+
operation: new SearchHighlightedTextOperation(false),
84+
label: 'Search Highlighted Text in Inactive Tab',
85+
},
86+
closeTabsToRight: {
87+
operation: new CloseTabsToRightOperation(),
88+
label: 'Close Tabs to the Right',
89+
}
7690
};
7791

7892
constructor(storage) {
7993
this.#storage = storage;
8094
}
8195

82-
async resolveAsync(gestures) {
83-
const serializedGestures = this.#serializeGestures(gestures);
96+
async resolveAsync(context) {
97+
const serializedGestures = this.#serializeGestures(context.gestures);
8498

8599
const operationKey = this.#storage.getOperationKey(serializedGestures);
86100
if (operationKey === undefined) {
@@ -92,7 +106,7 @@ export class OperationResolver {
92106
}
93107

94108
const element = OperationResolver.operations[operationKey];
95-
await element.operation.doAsync();
109+
await element.operation.doAsync(context);
96110
}
97111

98112
#serializeGestures(gestures) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export class CloseTabsToRightOperation {
2+
async doAsync() {
3+
const [currentTab] = await chrome.tabs.query({ active: true, currentWindow: true });
4+
if (!currentTab?.id) {
5+
return;
6+
}
7+
8+
const allTabs = await chrome.tabs.query({ currentWindow: true });
9+
const tabsToClose = allTabs.filter(tab => tab.index > currentTab.index).map(tab => tab.id);
10+
11+
if (tabsToClose.length > 0) {
12+
chrome.tabs.remove(tabsToClose);
13+
}
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export class SearchHighlightedTextOperation {
2+
#active = false;
3+
4+
constructor(active) {
5+
this.#active = active ?? false;
6+
}
7+
8+
async doAsync(context) {
9+
const selectedText = context?.selectedText?.trim() ?? '';
10+
if (selectedText?.length > 0) {
11+
const query = encodeURIComponent(selectedText);
12+
chrome.tabs.create({ url: `https://www.google.com/search?q=${query}`, active: this.#active });
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)