Skip to content

Commit

Permalink
fix: drop alternative clicks (close #241) (#243)
Browse files Browse the repository at this point in the history
* fix: drop alternative clicks (close #241)

* chore: rename files

* fix: edge case of Safari

---------

Co-authored-by: Dragon-Fish <[email protected]>
  • Loading branch information
dragon-fish and Dragon-Fish authored Jan 4, 2024
1 parent 6aa44d2 commit b02a4fb
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/method/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import _dir from './_dir'
import { loadScript } from './loadScript'
import { initQueryData } from './initQueryData'
import { loadStyles } from './loadStyles'
import { updateNotice } from './updateNotice'
import { syncI18nData } from './syncI18nData'

import version from '../module/version'
Expand All @@ -27,6 +26,7 @@ import { quickPreview } from '../module/quickPreview'
import { quickRedirect } from '../module/quickRedirect'
import { quickRename } from '../module/quickRename'
import { specialNotice } from '../module/specialNotice'
import { updateNotice } from '../module/updateNotice'
import { versionInfo } from '../module/versionInfo'

/**
Expand Down
2 changes: 1 addition & 1 deletion src/module/_analytics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { analyticsApi } from './endpoints'
import { preference } from './preference'
import { mwConfig } from './mw'
import { mwConfig } from '../utils/mw'
import version from './version'

/**
Expand Down
4 changes: 2 additions & 2 deletions src/module/_resolveExists.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { _msg } from './_msg'
import { _hasRight } from './_hasRight'
import { hasRight } from '../utils/hasRight'
import { quickDelete } from './quickDelete'
import { quickEdit } from './quickEdit'

Expand All @@ -11,7 +11,7 @@ import { quickEdit } from './quickEdit'
* @param {String} reason.edit 编辑原因
*/
export const _resolveExists = function (page, reason = {}) {
const canDelete = _hasRight('delete')
const canDelete = hasRight('delete')

if (typeof reason === 'string') {
reason = {
Expand Down
2 changes: 1 addition & 1 deletion src/module/linksHere.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { _analytics } from './_analytics'
import { $progress, $link } from './_elements'
import { _msg } from './_msg'
import { mwApi, mwConfig } from './mw'
import { mwApi, mwConfig } from '../utils/mw'
import { quickEdit } from './quickEdit'

/**
Expand Down
8 changes: 4 additions & 4 deletions src/module/loadQuickDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { _msg } from './_msg'
import { _analytics } from './_analytics'
import { quickDiff } from './quickDiff'
import { quickEdit } from './quickEdit'
import { mwConfig } from './mw'
import { mwConfig } from '../utils/mw'
import { isPureLMBClick } from '../utils/mouseEvent'
const { getParamValue } = mw.util

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

// 点击事件
$this.on('click', function (e) {
if (!isPureLMBClick(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 (!isPureLMBClick(e)) return

e.preventDefault()
_analytics('quick_diff_history_page')
Expand Down
6 changes: 3 additions & 3 deletions src/module/quickDelete.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { _analysis } from './_analytics'
import { _msg } from './_msg'
import { _hasRight } from './_hasRight'
import { hasRight } from '../utils/hasRight'
import { $br } from './_elements'
import { mwApi, mwConfig } from './mw'
import { mwApi, mwConfig } from '../utils/mw'

/**
* @module quickDelete 删除页面模块
Expand Down Expand Up @@ -36,7 +36,7 @@ export function quickDelete(page, givenReason = '') {
)
),
beforeShow: function () {
if (!_hasRight('delete')) {
if (!hasRight('delete')) {
ssi_modal.dialog({
title: _msg('notify-no-right'),
content: _msg('delete-no-right'),
Expand Down
2 changes: 1 addition & 1 deletion src/module/quickDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { _analysis } from './_analytics'
import { _msg } from './_msg'
import { $br, $progress } from './_elements'
import { articleLink } from './articleLink'
import { mwApi } from './mw'
import { mwApi } from '../utils/mw'

/**
* @module quickDiff 快速页面差异模块
Expand Down
10 changes: 5 additions & 5 deletions src/module/quickEdit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mwApi, mwConfig } from './mw'
import { mwApi, mwConfig } from '../utils/mw'

import { _analysis } from './_analytics'
import { _msg } from './_msg'
import { _hasRight } from './_hasRight'
import { hasRight } from '../utils/hasRight'

import { $br, $progress } from './_elements'

Expand Down Expand Up @@ -397,7 +397,7 @@ export function quickEdit(options) {
})
})
// 获取权限
if (!_hasRight('edit')) {
if (!hasRight('edit')) {
ssi_modal.notify('dialog', {
className: 'in-page-edit',
position: 'center bottom',
Expand Down Expand Up @@ -588,7 +588,7 @@ export function quickEdit(options) {
if (options.protection.length > 0) {
const isEditable = (level) => {
if (!level) return true
return _hasRight(
return hasRight(
level
.replace('sysop', 'editprotected')
.replace('autoconfirmed', 'editsemiprotected')
Expand All @@ -599,7 +599,7 @@ export function quickEdit(options) {
)
if (
!isEditable(protectionEdit?.level) ||
(options.namespace === 8 && !_hasRight('editinterface'))
(options.namespace === 8 && !hasRight('editinterface'))
) {
$modalWindow
.find('.save-btn')
Expand Down
2 changes: 1 addition & 1 deletion src/module/quickPreview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { _msg } from './_msg'
import { $progress } from './_elements'
import { mwApi } from './mw'
import { mwApi } from '../utils/mw'

/**
* @module quickPreview 快速预览文章页
Expand Down
2 changes: 1 addition & 1 deletion src/module/quickRedirect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { _analysis } from './_analytics'
import { _msg } from './_msg'
import { $br, $progress } from './_elements'
import { mwApi, mwConfig } from './mw'
import { mwApi, mwConfig } from '../utils/mw'
import { _resolveExists } from './_resolveExists'
import { preference } from './preference'

Expand Down
8 changes: 4 additions & 4 deletions src/module/quickRename.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { _analysis } from './_analytics'
import { _msg } from './_msg'
import { _hasRight } from './_hasRight'
import { hasRight } from '../utils/hasRight'
import { _resolveExists } from './_resolveExists'
import { $br } from './_elements'
import { mwApi, mwConfig } from './mw'
import { mwApi, mwConfig } from '../utils/mw'
import { progress } from './progress'

/**
Expand Down Expand Up @@ -58,7 +58,7 @@ export function quickRename(from, to) {
$('<input>', {
type: 'checkbox',
id: 'noredirect',
disabled: !_hasRight('suppressredirect'),
disabled: !hasRight('suppressredirect'),
}),
$('<span>', { text: _msg('rename-noredirect') })
)
Expand Down Expand Up @@ -150,7 +150,7 @@ export function quickRename(from, to) {
},
],
beforeShow: function () {
if (!_hasRight('move')) {
if (!hasRight('move')) {
ssi_modal.dialog({
title: _msg('notify-no-right'),
content: _msg('rename-no-right'),
Expand Down
2 changes: 1 addition & 1 deletion src/module/syncPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// 将 IPE 的参数设置保存在数据库内,实现多端同步
// ========================================= //

import { mwApi } from './mw'
import { mwApi } from '../utils/mw'

/**
* @param {string} name
Expand Down
3 changes: 0 additions & 3 deletions src/module/test.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/method/updateNotice.js → src/module/updateNotice.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import version from '../module/version'
import version from './version'

import { _msg } from '../module/_msg'
import { versionInfo } from '../module/versionInfo'
import { specialNotice } from '../module/specialNotice'
import { _msg } from './_msg'
import { versionInfo } from './versionInfo'
import { specialNotice } from './specialNotice'

export function updateNotice() {
if (localStorage.getItem('InPageEditVersion') !== version) {
Expand Down
3 changes: 1 addition & 2 deletions src/module/version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import { version } from '../../package.json'
export default version
export { version as default } from '../../package.json'
4 changes: 3 additions & 1 deletion src/module/_hasRight.js → src/utils/hasRight.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param {string} right
* @return {boolean}
*/
export const _hasRight = function (right) {
export const hasRight = function (right) {
const conf = window.mw.config.get()
console.info(
'[InPageEdit] _hasRight',
Expand All @@ -16,3 +16,5 @@ export const _hasRight = function (right) {
}
return (conf.wgUserRights || []).includes(right)
}
// KEEP THIS
export { hasRight as _hasRight }
17 changes: 17 additions & 0 deletions src/utils/mouseEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @param {MouseEvent} e
* @returns {boolean}
*/
export const isAlternativeClick = (e) => {
const event = e.originalEvent || e
return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey
}

/**
* @param {MouseEvent} e
* @returns {boolean}
*/
export const isPureLMBClick = (e) => {
const event = e.originalEvent || e
return event.button === 0 && !isAlternativeClick(e)
}
2 changes: 1 addition & 1 deletion src/module/mw.js → src/utils/mw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import version from './version'
import version from '../module/version'

export const mwConfig = mw.config.get()
export const mwApi = new mw.Api({
Expand Down

0 comments on commit b02a4fb

Please sign in to comment.