fix: allow native context menu in input elements (#428)

This commit is contained in:
Tuur Lievens 2022-06-05 10:11:39 +02:00 committed by GitHub
parent 8d125db94c
commit b8ad965763
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -9,7 +9,7 @@
<link rel="icon" href="./favicon.ico?s=1">
<title>qBittorrent</title>
</head>
<body oncontextmenu='return false'>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>

View file

@ -37,6 +37,7 @@ export default {
this.$store.commit('SET_APP_VERSION', process.env['APPLICATION_VERSION'])
this.$store.commit('SET_LANGUAGE')
this.checkAuthentication()
this.blockContextMenu()
},
methods: {
async checkAuthentication() {
@ -50,6 +51,20 @@ export default {
this.$store.commit('LOGIN', false)
if (!this.onLoginPage) return this.$router.push('login')
},
blockContextMenu() {
document.addEventListener('contextmenu', event => {
if (!event.target) return
const nodeName = event.target.nodeName.toLowerCase()
const nodeType = event.target.getAttribute('type')
if (nodeName === 'textarea') return
if (nodeName === 'input' && ['text', 'password', 'email', 'number'].includes(nodeType)) return
event.preventDefault()
return false
})
}
}
}