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

(miscreated pull)Add button text option #596

Merged
merged 6 commits into from
Nov 28, 2023
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
18 changes: 9 additions & 9 deletions __tests__/ButtonSetter.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ButtonSetter } from '../src/ButtonSetter';
// import * as main from '../src/main';
import { SHOW_ON_TIMELINE, SHOW_ON_TWEET_DETAIL, isFalse, isTrue } from '../src/constants';
import { SHOW_ON_TIMELINE, SHOW_ON_TWEET_DETAIL } from '../src/constants';

function makeAllEnabledOptions() {
return {
SHOW_ON_TIMELINE: isTrue,
SHOW_ON_TWEET_DETAIL: isTrue,
SHOW_ON_TWEETDECK_TIMELINE: isTrue,
SHOW_ON_TWEETDECK_TWEET_DETAIL: isTrue,
STRIP_IMAGE_SUFFIX: isTrue,
SHOW_ON_TIMELINE: true,
SHOW_ON_TWEET_DETAIL: true,
SHOW_ON_TWEETDECK_TIMELINE: true,
SHOW_ON_TWEETDECK_TWEET_DETAIL: true,
STRIP_IMAGE_SUFFIX: true,
};
}

Expand Down Expand Up @@ -300,7 +300,7 @@ describe('ButtonSetter', () => {
buttonSetter.setButton = jest.fn();

const options = makeAllEnabledOptions();
options[SHOW_ON_TIMELINE] = isFalse;
options[SHOW_ON_TIMELINE] = false;
buttonSetter._setButtonOnTimeline(options);

expect(buttonSetter.setButton).not.toHaveBeenCalled();
Expand Down Expand Up @@ -455,7 +455,7 @@ describe('ButtonSetter', () => {
buttonSetter.setButton = jest.fn();

const options = makeAllEnabledOptions();
options[SHOW_ON_TWEET_DETAIL] = isFalse;
options[SHOW_ON_TWEET_DETAIL] = false;
buttonSetter.setButtonOnTweetDetail(options);

expect(buttonSetter.setButton).not.toHaveBeenCalled();
Expand Down Expand Up @@ -649,7 +649,7 @@ describe('ButtonSetter', () => {
buttonSetter.setReactLayoutButton = jest.fn();

const options = makeAllEnabledOptions();
options[SHOW_ON_TIMELINE] = isFalse;
options[SHOW_ON_TIMELINE] = false;
buttonSetter._setButtonOnReactLayoutTimeline(options);

expect(buttonSetter.setReactLayoutButton).not.toHaveBeenCalled();
Expand Down
16 changes: 8 additions & 8 deletions __tests__/ButtonSetterTweetDeck.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ButtonSetterTweetDeck } from '../src/ButtonSetterTweetDeck';
import { SHOW_ON_TWEETDECK_TIMELINE, SHOW_ON_TWEETDECK_TWEET_DETAIL, isFalse, isTrue } from '../src/constants';
import { SHOW_ON_TWEETDECK_TIMELINE, SHOW_ON_TWEETDECK_TWEET_DETAIL } from '../src/constants';

function makeAllEnabledOptions() {
return {
SHOW_ON_TIMELINE: isTrue,
SHOW_ON_TWEET_DETAIL: isTrue,
SHOW_ON_TWEETDECK_TIMELINE: isTrue,
SHOW_ON_TWEETDECK_TWEET_DETAIL: isTrue,
STRIP_IMAGE_SUFFIX: isTrue,
SHOW_ON_TIMELINE: true,
SHOW_ON_TWEET_DETAIL: true,
SHOW_ON_TWEETDECK_TIMELINE: true,
SHOW_ON_TWEETDECK_TWEET_DETAIL: true,
STRIP_IMAGE_SUFFIX: true,
};
}

Expand Down Expand Up @@ -197,7 +197,7 @@ describe('ButtonSetterTweetDeck', () => {
buttonSetter.setButton = jest.fn();

const options = makeAllEnabledOptions();
options[SHOW_ON_TWEETDECK_TIMELINE] = isFalse;
options[SHOW_ON_TWEETDECK_TIMELINE] = false;
buttonSetter.setButtonOnTimeline(options);

expect(buttonSetter.setButton).not.toHaveBeenCalled();
Expand Down Expand Up @@ -410,7 +410,7 @@ describe('ButtonSetterTweetDeck', () => {
buttonSetter.setButton = jest.fn();

const options = makeAllEnabledOptions();
options[SHOW_ON_TWEETDECK_TWEET_DETAIL] = isFalse;
options[SHOW_ON_TWEETDECK_TWEET_DETAIL] = false;
buttonSetter.setButtonOnTweetDetail(options);

expect(buttonSetter.setButton).not.toHaveBeenCalled();
Expand Down
43 changes: 9 additions & 34 deletions __tests__/Constants.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
GET_LOCAL_STORAGE,
HOST_PBS_TWIMG_COM,
HOST_PRO_TWITTER_COM,
HOST_TWEETDECK_TWITTER_COM,
HOST_TWITTER_COM,
Expand All @@ -11,13 +10,9 @@ import {
SHOW_ON_TWEETDECK_TIMELINE,
SHOW_ON_TWEETDECK_TWEET_DETAIL,
SHOW_ON_TWEET_DETAIL,
STRIP_IMAGE_SUFFIX,
initialOptions,
isFalse,
isImageTab,
initialOptionsBool,
isNativeChromeExtension,
isReactView,
isTrue,
isTweetdeck,
isTwitter,
} from '../src/constants';
Expand All @@ -41,44 +36,28 @@ describe('定数', () => {
expect(SHOW_ON_TWEETDECK_TWEET_DETAIL).toBe('SHOW_ON_TWEETDECK_TWEET_DETAIL');
});

it('画像ページ', () => {
expect(HOST_PBS_TWIMG_COM).toBe('pbs.twimg.com');
expect(STRIP_IMAGE_SUFFIX).toBe('STRIP_IMAGE_SUFFIX');
});

it('設定に使う真偽値', () => {
expect(isTrue).toBe('istrue');
expect(isFalse).toBe('isfalse');
});

it('userjs用の設定項目の初期値は全部真', () => {
expect(initialOptions).toStrictEqual({
// 公式Web
SHOW_ON_TIMELINE: isTrue,
SHOW_ON_TWEET_DETAIL: isTrue,
// TweetDeck
SHOW_ON_TWEETDECK_TIMELINE: isTrue,
SHOW_ON_TWEETDECK_TWEET_DETAIL: isTrue,
// 画像ページ
STRIP_IMAGE_SUFFIX: isTrue,
it('初期設定', () => {
expect(initialOptionsBool).toStrictEqual({
SHOW_ON_TIMELINE: true,
SHOW_ON_TWEET_DETAIL: true,
SHOW_ON_TWEETDECK_TIMELINE: true,
SHOW_ON_TWEETDECK_TWEET_DETAIL: true,
});
});

it('設定ページの設定ごとのキーと日本語', () => {
expect(OPTION_KEYS).toStrictEqual([
SHOW_ON_TIMELINE,
SHOW_ON_TWEET_DETAIL,
SHOW_ON_TWEETDECK_TIMELINE,
SHOW_ON_TWEETDECK_TWEET_DETAIL,
STRIP_IMAGE_SUFFIX,
]);

expect(OPTIONS_TEXT).toStrictEqual({
SHOW_ON_TIMELINE: 'タイムライン',
SHOW_ON_TWEET_DETAIL: '(旧表示で)ツイート詳細',
// TweetDeck
SHOW_ON_TWEETDECK_TIMELINE: 'タイムライン',
SHOW_ON_TWEETDECK_TWEET_DETAIL: '(旧表示で)ツイート詳細',
// 画像ページ
STRIP_IMAGE_SUFFIX: '[Ctrl]+[s]で拡張子を校正',
});
});

Expand All @@ -95,27 +74,23 @@ describe('定数', () => {
window.location = new URL('https://twitter.com');
expect(isTwitter()).toBeTruthy();
expect(isTweetdeck()).toBeFalsy();
expect(isImageTab()).toBeFalsy();
});
describe('TweetDeck', () => {
it('tweetdeck.twitter.com', () => {
window.location = new URL('https://tweetdeck.twitter.com');
expect(isTwitter()).toBeFalsy();
expect(isTweetdeck()).toBeTruthy();
expect(isImageTab()).toBeFalsy();
});
it('pro.twitter.com', () => {
window.location = new URL('https://pro.twitter.com');
expect(isTwitter()).toBeFalsy();
expect(isTweetdeck()).toBeTruthy();
expect(isImageTab()).toBeFalsy();
});
});
it('画像ページ', () => {
window.location = new URL('https://pbs.twimg.com');
expect(isTwitter()).toBeFalsy();
expect(isTweetdeck()).toBeFalsy();
expect(isImageTab()).toBeTruthy();
});
});

Expand Down
2 changes: 1 addition & 1 deletion coverage/badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 29 additions & 76 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,113 +1,66 @@
// 設定取得メッセージ
export const OPTION_UPDATED = 'OPTION_UPDATED';
export const GET_LOCAL_STORAGE = 'GET_LOCAL_STORAGE';

// 公式Web
export const HOST_TWITTER_COM = 'twitter.com';
export const HOST_MOBILE_TWITTER_COM = 'mobile.twitter.com';
export const SHOW_ON_TIMELINE = 'SHOW_ON_TIMELINE';
export const SHOW_ON_TWEET_DETAIL = 'SHOW_ON_TWEET_DETAIL';
// TweetDeck
export const HOST_TWEETDECK_TWITTER_COM = 'tweetdeck.twitter.com';
export const HOST_PRO_TWITTER_COM = 'pro.twitter.com';
export const SHOW_ON_TWEETDECK_TIMELINE = 'SHOW_ON_TWEETDECK_TIMELINE';
export const SHOW_ON_TWEETDECK_TWEET_DETAIL = 'SHOW_ON_TWEETDECK_TWEET_DETAIL';

/**
* 設定項目
*/
export interface OptionsBool {
// 公式Web
SHOW_ON_TIMELINE: boolean;
SHOW_ON_TWEET_DETAIL: boolean;
// TweetDeck
SHOW_ON_TWEETDECK_TIMELINE: boolean;
SHOW_ON_TWEETDECK_TWEET_DETAIL: boolean;
// 画像ページ
STRIP_IMAGE_SUFFIX: boolean;
}

export interface Options {
// 公式Web
SHOW_ON_TIMELINE: TooiBoolean;
SHOW_ON_TWEET_DETAIL: TooiBoolean;
// TweetDeck
SHOW_ON_TWEETDECK_TIMELINE: TooiBoolean;
SHOW_ON_TWEETDECK_TWEET_DETAIL: TooiBoolean;
// 画像ページ
STRIP_IMAGE_SUFFIX: TooiBoolean;
}

export type OptionsMaybe = { [key in keyof Options]?: TooiBoolean };

/**
* 設定項目
*/
export const initialOptionsBool: OptionsBool = {
// 公式Web
SHOW_ON_TIMELINE: true,
SHOW_ON_TWEET_DETAIL: true,
// TweetDeck
SHOW_ON_TWEETDECK_TIMELINE: true,
SHOW_ON_TWEETDECK_TWEET_DETAIL: true,
// 画像ページ
STRIP_IMAGE_SUFFIX: true,
};

/**
* 設定項目
* 'isfalse' とすると、その設定がオフになる
*/
export const initialOptions: Options = {
export const OPTION_KEYS = [
SHOW_ON_TIMELINE,
SHOW_ON_TWEET_DETAIL,
SHOW_ON_TWEETDECK_TIMELINE,
SHOW_ON_TWEETDECK_TWEET_DETAIL,
] as const;
export const OPTIONS_TEXT: { [key in keyof OptionsBool]: string } = {
// 公式Web
SHOW_ON_TIMELINE: 'istrue',
SHOW_ON_TWEET_DETAIL: 'istrue',
SHOW_ON_TIMELINE: 'タイムライン',
SHOW_ON_TWEET_DETAIL: '(旧表示で)ツイート詳細',
// TweetDeck
SHOW_ON_TWEETDECK_TIMELINE: 'istrue',
SHOW_ON_TWEETDECK_TWEET_DETAIL: 'istrue',
// 画像ページ
STRIP_IMAGE_SUFFIX: 'istrue',
SHOW_ON_TWEETDECK_TIMELINE: 'タイムライン',
SHOW_ON_TWEETDECK_TWEET_DETAIL: '(旧表示で)ツイート詳細',
};

// 設定取得メッセージ
export const OPTION_UPDATED = 'OPTION_UPDATED';
export const GET_LOCAL_STORAGE = 'GET_LOCAL_STORAGE';

// 公式Web
export const HOST_TWITTER_COM = 'twitter.com';
export const HOST_MOBILE_TWITTER_COM = 'mobile.twitter.com';
export const SHOW_ON_TIMELINE = 'SHOW_ON_TIMELINE';
export const SHOW_ON_TWEET_DETAIL = 'SHOW_ON_TWEET_DETAIL';
// TweetDeck
export const HOST_TWEETDECK_TWITTER_COM = 'tweetdeck.twitter.com';
export const HOST_PRO_TWITTER_COM = 'pro.twitter.com';
export const SHOW_ON_TWEETDECK_TIMELINE = 'SHOW_ON_TWEETDECK_TIMELINE';
export const SHOW_ON_TWEETDECK_TWEET_DETAIL = 'SHOW_ON_TWEETDECK_TWEET_DETAIL';
// 画像ページ
export const HOST_PBS_TWIMG_COM = 'pbs.twimg.com';
export const STRIP_IMAGE_SUFFIX = 'STRIP_IMAGE_SUFFIX';

/** 公式Webかどうか */
export const isTwitter = (): boolean =>
window.location.hostname === HOST_TWITTER_COM || window.location.hostname === HOST_MOBILE_TWITTER_COM;
/** Tweetdeckかどうか */
export const isTweetdeck = (): boolean =>
window.location.hostname === HOST_TWEETDECK_TWITTER_COM || window.location.hostname === HOST_PRO_TWITTER_COM;
/** 画像ページかどうか */
export const isImageTab = (): boolean => window.location.hostname === HOST_PBS_TWIMG_COM;

/** Reactビューかどうか */
export const isReactView = (): boolean => !!document.getElementById('react-root');

/** これ自体がChrome拡張機能かどうか */
export const isNativeChromeExtension = (): boolean => chrome?.runtime?.id !== undefined;

// 設定

// 設定に使う真偽値
export const isTrue = 'istrue';
export const isFalse = 'isfalse';
type TooiBoolean = typeof isTrue | typeof isFalse;

export const OPTION_KEYS = [
SHOW_ON_TIMELINE,
SHOW_ON_TWEET_DETAIL,
SHOW_ON_TWEETDECK_TIMELINE,
SHOW_ON_TWEETDECK_TWEET_DETAIL,
STRIP_IMAGE_SUFFIX,
] as const;
export const OPTIONS_TEXT: { [key in keyof Options]: string } = {
// 公式Web
SHOW_ON_TIMELINE: 'タイムライン',
SHOW_ON_TWEET_DETAIL: '(旧表示で)ツイート詳細',
// TweetDeck
SHOW_ON_TWEETDECK_TIMELINE: 'タイムライン',
SHOW_ON_TWEETDECK_TWEET_DETAIL: '(旧表示で)ツイート詳細',
// 画像ページ
STRIP_IMAGE_SUFFIX: '[Ctrl]+[s]で拡張子を校正',
};

// chrome.storateへの移行が済んだかどうかのキー
export const MIGRATED_TO_CHROME_STORAGE = 'MIGRATED_TO_CHROME_STORAGE';
7 changes: 1 addition & 6 deletions src/extension-contexts/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useCallback, useState } from 'react';
import ReactDOM from 'react-dom';
import {
HOST_MOBILE_TWITTER_COM,
HOST_PBS_TWIMG_COM,
HOST_TWEETDECK_TWITTER_COM,
HOST_TWITTER_COM,
OPTIONS_TEXT,
Expand Down Expand Up @@ -46,11 +45,7 @@ export const Popup = (props: Props): JSX.Element => {
return;
}
const tabUrl = new URL(tab.url).hostname;
if (
![HOST_TWITTER_COM, HOST_MOBILE_TWITTER_COM, HOST_TWEETDECK_TWITTER_COM, HOST_PBS_TWIMG_COM].some(
(url) => url === tabUrl,
)
) {
if (![HOST_TWITTER_COM, HOST_MOBILE_TWITTER_COM, HOST_TWEETDECK_TWITTER_COM].some((url) => url === tabUrl)) {
// 送り先タブが拡張機能が動作する対象ではないならメッセージを送らない
return;
}
Expand Down
16 changes: 0 additions & 16 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
GET_LOCAL_STORAGE,
OPTION_UPDATED,
OptionsBool,
STRIP_IMAGE_SUFFIX,
initialOptionsBool,
isNativeChromeExtension,
isReactView,
Expand Down Expand Up @@ -277,18 +276,3 @@ export const setOriginalButton = (options: OptionsBool): void => {
});
}
};

/**
* @deprecated
* twitterの画像を表示したときのC-sを拡張
* 画像のファイル名を「~.jpg-orig」「~.png-orig」ではなく「~-orig.jpg」「~-orig.png」にする
*/
export const fixFileNameOnSaveCommand = (options: OptionsBool): void => {
// キーを押したとき
document.addEventListener('keydown', (e) => {
// 設定が有効なら
if (options[STRIP_IMAGE_SUFFIX]) {
downloadImage(e);
}
});
};
Loading