Tabun Keyboard (Comments)

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

  1. // ==UserScript==
  2. // @name Tabun Keyboard (Comments)
  3. // @namespace https://tabun.everypony.ru/
  4. // @version 0.3
  5. // @description Клавиатурная навигация по комментам на табуне.
  6. // @author Lunavod
  7. // @match https://tabun.everypony.ru/blog/*/*.html
  8. // @match https://tabun.everypony.ru/blog/*.html
  9. // @match https://tabun.everypony.ru/talk/read/*/
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. /*
  14. CTRL+SPACE - перейти к следующему непрочитанному комментарию.
  15. ALT+U - обновить комментарии. CTRl+(UP/DOWN) - перейти к комменту выше/ниже.
  16. CTRL+DOWN - перейти к комменту ниже.
  17. ALT+(UP/DOWN) - проголосовать +/- за выбранный комментарий.
  18. ALT+R - показать/скрыть форму ответа на выбранный комментарий.
  19. ALT+N - показать/скрыть форму нового комментария.
  20. ALT+SHIFT+P - перейти к комментарию-родителю
  21. */
  22.  
  23. (function() {
  24. 'use strict';
  25.  
  26. function goTo(d){
  27. var comments = [...document.querySelectorAll('.comment')];
  28. var cur_comm = document.querySelector('.comment-current') || comments[0];
  29. var cur_index = comments.indexOf(cur_comm);
  30. ls.comments.scrollToComment(comments[cur_index+d].getAttribute('data-id'));
  31. }
  32.  
  33. function voteCurr(d) {
  34. var cur_comm = document.querySelector('.comment-current');
  35. if (!cur_comm) {
  36. return;
  37. }
  38. return ls.vote.vote(cur_comm.getAttribute('data-id'),this,d,'comment');
  39. }
  40.  
  41. document.addEventListener('keyup', (e)=>{
  42. if (e.ctrlKey && e.code=="Space") {
  43. ls.comments.goToNextComment();
  44. }
  45. if (e.ctrlKey && !e.shiftKey && e.code=="ArrowUp") {
  46. goTo(-1);
  47. }
  48. if (e.ctrlKey && !e.shiftKey && e.code=="ArrowDown") {
  49. goTo(1);
  50. }
  51. if (e.altKey&& e.code=="ArrowUp") {
  52. voteCurr(1);
  53. }
  54. if (e.altKey && e.code=="ArrowDown") {
  55. voteCurr(-1);
  56. }
  57. if (e.altKey && e.code=="KeyU") {
  58. document.querySelector('#update-comments').click();
  59. }
  60. if (e.altKey && e.code=="KeyR") {
  61. var cur_comm = document.querySelector('.comment-current');
  62. if (!cur_comm) {
  63. return;
  64. }
  65. ls.comments.toggleCommentForm(cur_comm.getAttribute('data-id'));
  66. }
  67. if (e.altKey && e.code=="KeyN") {
  68. ls.comments.toggleCommentForm(0);
  69. }
  70. if (e.shiftKey && e.altKey && e.code=="KeyP") {
  71. var a = document.querySelector('.comment-current .goto-comment-parent a');
  72. if (!a) {
  73. return;
  74. }
  75. a.click();
  76. }
  77. });
  78. })();