Skip to content

Commit

Permalink
fix: drop alternative clicks (close #241)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Fish authored and AlPha5130 committed Jan 4, 2024
1 parent 6aa44d2 commit 73a5b46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/module/loadQuickDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { _analytics } from './_analytics'
import { quickDiff } from './quickDiff'
import { quickEdit } from './quickEdit'
import { mwConfig } from './mw'
import { isAlternativeClick } from '../utils/alternativeClick'
const { getParamValue } = mw.util

function injectLinks(container) {
Expand Down Expand Up @@ -87,6 +88,7 @@ function injectLinks(container) {

// 点击事件
$this.on('click', function (e) {
if (isAlternativeClick(e)) return
e.preventDefault()
_analytics('quick_diff_recentchanges')
return quickDiff(params)
Expand All @@ -108,9 +110,7 @@ export function loadQuickDiff(container) {
$('<button>')
.text(_msg('quick-diff'))
.on('click', function (e) {
if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) {
return
}
if (isAlternativeClick(e)) return

e.preventDefault()
_analytics('quick_diff_history_page')
Expand Down
8 changes: 8 additions & 0 deletions src/utils/alternativeClick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @param {MouseEvent} e
* @returns {boolean}
*/
export const isAlternativeClick = (e) => {
const event = e.originalEvent || e
return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey
}

0 comments on commit 73a5b46

Please sign in to comment.