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