Disable double tap to edit on mobile

Save this as a .js file and point CodeScript ToolKit to it as your “Startup script path.” It’ll make it so that double tapping in reading mode no longer switches to editing mode.

exports.invoke = async (app) => {
    window.addEventListener('pointerdown', (e) => {
        const isReader = e.target.closest('.markdown-reading-view');
        if (!isReader) return;

        if (e.pointerType === 'touch') {
            Object.defineProperty(e, 'pointerType', {
                get: function() { return 'mouse'; },
                configurable: true
            });
        }
    }, { capture: true, passive: true });
};
2 Likes

Here’s a version that restores[1] the double tap to select word behavior:

exports.invoke = async (app) => {
	let lastTap = 0;

	window.addEventListener('pointerdown', (e) => {
		const isReader = e.target.closest('.markdown-reading-view');
		if (!isReader || e.pointerType !== 'touch') return;

		Object.defineProperty(e, 'pointerType', { get: () => 'mouse', configurable: true });

		const now = Date.now();
		if (now - lastTap < 300) {
			const sel = window.getSelection();
			const range = document.caretRangeFromPoint(e.clientX, e.clientY);
			if (sel && range) {
				sel.removeAllRanges();
				sel.addRange(range);
				sel.modify("move", "backward", "word");
				sel.modify("extend", "forward", "word");
			}
		}
		lastTap = now;
	}, { capture: true });
};

  1. Or, rather, re-creates. ↩︎