mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-30 08:24:22 +00:00
Register protocol handler in WebUI for magnet links
This commit is contained in:
parent
18be4732b3
commit
d49379789a
@ -677,6 +677,7 @@ window.addEvent('load', function() {
|
|||||||
loadMethod: 'xhr',
|
loadMethod: 'xhr',
|
||||||
contentURL: 'transferlist.html',
|
contentURL: 'transferlist.html',
|
||||||
onContentLoaded: function() {
|
onContentLoaded: function() {
|
||||||
|
handleDownloadParam();
|
||||||
updateMainData();
|
updateMainData();
|
||||||
},
|
},
|
||||||
column: 'mainColumn',
|
column: 'mainColumn',
|
||||||
@ -781,8 +782,48 @@ window.addEvent('load', function() {
|
|||||||
addMainWindowTabsEventListener();
|
addMainWindowTabsEventListener();
|
||||||
addSearchPanel();
|
addSearchPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerMagnetHandler();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function registerMagnetHandler() {
|
||||||
|
if (typeof navigator.registerProtocolHandler !== 'function')
|
||||||
|
return;
|
||||||
|
|
||||||
|
const hashParams = getHashParamsFromUrl();
|
||||||
|
hashParams.download = '';
|
||||||
|
|
||||||
|
const templateHashString = Object.toQueryString(hashParams).replace('download=', 'download=%s');
|
||||||
|
|
||||||
|
const templateUrl = location.origin + location.pathname
|
||||||
|
+ location.search + '#' + templateHashString;
|
||||||
|
|
||||||
|
navigator.registerProtocolHandler('magnet', templateUrl,
|
||||||
|
'qBittorrent WebUI magnet handler');
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDownloadParam() {
|
||||||
|
// Extract torrent URL from download param in WebUI URL hash
|
||||||
|
const hashParams = getHashParamsFromUrl();
|
||||||
|
const url = hashParams.download;
|
||||||
|
if (!url)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Remove the download param from WebUI URL hash
|
||||||
|
delete hashParams.download;
|
||||||
|
let newHash = Object.toQueryString(hashParams);
|
||||||
|
newHash = newHash ? ('#' + newHash) : '';
|
||||||
|
history.replaceState('', document.title,
|
||||||
|
(location.pathname + location.search + newHash));
|
||||||
|
|
||||||
|
showDownloadPage([url]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHashParamsFromUrl() {
|
||||||
|
const hashString = location.hash ? location.hash.replace(/^#/, '') : '';
|
||||||
|
return (hashString.length > 0) ? String.parseQueryString(hashString) : {};
|
||||||
|
}
|
||||||
|
|
||||||
function closeWindows() {
|
function closeWindows() {
|
||||||
MochaUI.closeAll();
|
MochaUI.closeAll();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user