-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (61 loc) · 1.75 KB
/
script.js
File metadata and controls
67 lines (61 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
*
* @Name: git-conflict-resolver-web
* @Author: Max Base
* @Repository: https://github.com/BaseMax/git-conflict-resolver-web
* @License: MIT
* @Date: 05/17/2025
*
**/
// Variables
let outputClickedOnce = false;
// Functions
function resolveConflicts() {
const text = document.getElementById('input').value;
const mode = document.querySelector('input[name="mode"]:checked').value;
const lines = text.split('\n');
const output = [];
let inConflict = false;
let local = [], remote = [], readingRemote = false;
for (let line of lines) {
if (line.startsWith('<<<<<<<')) {
inConflict = true;
local = [];
remote = [];
readingRemote = false;
} else if (line.startsWith('=======')) {
readingRemote = true;
} else if (line.startsWith('>>>>>>>')) {
inConflict = false;
output.push(...(mode === 'local' ? local : remote));
} else {
if (inConflict) {
(readingRemote ? remote : local).push(line);
} else {
output.push(line);
}
}
}
document.getElementById('output').textContent = output.join('\n');
}
function copyOutput() {
const output = document.getElementById('output');
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(output);
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
alert('Resolved content copied to clipboard!');
}
function selectOutput(event) {
if (!outputClickedOnce) {
const output = document.getElementById('output');
const range = document.createRange();
const selection = window.getSelection();
range.selectNodeContents(output);
selection.removeAllRanges();
selection.addRange(range);
outputClickedOnce = true;
}
}