From 159c5a5f6fffac6ee7dad7db1fb3d6f9c97545be Mon Sep 17 00:00:00 2001 From: "YUKI \"Piro\" Hiroshi" Date: Mon, 6 Jan 2025 15:44:10 +0900 Subject: [PATCH] Apply rightside appearance if the sidebar position detection is "auto" and the language is RTL #3689 --- webextensions/common/common.js | 17 +++++++++++++++++ webextensions/sidebar/sidebar.js | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/webextensions/common/common.js b/webextensions/common/common.js index 343b39a34..6d77365cf 100644 --- a/webextensions/common/common.js +++ b/webextensions/common/common.js @@ -1200,3 +1200,20 @@ export function isMacOS() { export function isWindows() { return configs.enableWindowsBehaviors || /^Win/i.test(navigator.platform); } + +const RTL_LANGUAGES = new Set([ + 'ar', + 'he', + 'fa', + 'ur', +]); + +export function isRTL() { + const lang = ( + navigator.language || + navigator.userLanguage || + //(new Intl.DateTimeFormat()).resolvedOptions().locale || + '' + ).split('-')[0]; + return RTL_LANGUAGES.has(lang); +} diff --git a/webextensions/sidebar/sidebar.js b/webextensions/sidebar/sidebar.js index ea801e0ac..3df68d05c 100644 --- a/webextensions/sidebar/sidebar.js +++ b/webextensions/sidebar/sidebar.js @@ -16,6 +16,7 @@ import { shouldApplyAnimation, loadUserStyleRules, isMacOS, + isRTL, notify, } from '/common/common.js'; import * as ApiTabs from '/common/api-tabs.js'; @@ -91,6 +92,7 @@ const mContextualIdentitiesStyle = document.querySelector('#contextual-identity // allow customiation for platform specific styles with selectors like `:root[data-user-agent*="Windows NT 10"]` document.documentElement.dataset.userAgent = navigator.userAgent; document.documentElement.classList.toggle('platform-mac', isMacOS()); +document.documentElement.classList.toggle('rtl', isRTL()); { const url = new URL(location.href); @@ -1018,6 +1020,7 @@ async function isSidebarRightSide() { const mayBeRight = window.mozInnerScreenX - window.screenX > (window.outerWidth - window.innerWidth) / 2; if (configs.sidebarPosition == Constants.kTABBAR_POSITION_AUTO && mayBeRight && + !isRTL() && !configs.sidebarPositionRighsideNotificationShown) { if (mTargetWindow != (await browser.windows.getLastFocused({})).id) return; @@ -1053,7 +1056,7 @@ async function isSidebarRightSide() { } } return configs.sidebarPosition == Constants.kTABBAR_POSITION_AUTO ? - mayBeRight : + (mayBeRight || isRTL()) : configs.sidebarPosition == Constants.kTABBAR_POSITION_RIGHT; }