Skip to content

Commit 4a2a07a

Browse files
committed
add button to copy delta as json string
1 parent 194e8d1 commit 4a2a07a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

manifest.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"https://*/*",
2020
"file:///*",
2121
"activeTab",
22-
"tabs"
22+
"tabs",
23+
"clipboardWrite"
2324
]
2425
}

src/js/app/panel.vue.js

+20
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,24 @@ define(['api'], function(api) {
1111
ce('div', {class: ['-toolbox']}, [
1212
ce('button', {
1313
class: ['btn'],
14+
attrs: {title: 'Inject console.diff API to current tab'},
1415
on: {click: this.onReinject}
1516
}, 'Inject API'),
1617
(this.hasBothSides ?
1718
ce('button', {
1819
class: ['btn'],
20+
attrs: {title: 'Hide/Show unchanged properties'},
1921
on: {click: this.onToggleUnchanged}
2022
}, 'Toggle Unchanged')
2123
: null
24+
),
25+
(this.hasBothSides ?
26+
ce('button', {
27+
class: ['btn'],
28+
attrs: {title: 'Copy delta as json string'},
29+
on: {click: this.onCopyDelta}
30+
}, 'Copy')
31+
: null
2232
)
2333
]),
2434
(this.hasBothSides ?
@@ -119,6 +129,16 @@ define(['api'], function(api) {
119129
chrome.runtime.sendMessage('jsdiff-panel-reinject');
120130
},
121131

132+
onCopyDelta() {
133+
const delta = api.jsondiffpatch.diff(this.compare.left, this.compare.right);
134+
const sDelta = JSON.stringify(delta);
135+
document.oncopy = function(e) {
136+
e.clipboardData.setData('text', sDelta);
137+
e.preventDefault();
138+
};
139+
document.execCommand('copy', false, null);
140+
},
141+
122142
$_restartLastUpdated() {
123143
this.compare.timestamp = Date.now();
124144

0 commit comments

Comments
 (0)