2 #searchPluginsContainer {
3 height: calc(
100% -
20px);
8 #searchPluginsContainer button {
12 #searchPluginsContainer span {
19 height: calc(
100% -
150px);
22 #searchPluginsTable .dynamicTable {
26 #searchPluginsTableDiv {
27 height: calc(
100% -
26px);
30 #dynamicTableFixedHeaderDiv {
34 #searchPlugins_content {
40 <div id=
"searchPluginsContainer">
41 <h2>QBT_TR(Installed search plugins:)QBT_TR[CONTEXT=PluginSelectDlg]
</h2>
43 <div id=
"searchPluginsTable">
44 <div id=
"searchPluginsTableFixedHeaderDiv" class=
"dynamicTableFixedHeaderDiv">
45 <table class=
"dynamicTable unselectable" style=
"position:relative;">
47 <tr class=
"dynamicTableHeader" id=
"searchPluginsTableFixedHeaderRow"></tr>
51 <div id=
"searchPluginsTableDiv" class=
"dynamicTableDiv">
52 <table class=
"dynamicTable unselectable">
54 <tr class=
"dynamicTableHeader"></tr>
61 <span>QBT_TR(Warning: Be sure to comply with your country's copyright laws when downloading torrents from any of these search engines.)QBT_TR[CONTEXT=PluginSelectDlg]
</span>
62 <span style=
"font-style: italic;">QBT_TR(You can get new search engine plugins here:)QBT_TR[CONTEXT=PluginSelectDlg]
<a href=
"https://plugins.qbittorrent.org" target=
"_blank">https://plugins.qbittorrent.org
</a></span>
63 <div style=
"width: 100%; margin-top: 10px;">
64 <button type=
"button" style=
"width: 33%; line-height: 1.4em;" onclick=
"qBittorrent.SearchPlugins.installPlugin();">QBT_TR(Install new plugin)QBT_TR[CONTEXT=PluginSelectDlg]
</button>
65 <button type=
"button" style=
"width: 33%; line-height: 1.4em;" onclick=
"qBittorrent.SearchPlugins.checkForUpdates();">QBT_TR(Check for updates)QBT_TR[CONTEXT=PluginSelectDlg]
</button>
66 <button type=
"button" style=
"width: 32%; line-height: 1.4em;" onclick=
"qBittorrent.SearchPlugins.closeSearchWindow('searchPlugins');">QBT_TR(Close)QBT_TR[CONTEXT=PluginSelectDlg]
</button>
70 <ul id=
"searchPluginsTableMenu" class=
"contextMenu">
71 <li><a href=
"#Enabled"><img src=
"images/checked-completed.svg" alt=
"QBT_TR(Enabled)QBT_TR[CONTEXT=PluginSelectDlg]"> QBT_TR(Enabled)QBT_TR[CONTEXT=PluginSelectDlg]
</a></li>
72 <li class=
"separator"><a href=
"#Uninstall"><img src=
"images/list-remove.svg" alt=
"QBT_TR(Uninstall)QBT_TR[CONTEXT=PluginSelectDlg]"> QBT_TR(Uninstall)QBT_TR[CONTEXT=PluginSelectDlg]
</a></li>
78 window
.qBittorrent
??= {};
79 window
.qBittorrent
.SearchPlugins
??= (() => {
80 const exports
= () => {
82 closeSearchWindow
: closeSearchWindow
,
84 installPlugin
: installPlugin
,
85 checkForUpdates
: checkForUpdates
,
86 updateTable
: updateTable
90 let searchPluginsTable
;
91 let searchPluginsTableContextMenu
;
95 const setup = function() {
96 searchPluginsTable
= new window
.qBittorrent
.DynamicTable
.SearchPluginsTable();
97 searchPluginsTableContextMenu
= new window
.qBittorrent
.ContextMenu
.SearchPluginsTableContextMenu({
98 targets
: ".searchPluginsTableRow",
99 menu
: "searchPluginsTableMenu",
101 Enabled
: enablePlugin
,
102 Uninstall
: uninstallPlugin
104 offsets
: calculateContextMenuOffsets()
106 searchPluginsTable
.setup("searchPluginsTableDiv", "searchPluginsTableFixedHeaderDiv", searchPluginsTableContextMenu
);
110 const closeSearchWindow = function(id
) {
111 window
.parent
.MochaUI
.closeWindow(window
.parent
.$(id
));
114 const installPlugin = function(path
) {
116 id
: "installSearchPlugin",
117 icon
: "images/qbittorrent-tray.svg",
118 title
: "QBT_TR(Install plugin)QBT_TR[CONTEXT=PluginSourceDlg]",
120 contentURL
: "views/installsearchplugin.html",
125 paddingHorizontal
: 0,
131 const uninstallPlugin = function() {
132 const plugins
= searchPluginsTable
.selectedRowsIds().join("|");
133 const url
= new URI("api/v2/search/uninstallPlugin");
143 const enablePlugin = function() {
144 const plugins
= searchPluginsTable
.selectedRowsIds();
146 if (plugins
&& plugins
.length
)
147 enable
= !window
.qBittorrent
.Search
.getPlugin(plugins
[0]).enabled
;
149 const url
= new URI("api/v2/search/enablePlugin");
154 names
: plugins
.join("|"),
160 const checkForUpdates = function() {
161 const url
= new URI("api/v2/search/updatePlugins");
168 const calculateContextMenuOffsets = function() {
169 prevOffsetLeft
= document
.getElementById("searchPlugins").getBoundingClientRect().left
;
170 prevOffsetTop
= document
.getElementById("searchPlugins").getBoundingClientRect().top
;
173 x
: -(prevOffsetLeft
+ 20),
174 y
: -(prevOffsetTop
+ 2)
178 const updateSearchPluginsTableContextMenuOffset = function() {
179 // only re-calculate if window has moved
180 if ((prevOffsetLeft
!== document
.getElementById("searchPlugins").getBoundingClientRect().left
) || (prevOffsetTop
!== document
.getElementById("searchPlugins").getBoundingClientRect().top
))
181 searchPluginsTableContextMenu
.options
.offsets
= calculateContextMenuOffsets();
184 const setupSearchPluginTableEvents = function(enable
) {
185 const clickHandler
= (e
) => { enablePlugin(); };
186 const menuHandler
= (e
) => { updateSearchPluginsTableContextMenuOffset(); };
188 $$(".searchPluginsTableRow").each((target
) => {
189 target
.addEventListener("dblclick", clickHandler
);
190 target
.addEventListener("contextmenu", menuHandler
, true);
194 $$(".searchPluginsTableRow").each((target
) => {
195 target
.removeEventListener("dblclick", clickHandler
);
196 target
.removeEventListener("contextmenu", menuHandler
, true);
201 const updateTable = function() {
202 // clear event listeners
203 setupSearchPluginTableEvents(false);
205 const oldPlugins
= Object
.keys(searchPluginsTable
.rows
);
206 // remove old rows from the table
207 for (let i
= 0; i
< oldPlugins
.length
; ++i
) {
209 for (let j
= 0; j
< window
.qBittorrent
.Search
.searchPlugins
.length
; ++j
) {
210 if (window
.qBittorrent
.Search
.searchPlugins
[j
].name
=== oldPlugins
[i
]) {
216 searchPluginsTable
.removeRow(oldPlugins
[i
]);
219 for (let i
= 0; i
< window
.qBittorrent
.Search
.searchPlugins
.length
; ++i
) {
220 window
.qBittorrent
.Search
.searchPlugins
[i
].rowId
= window
.qBittorrent
.Search
.searchPlugins
[i
].name
;
221 searchPluginsTable
.updateRowData(window
.qBittorrent
.Search
.searchPlugins
[i
]);
224 searchPluginsTable
.updateTable();
226 // add event listeners
227 setupSearchPluginTableEvents(true);
232 Object
.freeze(window
.qBittorrent
.SearchPlugins
);
234 window
.qBittorrent
.SearchPlugins
.setup();