|
1 | 1 | // content.tsx |
2 | 2 | export {} |
3 | 3 |
|
| 4 | +// 対象のホスト名 |
| 5 | +const TARGET_HOST = 'browser-hack.utcode.net'; |
| 6 | +if (window.location.host === TARGET_HOST) { |
| 7 | + let isSidePanelOpen = false; |
| 8 | + const warningElement = document.createElement('div'); |
| 9 | + warningElement.id = 'sidepanel-warning'; |
| 10 | + warningElement.innerHTML = ` |
| 11 | + <p><strong>注意</strong></p> |
| 12 | + <p>サイドパネルが開かれていません。右上の<span class="badge">ブ</span>をクリックしてサイドパネルを開いてください。</p> |
| 13 | + `; |
| 14 | + |
| 15 | + const badge = warningElement.querySelector<HTMLSpanElement>('.badge') |
| 16 | + if (badge) { |
| 17 | + Object.assign(badge.style, { |
| 18 | + display: 'inline-block', |
| 19 | + width: '1.6em', |
| 20 | + height: '1.6em', |
| 21 | + backgroundColor: '#6a6767ff', |
| 22 | + textAlign: 'center', |
| 23 | + lineHeight: '1.6em', |
| 24 | + color: '#ffffff', |
| 25 | + }) |
| 26 | + } |
| 27 | + |
| 28 | + // スタイルを直接設定 |
| 29 | + warningElement.style.position = 'fixed'; |
| 30 | + warningElement.style.top = '20px'; |
| 31 | + warningElement.style.right = '20px'; |
| 32 | + warningElement.style.padding = '20px'; |
| 33 | + warningElement.style.backgroundColor = '#fff3cd'; |
| 34 | + warningElement.style.color = '#ff0000ff'; |
| 35 | + warningElement.style.border = '1px solid #ffc107'; |
| 36 | + warningElement.style.borderRadius = '8px'; |
| 37 | + warningElement.style.zIndex = '9999'; |
| 38 | + warningElement.style.boxShadow = '0 4px 8px rgba(0,0,0,0.1)'; |
| 39 | + warningElement.style.fontFamily = 'sans-serif'; |
| 40 | + warningElement.style.display = 'none'; // 最初は非表示 |
| 41 | + |
| 42 | + document.body.appendChild(warningElement); |
| 43 | + |
| 44 | + // 2秒後にサイドパネルが開かれていなければ警告を表示 |
| 45 | + const warningTimeout = setTimeout(() => { |
| 46 | + if (!isSidePanelOpen) { |
| 47 | + warningElement.style.display = 'block'; |
| 48 | + } |
| 49 | + }, 2000); |
| 50 | + |
| 51 | + // タブが閉じるとリセット |
| 52 | + window.addEventListener('beforeunload', () => { |
| 53 | + isSidePanelOpen = false; |
| 54 | + clearTimeout(warningTimeout); |
| 55 | + }); |
| 56 | + |
| 57 | + chrome.runtime.onConnect.addListener((port) => { |
| 58 | + if (port.name !== 'sidepanel') return |
| 59 | + ports.add(port) |
| 60 | + |
| 61 | + // サイドパネルからのメッセージをリッスン |
| 62 | + port.onMessage.addListener((msg) => { |
| 63 | + if (msg.type === 'SIDE_PANEL_OPENED') { |
| 64 | + isSidePanelOpen = true; |
| 65 | + warningElement.style.display = 'none'; // 警告を非表示にする |
| 66 | + } |
| 67 | + }); |
| 68 | + |
| 69 | + const initialValues = getCurrentValues() |
| 70 | + lastJson = JSON.stringify(initialValues) |
| 71 | + port.postMessage({ |
| 72 | + type: 'DOM_VALUE_UPDATE', |
| 73 | + pageKey: PAGE_KEY, |
| 74 | + values: initialValues, |
| 75 | + }) |
| 76 | + |
| 77 | + port.onDisconnect.addListener(() => ports.delete(port)) |
| 78 | + }) |
| 79 | +} |
| 80 | + |
4 | 81 | const PAGE_KEY = `${location.origin}${location.pathname}` |
5 | 82 |
|
6 | 83 | function isDisplayed(el: Element | null): boolean { |
@@ -79,6 +156,7 @@ chrome.runtime.onConnect.addListener((port) => { |
79 | 156 | if (port.name !== 'sidepanel') return |
80 | 157 | ports.add(port) |
81 | 158 |
|
| 159 | + |
82 | 160 | const initialValues = getCurrentValues() |
83 | 161 | lastJson = JSON.stringify(initialValues) |
84 | 162 | port.postMessage({ |
|
0 commit comments