Skip to content

Commit

Permalink
Merge pull request #542 from hogashi/fix-button-color
Browse files Browse the repository at this point in the history
use color of grandchild svg, not child
  • Loading branch information
hogashi authored Aug 2, 2023
2 parents 9ff0571 + f93228c commit 87ba05d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions __tests__/ButtonSetter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,14 @@ describe('ButtonSetter', () => {
const button = document.createElement('div');
button.setAttribute('role', 'button');
const child = document.createElement('div');
const svg = document.createElement('svg');
if (color) {
child.style.color = color;
// 本来はsvgにはcolorは当たっていなくて, 親のcolorをgetComputedStyleで取得すると自然ととれる
// テストでは再現できなかったのでstyleを当ててしまう
svg.style.color = color;
}
child.appendChild(svg);
button.appendChild(child);
group.appendChild(button);
document.body.appendChild(group);
Expand Down
2 changes: 1 addition & 1 deletion dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "twitter画像原寸ボタン",
"version": "5.2.0",
"version": "5.2.1",
"description": "twitterの画像ツイートにボタンを追加する拡張機能。追加されたボタンを押すとツイートの画像を原寸で新しいタブに表示する。連絡先: @hogextend",
"author": "hogashi",
"permissions": ["tabs", "storage"],
Expand Down
6 changes: 3 additions & 3 deletions src/ButtonSetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ export class ButtonSetter implements ButtonSetterType {
// 初期値: コントラスト比4.5(chromeの推奨する最低ライン)の色
let color = '#697b8c';
// ツイートアクション(返信とか)のボタンのクラス(夜間モードか否かでクラス名が違う)
const actionButton = document.querySelector<HTMLElement>('div[role="group"] div[role="button"]');
if (actionButton?.children[0] && (actionButton.children[0] as HTMLElement).style) {
const buttonColor = window.getComputedStyle(actionButton.children[0]).color;
const actionButtonSvg = document.querySelector<SVGSVGElement>('div[role="group"] div[role="button"] svg');
if (actionButtonSvg) {
const buttonColor = window.getComputedStyle(actionButtonSvg).color;
if (buttonColor && buttonColor.length > 0) {
color = buttonColor;
}
Expand Down

0 comments on commit 87ba05d

Please sign in to comment.