🐛 Link jump optimization

This commit is contained in:
Tw93
2024-12-09 19:00:22 +08:00
parent b1e061bc29
commit d494fce6f8

View File

@@ -186,8 +186,7 @@ document.addEventListener('DOMContentLoaded', () => {
const isDownloadRequired = (url, anchorElement, e) => anchorElement.download || e.metaKey || e.ctrlKey || isDownloadLink(url); const isDownloadRequired = (url, anchorElement, e) => anchorElement.download || e.metaKey || e.ctrlKey || isDownloadLink(url);
const handleExternalLink = (e, url) => { const handleExternalLink = (url) => {
e.preventDefault();
invoke('plugin:shell|open', { invoke('plugin:shell|open', {
path: url, path: url,
}); });
@@ -200,10 +199,8 @@ document.addEventListener('DOMContentLoaded', () => {
const detectAnchorElementClick = e => { const detectAnchorElementClick = e => {
const anchorElement = e.target.closest('a'); const anchorElement = e.target.closest('a');
if (anchorElement && anchorElement.href) { if (anchorElement && anchorElement.href) {
if (!anchorElement.target) {
anchorElement.target = '_self';
}
const hrefUrl = new URL(anchorElement.href); const hrefUrl = new URL(anchorElement.href);
const absoluteUrl = hrefUrl.href; const absoluteUrl = hrefUrl.href;
@@ -211,13 +208,19 @@ document.addEventListener('DOMContentLoaded', () => {
// Handling external link redirection, _blank will automatically open. // Handling external link redirection, _blank will automatically open.
if (isExternalLink(absoluteUrl) && (['_new'].includes(anchorElement.target))) { if (isExternalLink(absoluteUrl) && (['_new'].includes(anchorElement.target))) {
handleExternalLink(e, absoluteUrl); handleExternalLink(absoluteUrl);
return; return;
} }
// Process download links for Rust to handle. // Process download links for Rust to handle.
if (isDownloadRequired(absoluteUrl, anchorElement, e) && !externalDownLoadLink() && !isSpecialDownload(absoluteUrl)) { if (isDownloadRequired(absoluteUrl, anchorElement, e) && !externalDownLoadLink() && !isSpecialDownload(absoluteUrl)) {
handleDownloadLink(e, absoluteUrl, filename); handleDownloadLink(e, absoluteUrl, filename);
return;
}
// App internal jump.
if (!anchorElement.target) {
location.href = anchorElement.href;
} }
} }
}; };
@@ -239,7 +242,7 @@ document.addEventListener('DOMContentLoaded', () => {
} else { } else {
const baseUrl = window.location.origin + window.location.pathname; const baseUrl = window.location.origin + window.location.pathname;
const hrefUrl = new URL(url, baseUrl); const hrefUrl = new URL(url, baseUrl);
handleExternalLink(e, hrefUrl.href); handleExternalLink(hrefUrl.href);
} }
// Call the original window.open function to maintain its normal functionality. // Call the original window.open function to maintain its normal functionality.
return originalWindowOpen.call(window, url, name, specs); return originalWindowOpen.call(window, url, name, specs);