Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjj1024 committed Dec 27, 2024
1 parent a58e6ea commit 81d0d2d
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src-tauri/src/extension/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function zoomOut() {
}

function handleShortcut(event) {
console.log('event.key')
if (shortcuts[event.key]) {
event.preventDefault()
shortcuts[event.key]()
Expand All @@ -38,6 +39,7 @@ function handleShortcut(event) {

// Judgment of file download.
function isDownloadLink(url) {
console.log('is download link', url)
const fileExtensions = [
'3gp',
'7z',
Expand Down Expand Up @@ -113,7 +115,18 @@ function externalTargetLink() {
return ['zbook.lol'].indexOf(location.hostname) > -1
}

document.addEventListener('keyup', (event) => {
console.log('add event listener keyup', event)
if (/windows|linux/i.test(navigator.userAgent) && event.ctrlKey) {
handleShortcut(event)
}
if (/macintosh|mac os x/i.test(navigator.userAgent) && event.metaKey) {
handleShortcut(event)
}
})

document.addEventListener('DOMContentLoaded', () => {
console.log('eventjs DOMContentLoaded------')
const tauri = window.__TAURI__
const appWindow = tauri.window.appWindow
const invoke = tauri.tauri.invoke
Expand All @@ -140,15 +153,6 @@ document.addEventListener('DOMContentLoaded', () => {
})
})

document.addEventListener('keyup', (event) => {
if (/windows|linux/i.test(navigator.userAgent) && event.ctrlKey) {
handleShortcut(event)
}
if (/macintosh|mac os x/i.test(navigator.userAgent) && event.metaKey) {
handleShortcut(event)
}
})

// Collect blob urls to blob by overriding window.URL.createObjectURL
function collectUrlToBlobs() {
const backupCreateObjectURL = window.URL.createObjectURL
Expand Down Expand Up @@ -207,15 +211,17 @@ document.addEventListener('DOMContentLoaded', () => {

// detect blob download by createElement("a")
function detectDownloadByCreateAnchor() {
console.log('detectDownloadByCreateAnchor')
const createEle = document.createElement

document.createElement = (el) => {
if (el !== 'a') return createEle.call(document, el)
const anchorEle = createEle.call(document, el)

// use addEventListener to avoid overriding the original click event.
anchorEle.addEventListener(
'click',
(e) => {
console.log('anchorEle.addEventListener')
const url = anchorEle.href
const filename =
anchorEle.download || getFilenameFromUrl(url)
Expand Down Expand Up @@ -247,25 +253,27 @@ document.addEventListener('DOMContentLoaded', () => {
anchorElement.download || e.metaKey || e.ctrlKey || isDownloadLink(url)

const handleExternalLink = (e, url) => {
console.log('handleExternalLink')
console.log('handleExternalLink----')
e.preventDefault()
tauri.shell.open(url)
}

const handleDownloadLink = (e, url, filename) => {
console.log('handleDownloadLink----')
e.preventDefault()
invoke('download_file', { params: { url, filename } })
}

const detectAnchorElementClick = (e) => {
console.log('detectAnchorElementClick----')
const anchorElement = e.target.closest('a')
console.log('anchorElement--', anchorElement.href)
if (anchorElement && anchorElement.href) {
anchorElement.target = '_self'
const hrefUrl = new URL(anchorElement.href)
const absoluteUrl = hrefUrl.href
let filename =
anchorElement.download || getFilenameFromUrl(absoluteUrl)

// Handling external link redirection.
if (
isExternalLink(absoluteUrl) &&
Expand Down

0 comments on commit 81d0d2d

Please sign in to comment.