Tabun Keyboard (Comments)

Клавиатурная навигация по комментам на табуне.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Tabun Keyboard (Comments)
// @namespace    https://tabun.everypony.ru/
// @version      0.3
// @description  Клавиатурная навигация по комментам на табуне.
// @author       Lunavod
// @match        https://tabun.everypony.ru/blog/*/*.html
// @match        https://tabun.everypony.ru/blog/*.html
// @match        https://tabun.everypony.ru/talk/read/*/
// @grant        none
// ==/UserScript==

/*
CTRL+SPACE - перейти к следующему непрочитанному комментарию.
ALT+U - обновить комментарии. CTRl+(UP/DOWN) - перейти к комменту выше/ниже.
CTRL+DOWN - перейти к комменту ниже.
ALT+(UP/DOWN) - проголосовать +/- за выбранный комментарий.
ALT+R - показать/скрыть форму ответа на выбранный комментарий.
ALT+N - показать/скрыть форму нового комментария.
ALT+SHIFT+P - перейти к комментарию-родителю
*/

(function() {
    'use strict';

    function goTo(d){
        var comments = [...document.querySelectorAll('.comment')];
        var cur_comm = document.querySelector('.comment-current') || comments[0];
        var cur_index = comments.indexOf(cur_comm);
        ls.comments.scrollToComment(comments[cur_index+d].getAttribute('data-id'));
    }

    function voteCurr(d) {
        var cur_comm = document.querySelector('.comment-current');
        if (!cur_comm) {
            return;
        }
        return ls.vote.vote(cur_comm.getAttribute('data-id'),this,d,'comment');
    }

    document.addEventListener('keyup', (e)=>{
        if (e.ctrlKey && e.code=="Space") {
            ls.comments.goToNextComment();
        }
        if (e.ctrlKey && !e.shiftKey && e.code=="ArrowUp") {
            goTo(-1);
        }
        if (e.ctrlKey && !e.shiftKey && e.code=="ArrowDown") {
            goTo(1);
        }
        if (e.altKey&& e.code=="ArrowUp") {
            voteCurr(1);
        }
        if (e.altKey && e.code=="ArrowDown") {
            voteCurr(-1);
        }
        if (e.altKey && e.code=="KeyU") {
            document.querySelector('#update-comments').click();
        }
        if (e.altKey && e.code=="KeyR") {
            var cur_comm = document.querySelector('.comment-current');
            if (!cur_comm) {
                return;
            }
            ls.comments.toggleCommentForm(cur_comm.getAttribute('data-id'));
        }
        if (e.altKey && e.code=="KeyN") {
            ls.comments.toggleCommentForm(0);
        }
        if (e.shiftKey && e.altKey && e.code=="KeyP") {
            var a = document.querySelector('.comment-current .goto-comment-parent a');
            if (!a) {
                return;
            }
            a.click();
        }
    });
})();