Skip to content

Commit faa2734

Browse files
committed
Editor submissions
1 parent b0a17fe commit faa2734

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

editor.html

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,79 @@ <h1>Telegram Limits Editor</h1>
831831
static contentElement = null;
832832
static draggingType = null;
833833

834+
static async openHelp(source) {
835+
alert("We're already working on documentation. Until then, for guidance, please contact contributors directly.");
836+
}
837+
838+
static async suggestEdit() {
839+
try {
840+
const dialog = document.createElement('dialog');
841+
dialog.innerHTML = `
842+
<form method="dialog">
843+
<article>
844+
<p>
845+
<b>Note:</b> We do not accept translations through this form.
846+
Please go to <a href="https://crowdin.com/project/telegram-limits" target="_blank">Crowdin</a> for translation.
847+
</p>
848+
</article>
849+
<label>
850+
<span>Description:</span>
851+
<textarea id="description" rows="5" style="width: 100%;" placeholder="Describe changes you've made" maxlength="800"></textarea>
852+
</label>
853+
<label>
854+
<span>Contact:</span>
855+
<input id="contact" type="text" style="width: 100%;" placeholder="Telegram username, email, etc." maxlength="100">
856+
</label>
857+
<menu style="display: flex; padding: 0;">
858+
<button id="cancelButton" value="cancel" class="secondary">Cancel</button>
859+
<button id="sendButton" value="send" class="trailing-container">Send</button>
860+
</menu>
861+
</form>
862+
`;
863+
864+
dialog.querySelector('#cancelButton').addEventListener('click', () => {
865+
dialog.close();
866+
dialog.remove();
867+
});
868+
dialog.querySelector('#sendButton').addEventListener('click', async () => {
869+
try {
870+
const url = 'https://limits.tginfo.me/prop/suggest.php';
871+
872+
const data = {
873+
structure: this.structure,
874+
localization: this.localization,
875+
description: dialog.querySelector('#description').value,
876+
contact: dialog.querySelector('#contact').value,
877+
};
878+
879+
const response = await fetch(url, {
880+
method: 'POST',
881+
headers: {
882+
'Content-Type': 'application/json',
883+
},
884+
body: JSON.stringify(data),
885+
});
886+
887+
const responseText = await response.text();
888+
if (response.ok) {
889+
alert('✅ Suggestion sent successfully:\n\n' + responseText);
890+
} else {
891+
alert('⛔️ An error occurred while sending the suggestion:\n\n' + responseText);
892+
}
893+
} catch (e) {
894+
console.error(e);
895+
alert('An error occurred while sending the suggestion: ' + e.message);
896+
}
897+
});
898+
899+
document.body.appendChild(dialog);
900+
dialog.showModal();
901+
} catch (e) {
902+
console.error(e);
903+
alert('An error occurred while sending the suggestion: ' + e.message);
904+
}
905+
}
906+
834907
static async check() {
835908
if (!('showDirectoryPicker' in window)) {
836909
alert('Your browser does not support the File System Access API. ' +
@@ -1024,13 +1097,23 @@ <h1>Telegram Limits Editor</h1>
10241097
helpButton.classList.add('icon');
10251098
helpButton.classList.add('secondary');
10261099
helpButton.textContent = 'help';
1100+
helpButton.title = 'Help & Documentation';
10271101
helpButton.addEventListener('click', () => EditorUi.openHelp("toolbar"));
10281102
toolbar.appendChild(helpButton);
10291103

1104+
const sendButton = document.createElement('button');
1105+
sendButton.classList.add('icon');
1106+
sendButton.classList.add('secondary');
1107+
sendButton.textContent = 'send';
1108+
sendButton.title = 'Send The Edit to @tginfo';
1109+
sendButton.addEventListener('click', () => EditorUi.suggestEdit());
1110+
toolbar.appendChild(sendButton);
1111+
10301112
const saveButton = document.createElement('button');
10311113
saveButton.classList.add('icon');
10321114
saveButton.classList.add('secondary');
10331115
saveButton.textContent = 'save';
1116+
saveButton.title = 'Save to Disk';
10341117
saveButton.addEventListener('click', () => this.save());
10351118
toolbar.appendChild(saveButton);
10361119

0 commit comments

Comments
 (0)