Skip to content

Commit 8a85e04

Browse files
committed
Improve prevent-clipboard-write scriptlet
As discussed internally with team.
1 parent 0ddca72 commit 8a85e04

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/js/resources/prevent-clipboard-write.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,23 @@ function preventClipboardWrite(matches = '', ...varargs) {
5959
const div = doc.createElement('div');
6060
const span = doc.createElement('span');
6161
span.style = 'flex-grow:1;padding:0.5em 0 0.5em 0.5em;';
62-
const { domAlert } = extraArgs;
62+
const domAlert = extraArgs.domAlert.replace(/\\n/g, '\n');
6363
const placeholder = /\$\{text\}/.exec(domAlert);
6464
if ( placeholder ) {
6565
const code = doc.createElement('code');
66-
code.style = 'background-color:#ddc;font-family:monospace;padding:0.25em;user-select:none;word-break:break-all';
66+
const styles = [
67+
'background-color: #ddc',
68+
'display: inline-block',
69+
'font-family: monospace',
70+
'max-height: 8em',
71+
'overflow: auto',
72+
'padding: 0.25em',
73+
'word-break: break-all'
74+
];
75+
if ( Boolean(extraArgs.selectable ?? true) === false ) {
76+
styles.push('user-select: none');
77+
}
78+
code.style = styles.join(';');
6779
code.textContent = clipboardText;
6880
span.append(
6981
domAlert.slice(0, placeholder.index),
@@ -74,15 +86,15 @@ function preventClipboardWrite(matches = '', ...varargs) {
7486
span.append(domAlert);
7587
}
7688
const button = doc.createElement('button');
77-
button.style = 'padding:1em';
89+
button.style = 'font-size:32px;padding:0.5em';
7890
button.textContent = '×';
7991
button.addEventListener('click', ( ) => {
8092
if ( currentAlert === null ) { return; }
8193
currentAlert.remove();
8294
currentAlert = null;
8395
});
8496
div.append(span, button);
85-
div.style = 'background-color:beige;color:black;border:1px solid black;display:flex;font-size:medium;position:fixed;text-align:center;top:0;width:100%;z-index:2147483647';
97+
div.style = 'background-color:beige;color:black;border:1px solid black;display:flex;font-family:sans-serif;font-size:medium;position:fixed;top:0;white-space:pre-wrap;width:100%;z-index:2147483647';
8698
doc.documentElement.append(div);
8799
if ( currentAlert ) {
88100
currentAlert.remove();

0 commit comments

Comments
 (0)