diff --git a/src/content/content.ts b/src/content/content.ts index 4a9caff58b..8097b3210d 100644 --- a/src/content/content.ts +++ b/src/content/content.ts @@ -2088,9 +2088,10 @@ export class ContentHandler { } else if (dictToShow === 'prev') { dict = this.currentDict; - let prev = - (cycleOrder.length + (cycleOrder.indexOf(this.currentDict) - 1)) % - cycleOrder.length; + let prev = mod( + cycleOrder.indexOf(this.currentDict) - 1, + cycleOrder.length + ); while (cycleOrder[prev] !== this.currentDict) { const prevDict = cycleOrder[prev]; if ( @@ -2100,7 +2101,7 @@ export class ContentHandler { dict = prevDict; break; } - prev = --prev % cycleOrder.length; + prev = mod(--prev, cycleOrder.length); } } else { dict = dictToShow; diff --git a/src/content/popup/popup.ts b/src/content/popup/popup.ts index 2487310c74..3ccc04e201 100644 --- a/src/content/popup/popup.ts +++ b/src/content/popup/popup.ts @@ -32,11 +32,11 @@ import { renderKanjiEntries } from './kanji'; import { renderMetadata } from './metadata'; import { renderNamesEntries } from './names'; import { renderCopyDetails, renderUpdatingStatus } from './status'; +import { onHorizontalSwipe } from './swipe'; import { renderTabBar } from './tabs'; import { renderWordEntries } from './words'; import popupStyles from '../../../css/popup.css'; -import { onHorizontalSwipe } from './swipe'; export type StartCopyCallback = ( index: number, @@ -126,7 +126,9 @@ export function renderPopup( windowElem.dataset.tabSide = options.tabDisplay || 'top'; + console.log('Hello1'); onHorizontalSwipe(contentContainer, (direction) => { + console.log('Hello?'); if (options.onSwitchDictionary) { options.onSwitchDictionary(direction === 'left' ? 'prev' : 'next'); } diff --git a/src/content/popup/swipe.ts b/src/content/popup/swipe.ts index b39c17d584..c7c0738262 100644 --- a/src/content/popup/swipe.ts +++ b/src/content/popup/swipe.ts @@ -21,7 +21,7 @@ export function onHorizontalSwipe( function (e) { startX = e.changedTouches[0].pageX; startY = e.changedTouches[0].pageY; - startTime = Date.now(); + startTime = performance.now(); }, false ); @@ -41,7 +41,7 @@ export function onHorizontalSwipe( const touch = e.changedTouches[0]; const deltaX = touch.pageX - startX; const deltaY = touch.pageY - startY; - const elapsedTime = Date.now() - startTime; + const elapsedTime = performance.now() - startTime; // Check that elapsed time is within specified, horizontal dist // traveled >= threshold, and vertical dist traveled <= 100 @@ -50,8 +50,7 @@ export function onHorizontalSwipe( Math.abs(deltaX) >= xMinThreshold && Math.abs(deltaY) <= yMaxThreshold; if (isSwipe) { - const dir: HorizontalSwipeDirection = deltaX < 0 ? 'right' : 'left'; - handler(dir); + handler(deltaX < 0 ? 'right' : 'left'); } }, false