Tabun Keyboard (Comments)

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

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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();
        }
    });
})();