magnet protocol, autostart torrents based on URI, future proofing

This commit is contained in:
ThaUnknown 2020-10-28 15:41:40 +01:00
parent 7fc39fe703
commit 21922f3c31
5 changed files with 32 additions and 6 deletions

View file

@ -312,7 +312,8 @@
<input type="checkbox" id="subtitle3">
<label for="subtitle3">Video Canvas Merging [Displays subtitles in PiP and ChromeCast, requires
<a href="chrome://flags/#disable-accelerated-2d-canvas"
target="_blank">chrome://flags/#disable-accelerated-2d-canvas</a> set to Disabled]</label>
target="_blank">chrome://flags/#disable-accelerated-2d-canvas</a> set to
Disabled]</label>
</div>
@ -348,7 +349,7 @@
<input type="checkbox" id="torrent3">
<label for="torrent3">Trusted Only [Less results but higher quality and more seeders]</label>
</div>
<h1 class="content-title font-size-22">
Other
</h1>
@ -363,12 +364,15 @@
</div>
<div class="custom-switch mb-20">
<input type="checkbox" id="other2">
<label for="other2">AniList Sync [Requires <a href="https://anilist.co/api/v2/oauth/authorize?client_id=4254&response_type=token" target="_top">OAuth2 Login</a>]</label>
<label for="other2">AniList Sync [Requires <a
href="https://anilist.co/api/v2/oauth/authorize?client_id=4254&response_type=token"
target="_top">OAuth2 Login</a>]</label>
</div>
<button class="btn btn-danger" type="button" id="setRes">Restore Defaults</button>
<button class="btn btn-success" type="button" id="regProtButton">Set As Default For Magnet Links</button>
<p class="text-muted">
Restart may be required for some settings to take effect.
</p>

View file

@ -66,6 +66,15 @@ function renderSettings() {
}
})
}
function registerProtocol() {
if ('registerProtocolHandler' in navigator) {
navigator.registerProtocolHandler(
'magnet',
`${location.href.replace(location.hash, '')}#&m=%s`,
'Miru'
);
}
}
if (!localStorage.getItem("settings")) {
restoreDefaults()
@ -74,6 +83,7 @@ settings = JSON.parse(localStorage.getItem("settings"))
renderSettings()
setRes.addEventListener("click", restoreDefaults)
settingsTab.addEventListener("click", applySettings)
regProtButton.addEventListener("click", registerProtocol)
let searchParams = new URLSearchParams(location.href)
if (searchParams.get("access_token")) {

View file

@ -28,7 +28,13 @@ const announceList = [
'.avi', '.mp4', '.m4v', '.webm', '.mov', '.mkv', '.mpg', '.mpeg', '.ogv', '.wmv', '.m2ts'
],
scope = '/app/',
sw = navigator.serviceWorker.register('sw.js', { scope })
sw = navigator.serviceWorker.register('sw.js', { scope }).then(e => {
if (searchParams.get("m")) {
addTorrent(searchParams.get("m"))
}
}).catch(e => {
location.reload()
})
//for debugging
function t(a) {
switch (a) {

View file

@ -57,7 +57,7 @@
<div class="btn btn-primary" role="button" id="add">
Add App
</div>
<a class="btn" role="button" href="/app/">
<a class="btn" role="button" href="/app/#browse">
Open In Browser
</a>
</div>

View file

@ -23,5 +23,11 @@
"scope_url_scheme": "https",
"scope_url_host": "miru.moe",
"scope_url_path": "/app/"
}
},
"protocol_handlers": [
{
"protocol": "magnet",
"url": "/app/#&m=%s"
}
]
}