Skip to content

Commit 54cad7a

Browse files
committed
Make timestamps visually uncopyable and simplify the impl
1 parent 553fc2e commit 54cad7a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/gha_logs.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,22 @@ body {{
217217
background: #0C0C0C;
218218
color: #CCC;
219219
white-space: pre;
220+
padding-left: 29ch; // timestamp length + one space
221+
margin: 0;
220222
}}
221223
.timestamp {{
222224
color: #848484;
223225
text-decoration: none;
226+
position: absolute;
227+
left: 0;
228+
width: 28ch; // timestamp length
224229
}}
225230
.timestamp:hover {{
226231
text-decoration: underline;
227232
}}
233+
.timestamp::before {{
234+
content: attr(data-timestamp);
235+
}}
228236
.error-marker {{
229237
scroll-margin-bottom: 15vh;
230238
color: #e5534b;
@@ -276,9 +284,9 @@ body {{
276284
}}
277285
278286
// 3. Add a self-referencial anchor to all timestamps at the start of the lines
279-
const dateRegex = /^(\d{{4}}-\d{{2}}-\d{{2}}T\d{{2}}:\d{{2}}:\d{{2}}\.\d+Z)/gm;
280-
html = html.replace(dateRegex, (ts) =>
281-
`<a id="${{ts}}" href="#${{ts}}" class="timestamp">${{ts}}</a>`
287+
const dateRegex = /^(\d{{4}}-\d{{2}}-\d{{2}}T\d{{2}}:\d{{2}}:\d{{2}}\.\d+Z) /gm;
288+
html = html.replace(dateRegex, (match, ts) =>
289+
`<a id="${{ts}}" href="#${{ts}}" class="timestamp" data-timestamp="${{ts}}"></a>`
282290
);
283291
284292
// 4. Add a anchor around every "##[error]" string
@@ -338,11 +346,9 @@ body {{
338346
}});
339347
}}
340348
341-
// 8. Add a copy handler that force plain/text copy and removes the timestamps
342-
// from the copied selection.
343-
const dateRegexWithSpace = /^(\d{{4}}-\d{{2}}-\d{{2}}T\d{{2}}:\d{{2}}:\d{{2}}\.\d+Z )/gm;
349+
// 8. Add a copy handler that force plain/text copy
344350
document.addEventListener("copy", function(e) {{
345-
var text = window.getSelection().toString().replace(dateRegexWithSpace, '');
351+
var text = window.getSelection().toString();
346352
e.clipboardData.setData('text/plain', text);
347353
e.preventDefault();
348354
}});

0 commit comments

Comments
 (0)