Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1431584
pygments.copy.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
pygments.copy.js
View Options
/**
* Adapted from https://www.mediawiki.org/wiki/MediaWiki:Gadget-site-tpl-copy.js
* Original author: Krinkle
*/
// eslint-disable-next-line compat/compat
const
hasFeature
=
navigator
.
clipboard
&&
'writeText'
in
navigator
.
clipboard
;
if
(
hasFeature
)
{
// Add type=button to avoid form submission in preview
const
$btn
=
$
(
'<button>'
)
.
attr
(
'type'
,
'button'
)
.
text
(
mw
.
msg
(
'syntaxhighlight-button-copy'
)
)
.
on
(
'click'
,
function
()
{
const
btn
=
this
;
const
wrapper
=
btn
.
closest
(
'.mw-highlight-copy'
);
const
preNode
=
wrapper
&&
wrapper
.
querySelector
(
'pre'
);
const
content
=
preNode
&&
preNode
.
textContent
.
trim
();
try
{
navigator
.
clipboard
.
writeText
(
content
);
}
catch
(
e
)
{
return
;
}
const
prevLabel
=
btn
.
textContent
;
btn
.
textContent
=
mw
.
msg
(
'syntaxhighlight-button-copied'
);
setTimeout
(
()
=>
{
btn
.
textContent
=
prevLabel
;
},
5000
);
}
);
mw
.
hook
(
'wikipage.content'
).
add
(
(
$content
)
=>
{
$content
.
find
(
'.mw-highlight-copy:not(.mw-highlight-copy--bound)'
)
.
append
(
$btn
.
clone
(
true
)
)
.
addClass
(
'mw-highlight-copy--bound'
);
}
);
}
File Metadata
Details
Attached
Mime Type
text/x-asm
Expires
Sat, May 16, 20:48 (1 d, 10 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
cc/de/1ac91aba97c98e8152302a9475eb
Default Alt Text
pygments.copy.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment