-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
191 lines (155 loc) 路 5.96 KB
/
Copy pathscript.js
File metadata and controls
191 lines (155 loc) 路 5.96 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
const nameInput1 = document.getElementById('nameInput1');
const codeArea1 = document.getElementById('codeArea1');
const copyButton1 = document.getElementById('copyButton1');
const nameInput2 = document.getElementById('nameInput2');
const codeArea2 = document.getElementById('codeArea2');
const copyButton2 = document.getElementById('copyButton2');
const codeArea3 = document.getElementById('codeArea3');
const copyButton3 = document.getElementById('copyButton3');
const langSelect = document.getElementById('lang-select');
const translatableElements = {
title: document.getElementById('app-title'),
labelInput: document.getElementById('label-input'),
labelOutput: document.getElementById('label-output'),
labelCombined: document.getElementById('label-combined'),
guideLabel: document.getElementById('guide-label'),
guideLink: document.getElementById('guide-link'),
steamGroupLink: document.getElementById('steam-group-link')
};
window.LINKED_BELT_LOCALES = window.LINKED_BELT_LOCALES || {};
const originalCode1 = `/c
local player = game.players[1]
local position = player.position
local offset = {x = 0, y = -1}
local chest_position = {x = position.x + offset.x, y = position.y + offset.y}
local entity = player.surface.create_entity({
name = "linked-belt",
position = chest_position,
force = player.force })
entity.name_tag = "FCTteam"`;
const originalCode2 = `/c
local player = game.players[1]
local position = player.position
local offset = {x = 0, y = -1}
local chest_position = {x = position.x + offset.x, y = position.y + offset.y}
local entity = player.surface.create_entity({
name = "linked-belt",
position = chest_position,
force = player.force })
entity.name_tag = "FCTteam"`;
const originalCode3 = `/c
local i = game.get_entity_by_tag('FCTteam1')
local o = game.get_entity_by_tag('FCTteam2')
i.linked_belt_type = 'input'
o.linked_belt_type = 'output'
i.connect_linked_belts(o)`;
function updateCombinedCode() {
const tag1 = nameInput1.value || 'FCTteam1';
const tag2 = nameInput2.value || 'FCTteam2';
const updatedCode1 = originalCode1.replace(/entity\.name_tag = ".*?"/, `entity.name_tag = "${tag1}"`);
codeArea1.value = updatedCode1;
const updatedCode2 = originalCode2.replace(/entity\.name_tag = ".*?"/, `entity.name_tag = "${tag2}"`);
codeArea2.value = updatedCode2;
const combinedCode = originalCode3
.replace(/'FCTteam1'/, `'${tag1}'`)
.replace(/'FCTteam2'/, `'${tag2}'`);
codeArea3.value = combinedCode;
}
function showCopyFeedback(button) {
const feedbackSpan = button.nextElementSibling;
button.classList.add('is-copying');
feedbackSpan.classList.add('show');
setTimeout(() => {
button.classList.remove('is-copying');
}, 500);
setTimeout(() => {
feedbackSpan.classList.remove('show');
}, 2000);
}
function getSavedLanguage() {
const saved = localStorage.getItem('linked-belt-lang');
if (saved && langSelect.querySelector(`option[value="${saved}"]`)) {
return saved;
}
return 'ru';
}
function applyLocale(locale) {
const data = window.LINKED_BELT_LOCALES[locale];
if (!data) {
return;
}
document.documentElement.lang = locale;
document.title = data.pageTitle;
translatableElements.title.textContent = data.appTitle;
translatableElements.labelInput.textContent = data.loadingLabel;
translatableElements.labelOutput.textContent = data.unloadingLabel;
translatableElements.labelCombined.textContent = data.mergeLabel;
translatableElements.guideLabel.textContent = data.guideLabel;
translatableElements.guideLink.textContent = data.guideLinkText;
translatableElements.steamGroupLink.textContent = data.steamGroupLabel;
nameInput1.placeholder = data.inputPlaceholder;
nameInput2.placeholder = data.outputPlaceholder;
copyButton1.textContent = data.copyButton;
copyButton2.textContent = data.copyButton;
copyButton3.textContent = data.copyButton;
document.querySelectorAll('.copy-feedback').forEach((element) => {
element.textContent = data.copiedFeedback;
});
}
function loadLocaleScript(locale) {
if (window.LINKED_BELT_LOCALES[locale]) {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = `profiles/${locale}.js`;
script.onload = () => resolve();
script.onerror = () => reject(new Error(`Failed to load locale: ${locale}`));
document.head.appendChild(script);
});
}
async function setLanguage(locale) {
try {
await loadLocaleScript(locale);
applyLocale(locale);
localStorage.setItem('linked-belt-lang', locale);
} catch (error) {
if (locale !== 'ru') {
await setLanguage('ru');
langSelect.value = 'ru';
}
}
}
nameInput1.addEventListener('input', updateCombinedCode);
nameInput2.addEventListener('input', updateCombinedCode);
copyButton1.addEventListener('click', () => {
codeArea1.select();
document.execCommand('copy');
showCopyFeedback(copyButton1);
});
copyButton2.addEventListener('click', () => {
codeArea2.select();
document.execCommand('copy');
showCopyFeedback(copyButton2);
});
copyButton3.addEventListener('click', () => {
codeArea3.select();
document.execCommand('copy');
showCopyFeedback(copyButton3);
});
langSelect.addEventListener('change', async (event) => {
await setLanguage(event.target.value);
});
updateCombinedCode();
const initialLanguage = getSavedLanguage();
langSelect.value = initialLanguage;
setLanguage(initialLanguage);
document.addEventListener('mousemove', (event) => {
const body = document.body;
const { innerWidth, innerHeight } = window;
const { clientX, clientY } = event;
const moveStrength = 40;
const xPos = (clientX / innerWidth - 0.5) * moveStrength;
const yPos = (clientY / innerHeight - 0.5) * moveStrength;
body.style.backgroundPosition = `${-xPos}px ${-yPos}px`;
});