Skip to content

Commit 76cb5f2

Browse files
committed
feat: support click copy css
1 parent d73dd59 commit 76cb5f2

File tree

7 files changed

+85
-10
lines changed

7 files changed

+85
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ You need to download the zip file from my release and manually drag it into your
1313

1414
## Specific operations
1515

16-
Select two elements in the Elements tab of the DevTools panel.
16+
- Select two elements in the Elements tab of the DevTools panel.
17+
- Click on different styles to automatically copy
1718

1819
# Inspiration
1920

entrypoints/devtools-panel/devtools-panel.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
handleClearSelection,
1111
onTableCellClassName,
1212
onTableRowClassName,
13+
handleCopyStyle,
1314
} = useDevToolsPanel()
1415
</script>
1516

@@ -46,6 +47,7 @@ const {
4647
:data="renderCssDiffs"
4748
:cell-class-name="onTableCellClassName"
4849
:row-class-name="onTableRowClassName"
50+
@cell-click="handleCopyStyle"
4951
>
5052
<ElTableColumn prop="property" :label="$t('property')" />
5153
<template v-for="(el) in selectedEl" :key="el.valueType">

entrypoints/devtools-panel/hooks/useDevToolsPanel.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import type { CssDiffsType, SelectedElType } from '../types'
2+
import { useClipboard } from '@vueuse/core'
3+
import { ElMessage } from 'element-plus'
4+
import { useI18n } from 'vue-i18n'
25
import { formatStyle, type FormatStyleValue } from '../utils'
36

47
export function useDevToolsPanel() {
8+
const { t } = useI18n()
9+
510
const selectedEl: Array<SelectedElType> = reactive([])
611
const cssDiffs: Array<CssDiffsType> = reactive([])
712

@@ -84,16 +89,45 @@ export function useDevToolsPanel() {
8489

8590
function onTableCellClassName({ columnIndex }: { columnIndex: number }) {
8691
if (!columnIndex) {
87-
return 'text-[var(--el-table-text-color)]'
92+
return 'text-[var(--el-table-text-color)] cursor-auto'
8893
}
8994
}
9095

9196
function onTableRowClassName({ row }: { row: CssDiffsType }) {
9297
if (row.isDiff) {
93-
return '!bg-[#ffe6e6] text-[red]'
98+
return '!bg-[#ffe6e6] text-[red] cursor-pointer'
9499
}
95100
else {
96-
return '!bg-[#e6ffe6] text-[green]'
101+
return '!bg-[#e6ffe6] text-[green] cursor-pointer'
102+
}
103+
}
104+
105+
function handleCopyStyle(row: CssDiffsType, column: any) {
106+
if (column.property !== 'property') {
107+
const source = `${row.property}: ${row[column.property as 'left' | 'right']};`
108+
109+
const { text, copied, copy } = useClipboard({
110+
read: true,
111+
source,
112+
legacy: true,
113+
})
114+
115+
copy(source)
116+
117+
watch(
118+
() => copied.value,
119+
(copied) => {
120+
if (copied) {
121+
ElMessage({
122+
message: `${t('copyInfo')} > ${text.value}`,
123+
type: 'success',
124+
})
125+
}
126+
},
127+
{
128+
immediate: true,
129+
},
130+
)
97131
}
98132
}
99133

@@ -104,5 +138,6 @@ export function useDevToolsPanel() {
104138
handleClearSelection,
105139
onTableCellClassName,
106140
onTableRowClassName,
141+
handleCopyStyle,
107142
}
108143
}

entrypoints/devtools-panel/lang.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default {
66
property: 'property',
77
isAllProperty: 'Show all',
88
tableColumnInfo: 'The header name is concatenated from the DOM\'s `TagName`, `Id`, and `Class` attributes using `$$`.',
9+
copyInfo: 'Copy Success',
910
},
1011

1112
'zh-CN': {
@@ -15,5 +16,6 @@ export default {
1516
property: '属性名',
1617
isAllProperty: '显示全部',
1718
tableColumnInfo: '表头名称由DOM的 `TagName`、`Id`、`Class` 属性使用 `$$` 拼接而成。',
19+
copyInfo: '复制成功',
1820
},
1921
}

entrypoints/devtools-panel/main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { createApp } from 'vue';
2-
import App from './devtools-panel.vue';
1+
import { createApp } from 'vue'
32
import { createI18n } from 'vue-i18n'
3+
import App from './devtools-panel.vue'
44

55
import messages from './lang'
66
import 'element-plus/dist/index.css'
77

88
const i18n = createI18n({
9-
locale: 'zh-CN',
10-
messages
9+
locale: 'en',
10+
messages,
1111
})
1212

13-
createApp(App).use(i18n).mount('#app');
13+
createApp(App).use(i18n).mount('#app')

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.1",
55
"private": true,
66
"packageManager": "[email protected]",
7-
"description": "manifest.json description",
7+
"description": "A browser extension that compares different CSS",
88
"scripts": {
99
"dev": "wxt",
1010
"dev:firefox": "wxt -b firefox",
@@ -23,6 +23,7 @@
2323
"devDependencies": {
2424
"@antfu/eslint-config": "^3.12.0",
2525
"@types/chrome": "^0.0.280",
26+
"@vueuse/core": "^12.0.0",
2627
"@wxt-dev/module-vue": "^1.0.1",
2728
"autoprefixer": "^10.4.20",
2829
"eslint": "^9.17.0",

pnpm-lock.yaml

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)