Skip to content

Commit

Permalink
🐛 Fix the problem of external jump
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed Sep 11, 2024
1 parent a285a83 commit 4521192
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src-tauri/src/inject/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function isDownloadLink(url) {
'3gp', '7z', 'ai', 'apk', 'avi', 'bmp', 'csv', 'dmg', 'doc', 'docx',
'fla', 'flv', 'gif', 'gz', 'gzip', 'ico', 'iso', 'indd', 'jar', 'jpeg',
'jpg', 'm3u8', 'mov', 'mp3', 'mp4', 'mpa', 'mpg', 'mpeg', 'msi', 'odt',
'ogg', 'ogv', 'pdf', 'png', 'ppt', 'pptx', 'psd', 'rar', 'raw', 'rss',
'ogg', 'ogv', 'pdf', 'png', 'ppt', 'pptx', 'psd', 'rar', 'raw',
'svg', 'swf', 'tar', 'tif', 'tiff', 'ts', 'txt', 'wav', 'webm', 'webp',
'wma', 'wmv', 'xls', 'xlsx', 'xml', 'zip', 'json', 'yaml', '7zip', 'mkv'
];
Expand All @@ -56,10 +56,6 @@ function externalDownLoadLink() {
return ['quickref.me'].indexOf(location.hostname) > -1;
}

// Directly jumping out without hostname address.
function externalTargetLink() {
return ['zbook.lol'].indexOf(location.hostname) > -1;
}

document.addEventListener('DOMContentLoaded', () => {
const tauri = window.__TAURI__;
Expand Down Expand Up @@ -176,8 +172,6 @@ document.addEventListener('DOMContentLoaded', () => {
// case: download from dataURL -> convert dataURL ->
} else if (url.startsWith('data:')) {
downloadFromDataUri(url, filename);
} else if (isDownloadLink(url) || anchorEle.host !== window.location.host) {
handleExternalLink(e, url);
}
},
true,
Expand All @@ -187,7 +181,6 @@ document.addEventListener('DOMContentLoaded', () => {
};
}

const isExternalLink = link => window.location.host !== link.host;
// process special download protocol['data:','blob:']
const isSpecialDownload = url => ['blob', 'data'].some(protocol => url.startsWith(protocol));

Expand All @@ -214,12 +207,6 @@ document.addEventListener('DOMContentLoaded', () => {
const absoluteUrl = hrefUrl.href;
let filename = anchorElement.download || getFilenameFromUrl(absoluteUrl);

// Handling external link redirection.
if ((isExternalLink(absoluteUrl) && ['_blank', '_new'].includes(anchorElement.target)) || externalTargetLink()) {
handleExternalLink(e, absoluteUrl);
return;
}

// Process download links for Rust to handle.
if (isDownloadRequired(absoluteUrl, anchorElement, e) && !externalDownLoadLink() && !isSpecialDownload(absoluteUrl)) {
handleDownloadLink(e, absoluteUrl, filename);
Expand Down

0 comments on commit 4521192

Please sign in to comment.