Support removing tracker from all torrents in WebUI/WebAPI

Closes #20661.
PR #21056.
This commit is contained in:
Thomas Piccirello
2024-09-16 02:47:10 -07:00
committed by GitHub
parent d19f7b12d9
commit d2b2afad23
8 changed files with 132 additions and 8 deletions

View File

@@ -644,6 +644,12 @@ window.addEventListener("DOMContentLoaded", () => {
trackerFilterList.appendChild(createLink(TRACKERS_ALL, "QBT_TR(All (%1))QBT_TR[CONTEXT=TrackerFiltersList]", torrentsCount));
trackerFilterList.appendChild(createLink(TRACKERS_TRACKERLESS, "QBT_TR(Trackerless (%1))QBT_TR[CONTEXT=TrackerFiltersList]", trackerlessTorrentsCount));
// Remove unused trackers
for (const [key, { trackerTorrentMap }] of trackerList) {
if (trackerTorrentMap.size === 0)
trackerList.delete(key);
}
// Sort trackers by hostname
const sortedList = [];
trackerList.forEach(({ host, trackerTorrentMap }, hash) => {

View File

@@ -36,6 +36,7 @@ window.qBittorrent.ContextMenu ??= (() => {
TorrentsTableContextMenu: TorrentsTableContextMenu,
CategoriesFilterContextMenu: CategoriesFilterContextMenu,
TagsFilterContextMenu: TagsFilterContextMenu,
TrackersFilterContextMenu: TrackersFilterContextMenu,
SearchPluginsTableContextMenu: SearchPluginsTableContextMenu,
RssFeedContextMenu: RssFeedContextMenu,
RssArticleContextMenu: RssArticleContextMenu,
@@ -604,6 +605,17 @@ window.qBittorrent.ContextMenu ??= (() => {
}
});
const TrackersFilterContextMenu = new Class({
Extends: ContextMenu,
updateMenuItems: function() {
const id = Number(this.options.element.id);
if ((id !== TRACKERS_ALL) && (id !== TRACKERS_TRACKERLESS))
this.showItem("deleteTracker");
else
this.hideItem("deleteTracker");
}
});
const SearchPluginsTableContextMenu = new Class({
Extends: ContextMenu,

View File

@@ -132,6 +132,7 @@ let deleteTorrentsByTagFN = function() {};
let startTorrentsByTrackerFN = function() {};
let stopTorrentsByTrackerFN = function() {};
let deleteTorrentsByTrackerFN = function() {};
let deleteTrackerFN = function() {};
let copyNameFN = function() {};
let copyInfohashFN = function(policy) {};
let copyMagnetLinkFN = function() {};
@@ -1134,6 +1135,33 @@ const initializeWindows = function() {
}
};
deleteTrackerFN = function(trackerHash) {
const trackerHashInt = Number.parseInt(trackerHash, 10);
if ((trackerHashInt === TRACKERS_ALL) || (trackerHashInt === TRACKERS_TRACKERLESS))
return;
const tracker = trackerList.get(trackerHashInt);
const host = tracker.host;
const urls = [...tracker.trackerTorrentMap.keys()];
new MochaUI.Window({
id: "confirmDeletionPage",
title: "QBT_TR(Remove tracker)QBT_TR[CONTEXT=confirmDeletionDlg]",
loadMethod: "iframe",
contentURL: new URI("confirmtrackerdeletion.html").setData("host", host).setData("urls", urls.map(encodeURIComponent).join("|")).toString(),
scrollbars: false,
resizable: true,
maximizable: false,
padding: 10,
width: 424,
height: 100,
onCloseComplete: function() {
updateMainData();
setTrackerFilter(TRACKERS_ALL);
}
});
};
copyNameFN = function() {
const selectedRows = torrentsTable.selectedRowsIds();
const names = [];