Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the settings to disable on X Pro #910 #911

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
3 changes: 3 additions & 0 deletions src/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
"settingsShowTweetButton": {
"message": "結果をツイートするボタンを表示"
},
"settingsEnableOnXPro": {
"message": "X Pro上で実行する"
},
"settingsPleaseReload": {
"message": "設定を変更したらTwitterを再読み込みしてください。"
},
Expand Down
3 changes: 3 additions & 0 deletions src/_locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
"settingsShowTweetButton": {
"message": "결과 트윗하기 버튼 표시"
},
"settingsEnableOnXPro": {
"message": "X Pro에서 실행"
},
"settingsPleaseReload": {
"message": "설정을 변경한 후 Twitter를 다시 로드해주세요"
},
Expand Down
6 changes: 5 additions & 1 deletion src/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
"settingsShowTweetButton": {
"message": "顯示分享按鈕"
},
"settingsEnableOnXPro": {
"message": "在 X Pro 上執行",
"description": "This field was translated by machine translation."
},
"settingsPleaseReload": {
"message": "如更改過設定,請重新載入 Twitter/X"
},
Expand Down Expand Up @@ -171,4 +175,4 @@
"exitWithoutOpening": {
"message": "不需要並關閉"
}
}
}
23 changes: 22 additions & 1 deletion src/ts/browserAction/settingsItems.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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 };
1 change: 1 addition & 0 deletions src/ts/common/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const DEFAULT_SETTINGS = {
alwaysDetailedView: false,
enableForOtherUsersProfiles: true,
enableForOtherUsersTweets: true,
enableOnXPro: true,
showMessagesInUnproblematicProfiles: true,
showMessagesInUnproblematicTweets: false,
showNotesInMessages: true,
Expand Down
2 changes: 2 additions & 0 deletions src/ts/contentScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import browser from "webextension-polyfill";
const main = async (): Promise<void> => {
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/")
Expand Down
1 change: 1 addition & 0 deletions src/types/common/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export interface Settings {
showMessagesInUnproblematicTweets: boolean;
showNotesInMessages: boolean;
showTweetButton: boolean;
enableOnXPro: boolean;
}
3 changes: 2 additions & 1 deletion src/types/common/settings.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}