diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index b86ac17b..9d31d805 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -111,6 +111,9 @@ "settingsShowTweetButton": { "message": "Display buttons to tweet the results" }, + "settingsEnableOnXPro": { + "message": "Run on X Pro" + }, "settingsPleaseReload": { "message": "Please reload Twitter once you have changed the settings" }, diff --git a/src/_locales/ja/messages.json b/src/_locales/ja/messages.json index 418610be..b3a35bdf 100644 --- a/src/_locales/ja/messages.json +++ b/src/_locales/ja/messages.json @@ -111,6 +111,9 @@ "settingsShowTweetButton": { "message": "結果をツイートするボタンを表示" }, + "settingsEnableOnXPro": { + "message": "X Pro上で実行する" + }, "settingsPleaseReload": { "message": "設定を変更したらTwitterを再読み込みしてください。" }, diff --git a/src/_locales/ko/messages.json b/src/_locales/ko/messages.json index 1bd795b0..befee119 100644 --- a/src/_locales/ko/messages.json +++ b/src/_locales/ko/messages.json @@ -111,6 +111,9 @@ "settingsShowTweetButton": { "message": "결과 트윗하기 버튼 표시" }, + "settingsEnableOnXPro": { + "message": "X Pro에서 실행" + }, "settingsPleaseReload": { "message": "설정을 변경한 후 Twitter를 다시 로드해주세요" }, diff --git a/src/_locales/zh_TW/messages.json b/src/_locales/zh_TW/messages.json index 46977b9f..afd6bbce 100644 --- a/src/_locales/zh_TW/messages.json +++ b/src/_locales/zh_TW/messages.json @@ -111,6 +111,10 @@ "settingsShowTweetButton": { "message": "顯示分享按鈕" }, + "settingsEnableOnXPro": { + "message": "在 X Pro 上執行", + "description": "This field was translated by machine translation." + }, "settingsPleaseReload": { "message": "如更改過設定,請重新載入 Twitter/X" }, @@ -171,4 +175,4 @@ "exitWithoutOpening": { "message": "不需要並關閉" } -} +} \ No newline at end of file diff --git a/src/ts/browserAction/settingsItems.ts b/src/ts/browserAction/settingsItems.ts index c6ef0620..1631d3c8 100644 --- a/src/ts/browserAction/settingsItems.ts +++ b/src/ts/browserAction/settingsItems.ts @@ -1,3 +1,19 @@ +import type { Settings } from "../../types/common/settings"; +import type { TranslationKey } from "../../types/common/translator"; + +interface SettingsItem { + settingsName: keyof Settings; + translationKey: TranslationKey; + type: "checkbox"; +} + +interface SettingsSeparator { + translationKey: TranslationKey; + type: "separator"; +} + +type SettingsItems = (SettingsItem | SettingsSeparator)[]; + const SETTINGS_ITEMS = [ { translationKey: "settingsWhereToDisplayCheckResults", @@ -41,7 +57,12 @@ const SETTINGS_ITEMS = [ settingsName: "showTweetButton", translationKey: "settingsShowTweetButton", type: "checkbox" + }, + { + settingsName: "enableOnXPro", + translationKey: "settingsEnableOnXPro", + type: "checkbox" } -] as const; +] as const satisfies SettingsItems; export { SETTINGS_ITEMS }; diff --git a/src/ts/common/defaultSettings.ts b/src/ts/common/defaultSettings.ts index 85b658dc..15374cea 100644 --- a/src/ts/common/defaultSettings.ts +++ b/src/ts/common/defaultSettings.ts @@ -7,6 +7,7 @@ const DEFAULT_SETTINGS = { alwaysDetailedView: false, enableForOtherUsersProfiles: true, enableForOtherUsersTweets: true, + enableOnXPro: true, showMessagesInUnproblematicProfiles: true, showMessagesInUnproblematicTweets: false, showNotesInMessages: true, diff --git a/src/ts/contentScript.ts b/src/ts/contentScript.ts index 5ea1f2a2..17a06480 100644 --- a/src/ts/contentScript.ts +++ b/src/ts/contentScript.ts @@ -7,6 +7,8 @@ import browser from "webextension-polyfill"; const main = async (): Promise => { const settings = await browser.storage.local.get(DEFAULT_SETTINGS); + if (["pro.twitter.com", "pro.x.com"].includes(location.hostname) && !settings.enableOnXPro) return; + const translator = new Translator( (key, substitutions) => browser.i18n.getMessage(key, substitutions), browser.runtime.getURL("image/") diff --git a/src/types/common/settings.d.ts b/src/types/common/settings.d.ts index 78af0bdf..d83a2201 100644 --- a/src/types/common/settings.d.ts +++ b/src/types/common/settings.d.ts @@ -7,4 +7,5 @@ export interface Settings { showMessagesInUnproblematicTweets: boolean; showNotesInMessages: boolean; showTweetButton: boolean; + enableOnXPro: boolean; } diff --git a/src/types/common/settings.guard.ts b/src/types/common/settings.guard.ts index e45a24a5..5a8fc5df 100644 --- a/src/types/common/settings.guard.ts +++ b/src/types/common/settings.guard.ts @@ -16,6 +16,7 @@ export function isSettings(obj: unknown): obj is Settings { typeof typedObj["showMessagesInUnproblematicProfiles"] === "boolean" && typeof typedObj["showMessagesInUnproblematicTweets"] === "boolean" && typeof typedObj["showNotesInMessages"] === "boolean" && - typeof typedObj["showTweetButton"] === "boolean" + typeof typedObj["showTweetButton"] === "boolean" && + typeof typedObj["enableOnXPro"] === "boolean" ) }