Skip to content

Commit ad89872

Browse files
author
rakeshAlgo
committed
Remove $ from console codeblock
1 parent e6b625e commit ad89872

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/js/07-copy-to-clipboard.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,42 @@
2828

2929
copyButton.addEventListener('click', function (e) {
3030
if (e.target && e.target.matches('a.copy-code-button')) {
31-
navigator.clipboard.writeText(codeBlock.innerText).then(
32-
function () {
33-
/* Chrome doesn't seem to blur automatically,
34-
leaving the button in a focused state. */
35-
copyButton.blur()
31+
// for console text
32+
if (codeBlock.dataset.lang == 'console') {
33+
var bashText = codeBlock.innerText
34+
// remove $ from text
35+
navigator.clipboard.writeText(bashText.slice(2)).then(
36+
function () {
37+
/* Chrome doesn't seem to blur automatically,
38+
leaving the button in a focused state. */
39+
copyButton.blur()
40+
copyButton.dataset.title = 'Copied ✓'
41+
setTimeout(function () {
42+
copyButton.dataset.title = 'Copy'
43+
}, 2000)
44+
},
45+
function () {
46+
copyButton.dataset.title = 'Error'
47+
}
48+
)
49+
} else {
50+
navigator.clipboard.writeText(codeBlock.innerText).then(
51+
function () {
52+
/* Chrome doesn't seem to blur automatically,
53+
leaving the button in a focused state. */
54+
copyButton.blur()
3655

37-
copyButton.dataset.title = 'Copied ✓'
56+
copyButton.dataset.title = 'Copied ✓'
3857

39-
setTimeout(function () {
40-
copyButton.dataset.title = 'Copy'
41-
}, 2000)
42-
},
43-
function () {
44-
copyButton.dataset.title = 'Error'
45-
}
46-
)
58+
setTimeout(function () {
59+
copyButton.dataset.title = 'Copy'
60+
}, 2000)
61+
},
62+
function () {
63+
copyButton.dataset.title = 'Error'
64+
}
65+
)
66+
}
4767
}
4868
})
4969
var pre = codeBlock.parentNode

0 commit comments

Comments
 (0)