Wykop - scroll to unread comment

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

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

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