Wykop - scroll to unread comment

Scrolls window to first/next unread comment @ wykop.pl

当前为 2014-06-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Wykop - scroll to unread comment
  3. // @description Scrolls window to first/next unread comment @ wykop.pl
  4. // @namespace Wykop scripts
  5. // @include http://www.wykop.pl/link/*
  6. // @version 1.1
  7. // @license MIT License
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. if(document.getElementsByClassName('nav fix-b-border')[0].getElementsByTagName('a')[0].href.indexOf('/unreadCommentsToggle/')>0)
  13. {
  14. var nowe_komcie = document.getElementsByClassName('wblock lcontrast dC newComment');
  15. var ile_nowych = nowe_komcie.length;
  16. var aktual_poz = -1;
  17. function dodaj_button(komcie_node, ii)
  18. {
  19. if (!ile_nowych) return;
  20. var button_node = document.createElement('button');
  21. if (ii < ile_nowych - 1)
  22. {
  23. button_node.innerHTML = 'NEXT';
  24. button_node.val = ii + 1;
  25. button_node.onclick = function() {
  26. nowe_komcie[this.val].scrollIntoView(true);
  27. window.scrollBy(0, -56);
  28. aktual_poz = ii + 1;
  29. }; /* button_node.onclick = function(){nowe_komcie[ii+1].scrollIntoView(true);};*/
  30. }
  31. else
  32. {
  33. button_node.onclick = function() {
  34. nowe_komcie[0].scrollIntoView(true);
  35. window.scrollBy(0, -56);
  36. aktual_poz = 0;
  37. };
  38. button_node.innerHTML = 'FIRST';
  39. }
  40. komcie_node.appendChild(button_node);
  41. }
  42. for (var i = 0; i < ile_nowych; ++i)
  43. {
  44. dodaj_button(nowe_komcie[i], i);
  45. }
  46. var button_node = document.createElement('button');
  47. button_node.innerHTML = 'FIRST';
  48. button_node.onclick = function () {
  49. nowe_komcie[0].scrollIntoView(true);
  50. window.scrollBy(0, -56);
  51. aktual_poz = 0;
  52. }; /* document.getElementById('comments-list-entry').appendChild(button_node);*/
  53. document.getElementById('itemsStream').insertBefore(button_node, document.getElementById('itemsStream').firstChild);
  54. function nastepny(e)
  55. {
  56. e = e || window.event;
  57. if (e.keyCode == '220')
  58. {
  59. aktual_poz = (aktual_poz+1)%ile_nowych;
  60. nowe_komcie[aktual_poz].scrollIntoView(true);
  61. window.scrollBy(0, -56);
  62. }
  63. }
  64.  
  65. document.onkeydown = nastepny;
  66. }
  67. void 0;