Skip to content

Commit 1bd0710

Browse files
committed
feat: add torrent a specific server via context menu
1 parent 6f56913 commit 1bd0710

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

src/_locales/en/messages.json

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
"message": "Add torrent with path",
7676
"description": "Context menu action"
7777
},
78+
"addTorrentServerAction": {
79+
"message": "Add torrent to server",
80+
"description": "Context menu action"
81+
},
7882
"addRssFeedAction": {
7983
"message": "Add RSS feed",
8084
"description": "Context menu action"

src/_locales/fi/messages.json

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
"message": "Lisää torrent polulla",
7676
"description": "Context menu action"
7777
},
78+
"addTorrentServerAction": {
79+
"message": "Lisää torrent palvelimelle",
80+
"description": "Context menu action"
81+
},
7882
"addRssFeedAction": {
7983
"message": "Lisää RSS-syöte",
8084
"description": "Context menu action"

src/_locales/ru/messages.json

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
"message": "Добавить торрент (Путь)",
7676
"description": "Context menu action"
7777
},
78+
"addTorrentServerAction": {
79+
"message": "Add torrent to server",
80+
"description": "Context menu action"
81+
},
7882
"addRssFeedAction": {
7983
"message": "Добавить RSS-канал",
8084
"description": "Context menu action"

src/index.js

+28
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,23 @@ const createContextMenu = () => {
257257
});
258258
});
259259
}
260+
261+
if (options.servers.length > 1) {
262+
chrome.contextMenus.create({
263+
id: 'add-torrent-server',
264+
title: chrome.i18n.getMessage('addTorrentServerAction'),
265+
contexts: ['link'],
266+
});
267+
268+
options.servers.forEach((server, i) => {
269+
chrome.contextMenus.create({
270+
id: 'add-torrent-server-' + i.toString(),
271+
parentId: 'add-torrent-server',
272+
title: server.name,
273+
contexts: ['link'],
274+
});
275+
});
276+
}
260277
} else if (client.clientCapabilities) {
261278
if (client.clientCapabilities.includes('label') && options.globals.labels.length) {
262279
chrome.contextMenus.create({
@@ -314,6 +331,7 @@ const registerHandler = () => {
314331
const currentServer = info.menuItemId.match(/^current-server-(\d+)$/);
315332
const labelId = info.menuItemId.match(/^add-torrent-label-(\d+)$/);
316333
const pathId = info.menuItemId.match(/^add-torrent-path-(\d+)$/);
334+
const serverId = info.menuItemId.match(/^add-torrent-server-(\d+)$/);
317335

318336
const clientOptions = options.servers[options.globals.currentServer].clientOptions || {};
319337

@@ -343,6 +361,16 @@ const registerHandler = () => {
343361
path: options.servers[options.globals.currentServer].directories[~~pathId[1]],
344362
...clientOptions
345363
});
364+
else if (serverId) {
365+
const selectedServerId = parseInt(serverId[1], 10);
366+
const selectedClientOptions = options.servers[selectedServerId].clientOptions || {};
367+
368+
addTorrent(info.linkUrl, tab.id, {
369+
paused: options.globals.addPaused,
370+
server: selectedServerId,
371+
...selectedClientOptions,
372+
});
373+
}
346374
else if (info.menuItemId === 'add-torrent-advanced')
347375
addAdvancedDialog(info.linkUrl, !isMagnetUrl(info.linkUrl) ? tab.id : null);
348376
else if (currentServer)

0 commit comments

Comments
 (0)