@@ -2,6 +2,7 @@ import type { CssDiffsType, SelectedElType } from '../types'
22import { useClipboard } from '@vueuse/core'
33import { ElMessage } from 'element-plus'
44import { useI18n } from 'vue-i18n'
5+ import SM from '../message'
56import { formatStyle , type FormatStyleValue } from '../utils'
67
78export function useDevToolsPanel ( ) {
@@ -31,20 +32,40 @@ export function useDevToolsPanel() {
3132 `(${ formatStyle . toString ( ) } )($0)` ,
3233 ( result : FormatStyleValue , isException ) => {
3334 if ( ! isException && result != null && isLoadComplete . value ) {
34- saveSelectedEl ( result )
35+ const valueType = ! selectedEl . length ? 'left' : 'right'
36+
37+ saveSelectedEl ( { ...result , valueType } )
3538 }
3639 } ,
3740 )
3841 } )
42+
43+ // Receive the <selected element> transmitted from the tab being operated
44+ browser . runtime . onMessage . addListener ( ( data : Array < SelectedElType > ) => {
45+ selectedEl . length = 0
46+
47+ if ( ! data . length ) {
48+ cssDiffs . length = 0
49+ return
50+ }
51+
52+ selectedEl . push ( ...data )
53+
54+ if ( selectedEl . length === 2 ) {
55+ compareSelectedEl ( )
56+ }
57+ } )
3958 } )
4059
41- function saveSelectedEl ( result : FormatStyleValue ) {
60+ function saveSelectedEl ( result : SelectedElType ) {
4261 if ( selectedEl . length === 2 ) {
4362 return
4463 }
4564
46- const valueType = ! selectedEl . length ? 'left' : 'right'
47- selectedEl . push ( { ...result , valueType } )
65+ selectedEl . push ( result )
66+
67+ // Send selected data to other windows/tabs
68+ SM . send ( selectedEl )
4869
4970 if ( selectedEl . length === 2 ) {
5071 compareSelectedEl ( )
@@ -54,6 +75,9 @@ export function useDevToolsPanel() {
5475 function handleClearSelection ( ) {
5576 selectedEl . length = 0
5677 cssDiffs . length = 0
78+
79+ // Send selected data to other windows/tabs
80+ SM . send ( [ ] )
5781 }
5882
5983 function compareSelectedEl ( ) {
0 commit comments