lila/public/javascripts/inquiry.js

56 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2021-02-06 06:26:05 -07:00
$(function () {
const noteStore = lichess.storage.make('inquiry-note');
const usernameNoteStore = lichess.storage.make('inquiry-note-user');
const username = $('#inquiry .meat > .user-link').text().split(' ')[0];
if (username != usernameNoteStore.get()) noteStore.remove();
usernameNoteStore.set(username);
const noteTextArea = $('#inquiry .notes').find('textarea')[0];
$('#inquiry .notes').on('mouseenter', () => {
noteTextArea.focus();
noteTextArea.value = noteStore.get();
});
2021-04-19 01:11:38 -06:00
$('#inquiry .notes').on('input', () => setTimeout(() => noteStore.set(noteTextArea.value), 50));
$('#inquiry .notes').on('submit', noteStore.remove);
2020-09-09 06:57:36 -06:00
$('#inquiry .costello').on('click', () => {
2019-05-07 01:10:52 -06:00
$('#inquiry').toggleClass('hidden');
$('body').toggleClass('no-inquiry');
});
2017-09-12 17:00:36 -06:00
const nextStore = lichess.storage.makeBoolean('inquiry-auto-next');
2017-09-12 17:00:36 -06:00
2019-05-07 01:10:52 -06:00
if (!nextStore.get()) {
2020-09-22 03:08:03 -06:00
$('#inquiry .switcher input').prop('checked', false);
2019-05-07 01:10:52 -06:00
$('#inquiry input.auto-next').val('0');
}
2017-09-12 17:00:36 -06:00
2021-02-06 06:26:05 -07:00
$('#inquiry .switcher input').on('change', function () {
2019-05-07 01:10:52 -06:00
nextStore.set(this.checked);
$('#inquiry input.auto-next').val(this.checked ? '1' : '0');
2017-09-12 17:00:36 -06:00
});
Mousetrap.bind('d', () => $('#inquiry .actions.close form.process button[type="submit"]').trigger('click'));
$('#inquiry .atom p').each(function () {
$(this).html(
$(this)
.html()
2021-04-09 02:43:29 -06:00
.replaceAll(/(?:https:\/\/)?lichess\.org\/([\w\/]+)/g, '<a href="/$1">lichess.org/$1</a>')
);
});
$('#communication').on('click', '.line.author, .post.author', function () {
// Need to take username from the communcation page so that when being in inquiry for user A and checking communication of user B
// the notes cannot be mistakenly attributed to user A.
const username = $('#communication').find('.title').text().split(' ')[0];
const message = $(this).find('.message').text();
const storedNote = noteStore.get();
2021-08-06 11:18:19 -06:00
noteStore.set((storedNote ? storedNote + '\n' : '') + `${username}: "${message}"`);
const notes = $('#inquiry .notes span').addClass('flash');
setTimeout(() => notes.removeClass('flash'), 100);
});
});