|
34 | 34 |
|
35 | 35 | oReq = new XMLHttpRequest(); |
36 | 36 | oReq.addEventListener("load", function() { |
37 | | - let lines, start, deleteCount; |
| 37 | + let lines, start, deleteCount, lineSeparator; |
38 | 38 |
|
39 | 39 | // we'll append stuff in the loop below |
40 | 40 | container.innerHTML = '<p><a href="' + weburl + '" target="_blank" rel="noopener noreferrer">' + weburl + '</a></p>'; |
41 | 41 |
|
42 | | - lines = this.responseText.split(/\r\n|\n/); |
| 42 | + if (this.responseText.indexOf('\r\n') >= 0) { |
| 43 | + lineSeparator = '\r\n'; |
| 44 | + } else { |
| 45 | + lineSeparator = '\n'; |
| 46 | + } |
| 47 | + lines = this.responseText.split(lineSeparator); |
43 | 48 | start = violationLineNumber - contextLines; |
44 | 49 | if (start > 0) { |
45 | 50 | lines.splice(0, start); // remove lines before |
|
76 | 81 | tableBody.appendChild(tableRow); // append row to the table |
77 | 82 | }); |
78 | 83 | container.appendChild(table); |
| 84 | + |
| 85 | + if (navigator.clipboard) { |
| 86 | + let copyButton = document.createElement('button'); |
| 87 | + copyButton.classList.add('btn-clipboard'); |
| 88 | + copyButton.setAttribute('title', 'Copy to clipboard'); |
| 89 | + copyButton.appendChild(document.createTextNode('copy')); |
| 90 | + copyButton.onclick = function() { |
| 91 | + navigator.clipboard.writeText(lines.join(lineSeparator)); |
| 92 | + } |
| 93 | + container.appendChild(copyButton); |
| 94 | + } |
79 | 95 | }); |
80 | 96 |
|
81 | 97 | container.innerHTML = "<samp>fetching...</samp>"; |
|
0 commit comments