<!
DOCTYPE
html
>
<
html
lang
="
en
">
<
head
>
<
meta
charset
="
UTF-8
">
<
meta
name
="
viewport
"
content
="
width=device-width, initial-scale=1.0
">
<
meta
http-equiv
="
X-UA-Compatible
"
content
="
ie=edge
">
<
title
>
CopyAsHtmlFromVScode
</
title
>
<
style
>
<
/
style
>
</
head
>
<
body
>
<
div
id
="
codePart
">
<
div
id
="
codeBox
"
class
="
codeBox
"
style
='
width: 100%; height: auto; line-height: 34px; position: relative; font-family: "Meslo LG L DZ", "monospace";
'
>
<
div
id
="
banner
"
class
="
banner
"
style
="
width: 100%; height: 34px; position: absolute; top: 0; left: 0; background: rgba(0, 0, 0, .1); border-top-left-radius: 8px; border-bottom-left-radius: 8px; box-sizing: border-box; border-bottom: 1px solid rgba(0, 0, 0, .15)
"
>
<
div
id
="
bannerStamp
"
style
="
height: 34px; width: 34px; float: left; display: flex; align-items: center; justify-content: center
"
>
<
span
style
="
display: block; width: 60%; height: 60%; border-radius: 50%; background: green
"
>&
nbsp
;</
span
>
</
div
>
<
div
style
="
height: 34px; float: left; font-size: 16px; line-height: 34px; display: flex; align-items: center;
"
>
<
span
style
="
display: block; font-family: sans-serif
"
id
="
bannerTitle
">
123.html
</
span
>
</
div
>
<
div
style
="
height: 34px; float: right; font-size: 16px; line-height: 34px; display: flex; align-items: center; justify-content: center;
"
>
<
span
style
="
display: block; background: rgba(255, 255, 255, .65); font-family: sans-serif; padding: 0 5px; margin-right: 10px;
"
data-clipboard-target
="">
COPY
</
span
>
<
span
class
="
expandBtn
"
style
="
display: block; background: rgba(255, 0, 0, .65); color: #f5f5f5; font-family: sans-serif; padding: 0 5px; margin-right: 10px;
"
>
EXPAND
</
span
>
</
div
>
</
div
>
<
div
class
="
side
"
id
="
vsSide
"
style
="
width: 50px; background: none; float: left; padding: 40px 0 45px; background: #f5f5f5; border-top-left-radius: 8px; border-bottom-left-radius: 8px;
"
>
</
div
>
<
div
id
="
containerOuter
"
style
="
width: calc(100% - 70px); float: left; white-space: nowrap; background: #f5f5f5; overflow: auto; padding: 40px 0 45px 20px; border-bottom-right-radius: 8px; border-top-right-radius: 8px;
"
>
<
div
id
="
_containerBox
">
</
div
>
</
div
>
<
div
class
="
banner
"
style
="
width: 100%; height: 34px; position: absolute; bottom: 55px; left: 0; box-sizing: border-box; border-bottom: 1px solid rgba(0, 0, 0, .15)
"
>
<
div
style
="
height: 34px; float: right; font-size: 16px; line-height: 34px; display: flex; align-items: center; justify-content: center;
"
>
<
span
style
="
display: block; background: rgba(255, 255, 255, .65); font-family: sans-serif; padding: 0 5px; margin-right: 10px;
"
data-clipboard-target
="">
COPY
</
span
>
<
span
class
="
expandBtn
"
style
="
display: block; background: rgba(255, 0, 0, .65); color: #f5f5f5; font-family: sans-serif; padding: 0 5px; margin-right: 10px;
"
>
EXPAND
</
span
>
</
div
>
</
div
>
<
div
style
="
clear: both;
"
>
</
div
>
</
div
>
</
div
>
</
body
>
</
html
>
<
script
src
="
./clipBoard.js
">
<
/
script
>
<
script
>
var
themes
=
{
// 主題,本身定義了兩種,能夠本身加~
"
dark
"
:
{
c_title_bg
:
"
#252525
"
,
// 標題欄背景色
c_title_fg
:
"
#ededed
"
,
// 前景色(文字顏色)
c_editor_bg
:
"
#1e1e1e
"
,
// 代碼區背景
c_sideNum_bg
:
"
#1e1e1e
"
,
// 行數欄背景
c_sideNum_fg
:
"
#727272
"
// 前景色
},
"
light
"
:
{
c_title_bg
:
"
#dcdcdc
"
,
c_title_fg
:
"
#999
"
,
c_editor_bg
:
"
#f5f5f5
"
,
c_sideNum_bg
:
"
#e5e5e5
"
,
c_sideNum_fg
:
"
#999
"
}
}
;
var
config
=
{
// 調整基本樣式
"
theme
"
:
"
dark
"
,
// 主題名
"
fontFamily
"
:
'
"Meslo LG L DZ", "monospace"
'
,
"
lineHeight
"
:
"
25px
"
,
"
fontSize
"
:
"
15px
"
,
"
fileName
"
:
"
advancedHighLight_ver_2_0.html
"
,
// 標題名稱
"
stampColor
"
:
""
,
// 留空會根據文件拓展名設置圓點的顏色
"
maxHeight
"
:
400
,
// 限制高度,px
"
highLight
"
: [
true
,
"
#569cd6
"
]
}
;
/*
兼容 IE, getComputedStyle
*/
if
(
!
window
.
getComputedStyle
)
{
window
.
getComputedStyle
=
function
(
el
,
pseudo
)
{
this
.
el
=
el
;
this
.
getPropertyValue
=
function
(
prop
)
{
var
re
=
/(
\-
([
a-z
])
{1}
)/
g
;
if
(
prop
==
'
float
'
)
prop
=
'
styleFloat
'
;
if
(
re
.
test
(
prop
))
{
prop
=
prop
.
replace
(
re
,
function
()
{
return
arguments
[
2
].
toUpperCase
()
;
})
;
}
return
el
.
currentStyle
[
prop
]
?
el
.
currentStyle
[
prop
]
:
null
;
}
return
this
;
}
}
;
document
.
onpaste
=
function
(
e
){
format
()
;
// 初始化代碼外框模板
var
cb_str
=
e
.
clipboardData
.
getData
(
'
text\/html
'
)
||
e
.
clipboardData
.
getData
(
'
text\/plain
'
)
;
// 獲取從 VSCode 裏面複製的含 html 標籤的代碼
console
.
log
(
cb_str
)
var
tmpDiv
=
document
.
createElement
(
"
div
"
)
;
tmpDiv
.
innerHTML
=
cb_str
;
var
containerBox
=
tmpDiv
.
children
[
0
]
;
var
arrLineDiv
=
containerBox
.
children
;
var
HollowArr
=
[]
;
for
(
var
i
=
0;
i
<
arrLineDiv
.
length
;
i
++
){
var
arrLineSpanChar
=
arrLineDiv
[
i
].
children
;
var
tmp_arrLine
=
[]
;
for
(
var
j
=
0;
j
<
arrLineSpanChar
.
length
;
j
++
){
var
arrEmpty
=
[]
;
arrEmpty
[
0
]
=
arrLineSpanChar
[
j
].
style
.
color
;
// 空格替換爲 HTML 轉義符
arrEmpty
[
1
]
=
arrLineSpanChar
[
j
].
innerHTML
.
replace
(
/
/
g
,
"
"
)
;
tmp_arrLine
.
push
(
arrEmpty
)
;
}
HollowArr
.
push
(
tmp_arrLine
)
;
}
var
_containerBox
=
document
.
getElementById
(
"
_containerBox
"
)
;
var
stamp
=
new
Date
().
getTime
()
;
_containerBox
.
id
=
"
d
"
+
stamp
;
var
clipBoard_tars
=
document
.
querySelectorAll
(
"
[data-clipboard-target]
"
)
;
for
(
var
c
=
0;
c
<
clipBoard_tars
.
length
;
c
++
)
clipBoard_tars
[
c
].
dataset
.
clipboardTarget
=
"
#d
"
+
stamp
;
var
_sideNums
=
document
.
getElementById
(
"
vsSide
"
)
;
for
(
var
l
=
0;
l
<
HollowArr
.
length
;
l
++
){
_containerBox
.
append
(
returnLine
(
HollowArr
[
l
]))
;
var
tmpSpan
=
returnSpan
(
""
,
l
+
1
)
;
tmpSpan
.
style
=
"
display: block; width: 40px; text-align: right; padding-right: 10px; float: left; font-size: 14px; height:
"
+
config
.
lineHeight
;
_sideNums
.
append
(
tmpSpan
)
;
}
var
g_Span
=
_sideNums
.
querySelectorAll
(
"
span
"
)
;
if
(
_sideNums
.
innerHTML
)
g_Span
[
g_Span
.length
-
1
].
style
.
borderBottomRightRadius
=
"
4px
"
;
var
cb
=
document
.
getElementById
(
"
codeBox
"
)
;
var
codeHeight
=
parseFloat
(
window
.
getComputedStyle
(
codeBox
,
""
).
getPropertyValue
(
"
height
"
))
;
console
.
log
(
codeHeight
)
var
expandBtn
=
document
.
querySelector
(
"
.expandBtn
"
)
;
var
tog
=
{
"
expand
"
:
function
(){
document
.
getElementById
(
"
banner
"
).
style
.
borderTopRightRadius
=
"
8px
"
;
// cb.style.maxHeight = codeHeight + "px";
cb
.
style
.
overflow
=
"
auto
"
;
return
"
SHRINK
"
;
},
"
shrink
"
:
function
(){
document
.
getElementById
(
"
banner
"
).
style
.
borderTopRightRadius
=
0;
// cb.style.maxHeight = config.maxHeight + "px";
cb
.
style
.
overflow
=
"
auto
"
;
return
"
EXPAND
"
;
}
}
;
if
(
codeHeight
>
config
.
maxHeight
){
expandBtn
.
style
.
display
=
"
block
"
;
tog
[
"
shrink
"
]()
;
expandBtn
.
onclick
=
function
(){
var
lbl
=
this
.
innerHTML
;
this
.
innerHTML
=
(
lbl
===
"
EXPAND
"
?
tog
[
"
expand
"
]()
:
tog
[
"
shrink
"
]())
;
}
}
else
{
expandBtn
.
style
.
display
=
"
none
"
;
}
// 最終結果在看控制檯處輸出查看
console
.
log
(
document
.
getElementById
(
"
codePart
"
).
innerHTML
)
;
function
returnLine
(
array
){
var
oDiv
=
document
.
createElement
(
"
div
"
)
;
var
bFill
=
config
.
highLight
[
0
]
;
oDiv
.
style
=
"
height:
"
+
config
.
lineHeight
+
"
; line-height:
"
+
config
.
lineHeight
+
"
; font-size:
"
+
config
.
fontSize
+
"
;
"
;
if
(
!
bFill
)
oDiv
.
style
.
color
=
config
.
highLight
[
1
]
;
for
(
var
k
=
0;
k
<
array
.
length
;
k
++
){
tspan
=
returnSpan
(
array
[
k
][
0
],
array
[
k
][
1
],
bFill
)
;
tspan
.
style
.
lineHeight
=
"
100%
"
;
oDiv
.
append
(
tspan
)
;
}
var
groupSpan
=
oDiv
.
querySelectorAll
(
"
span
"
)
;
if
(
oDiv
.
innerHTML
)
groupSpan
[
groupSpan
.length
-
1
].
style
.
paddingRight
=
"
20px
"
;
return
oDiv
;
}
function
returnSpan
(
cr
,
ct
,
fill
=
true
){
var
oSpan
=
document
.
createElement
(
"
span
"
)
;
oSpan
.
innerHTML
=
ct
;
if
(
!
cr
)
return
oSpan
;
if
(
fill
)
oSpan
.
style
.
color
=
cr
;
return
oSpan
;
}
function
format
(){
var
stampColors
=
{
// 左上角圓點顏色主題集合
"
html
"
:
"
#d13239
"
,
"
css
"
:
"
#4286f4
"
,
"
js
"
:
"
#fbb507
"
,
"
txt
"
:
"
#373a41
"
,
"
plist
"
:
"
#8bc34a
"
}
var
oCodeBox
=
document
.
getElementById
(
"
codeBox
"
)
;
var
oBanner
=
document
.
getElementById
(
"
banner
"
)
;
var
bannerStamp
=
document
.
getElementById
(
"
bannerStamp
"
)
;
var
bannerTitle
=
document
.
getElementById
(
"
bannerTitle
"
)
;
var
oVsSide
=
document
.
getElementById
(
"
vsSide
"
)
;
var
oOuter
=
document
.
getElementById
(
"
containerOuter
"
)
;
var
theStampColor
=
config
.
stampColor
;
var
configTheme
=
config
.
theme
;
if
(
config
.
maxHeight
){
oCodeBox
.
dataset
.
maxHeight
=
config
.
maxHeight
;
}
;
if
(
!
config
.
stampColor
)
theStampColor
=
stampColors
[
config
.
fileName
.
split
(
"
.
"
).
pop
()]
;
oCodeBox
.
style
.
fontFamily
=
config
.
fontFamily
;
oCodeBox
.
style
.
lineHeight
=
config
.
lineHeight
;
bannerTitle
.
innerText
=
config
.
fileName
;
bannerStamp
.
querySelector
(
"
span
"
).
style
.
backgroundColor
=
theStampColor
;
oBanner
.
style
.
backgroundColor
=
themes
[
configTheme
].
c_title_bg
;
bannerTitle
.
style
.
color
=
themes
[
configTheme
].
c_title_fg
;
oOuter
.
style
.
backgroundColor
=
themes
[
configTheme
].
c_editor_bg
;
oVsSide
.
style
.
backgroundColor
=
themes
[
configTheme
].
c_sideNum_bg
;
oVsSide
.
style
.
color
=
themes
[
configTheme
].
c_sideNum_fg
;
}
}
new
ClipboardJS
(
'
[data-clipboard-target]
'
)
;
<
/
script
>