60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
/**
|
|
* commafeed-tweaks.js
|
|
*
|
|
* Client-side behavior tweaks for CommaFeed (Athou/commafeed), applied from
|
|
* outside the app bundle.
|
|
*
|
|
* Install (either):
|
|
* 1. Paste this file's contents into Settings -> Custom code -> Custom JS.
|
|
* CommaFeed serves it as `custom_js.js` and loads it after the app starts.
|
|
* 2. Serve this file alongside the app and add
|
|
* <script src="commafeed-tweaks.js"></script>
|
|
* to index.html.
|
|
*
|
|
* All listeners attach to `window`, so load timing relative to React doesn't matter.
|
|
*/
|
|
(function () {
|
|
'use strict'
|
|
|
|
if (window.__commafeedTweaksInstalled) return
|
|
window.__commafeedTweaksInstalled = true
|
|
|
|
const log = (...args) => console.debug('[commafeed-tweaks]', ...args)
|
|
|
|
/**
|
|
* Disable swipe-right-to-open the mobile sidebar.
|
|
*
|
|
* Upstream (pages/app/Layout.tsx) wraps the AppShell in a react-swipeable Box
|
|
* whose touch listeners live on that element and open the menu on a rightward
|
|
* swipe. We catch touchmove on window in the capture phase and stop propagation
|
|
* of rightward-horizontal moves so they never reach that element. No
|
|
* preventDefault, so native scrolling is untouched; leftward swipes still pass
|
|
* through, so swipe-left-to-close keeps working.
|
|
*/
|
|
function disableSwipeToOpenMenu() {
|
|
let startX = 0
|
|
let startY = 0
|
|
|
|
window.addEventListener('touchstart', e => {
|
|
const t = e.touches[0]
|
|
if (!t) return
|
|
startX = t.clientX
|
|
startY = t.clientY
|
|
}, { capture: true, passive: true })
|
|
|
|
window.addEventListener('touchmove', e => {
|
|
const t = e.touches[0]
|
|
if (!t) return
|
|
const dx = t.clientX - startX
|
|
const dy = t.clientY - startY
|
|
if (dx > 0 && Math.abs(dx) > Math.abs(dy)) {
|
|
e.stopPropagation()
|
|
}
|
|
}, { capture: true, passive: true })
|
|
|
|
log('swipe-to-open menu disabled')
|
|
}
|
|
|
|
disableSwipeToOpenMenu()
|
|
})()
|