Skip to content

Commit 8627907

Browse files
committed
[AniLINK] enhance referer handling for MPV playback and improve download fallback
1 parent 5990614 commit 8627907

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

AniLINK/AniLINK_Episode-Link-Extractor.user.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,13 +1324,14 @@ async function extractEpisodes() {
13241324
});
13251325
epnumSpan.addEventListener('click', e => {
13261326
e.preventDefault();
1327-
location.replace(`${MPV_PROTOCOL}://play/` + safeBtoa(link) + `/?v_title=${safeBtoa(name)}&cookies=${location.hostname}.txt` + (ep.links[quality].tracks?.some(t => t.kind === 'caption') ? `&subfile=${safeBtoa(ep.links[quality].tracks.filter(t => /^caption/.test(t.kind)).map(t => t.file).join(';'))}` : ''));
1327+
location.replace(`${MPV_PROTOCOL}://play/` + safeBtoa(link) + `/?v_title=${safeBtoa(name)}&cookies=${location.hostname}.txt&referer=${safeBtoa(ep.links[quality].referer || location.href)}` + (ep.links[quality].tracks?.some(t => t.kind === 'caption') ? `&subfile=${safeBtoa(ep.links[quality].tracks.filter(t => /^caption/.test(t.kind)).map(t => t.file).join(';'))}` : ''));
13281328
showToast('Sent to MPV. If nothing happened, install v0.4.0+ of <a href="https://github.com/akiirui/mpv-handler" target="_blank" style="color:#1976d2;">mpv-handler</a>.');
13291329
});
13301330
episodeLinkElement.addEventListener('click', () => {
13311331
fetch(episodeLinkElement.href)
13321332
.then(r => r.blob())
1333-
.then(b => Object.assign(document.createElement('a'), { href: URL.createObjectURL(b), download: decodeURIComponent(episodeLinkElement.download) }).click()); // workaround to force download with correct filename (some browsers ignore download attr for cross-origin links)
1333+
.then(b => Object.assign(document.createElement('a'), { href: URL.createObjectURL(b), download: decodeURIComponent(episodeLinkElement.download) }).click()) // workaround to force download with correct filename (some browsers ignore download attr for cross-origin links)
1334+
.catch(err => window.open(episodeLinkElement.href, '_blank') && showToast(`Could not download file directly, opened in new tab instead. Error: ${err}`));
13341335
});
13351336

13361337
// Subtitle toggle functionality

0 commit comments

Comments
 (0)