phpBB New Topics

Generates button which opens all new topics of phpBB3-boards in tabs.

  1. // ==UserScript==
  2. // @name phpBB New Topics
  3. // @namespace http://openuserjs.org/users/ardiman
  4. // @description Generates button which opens all new topics of phpBB3-boards in tabs.
  5. // @description:de-DE Neben dem Button "Neues Thema" wird eine Schaltfläche erstellt, die alle neuen Posts in Tabs öffnet.
  6. // @grant GM_openInTab
  7. // @homepage https://github.com/ardiman/userscripts/tree/master/phpbbnewtopics
  8. // @icon https://raw.githubusercontent.com/ardiman/userscripts/master/scriptlogo.gif
  9. // @include */viewforum.php*
  10. // @license CC-BY-NC-SA-3.0; https://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
  11. // @license MIT; https://opensource.org/licenses/MIT
  12. // @supportURL https://github.com/ardiman/userscripts/issues
  13. // @version 1.1.0
  14. // @date 2017-11-19
  15. // ==/UserScript==
  16.  
  17. (function (){
  18.  
  19. // Konfiguration
  20. var maxlnks = 0; // 0=open all new threads, 10=open first 10 new threads
  21. var showBtnIf = 1; // 0=button will always be shown, 5=show only, if there are more than 4 new threads
  22. var useTimeout = true; // don't attempt delay on thread-read cookie setting - YMMV - the timeout delay didn't work for me, so =false
  23. var tOut = 800; // set timeout in milliseconds for opening (cookies won't be stored if too low!)
  24. var oMode = false; // =true: show first *unread* post, =false: show first post/beginning of thread
  25. // Ende der Konfiguration
  26.  
  27. /* x-browser event register */
  28. function addEvent(elm, evType, fn, useCapture) {
  29. if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true; }
  30. else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r; }
  31. else { elm['on' + evType] = fn; }
  32. }
  33.  
  34. /* x-browser open tab */
  35. function openTab(url) {
  36. if (typeof GM_openInTab != 'undefined') GM_openInTab(url);
  37. // if (typeof GM_openInTab != 'undefined') chromeWin.openNewTabWith(url,url,null,true);
  38. else if (typeof PRO_openInTab != 'undefined') PRO_openInTab(url,2);
  39. else window.open(url);
  40. }
  41.  
  42. var f = 0;
  43. var newposts = new Array();
  44. // alle Links zu neuen Beitraegen finden
  45. var lnks = document.evaluate("//a[contains(@href,'&view=unread#unread') and (not(contains(@class, 'row-item-link')) and not (contains(@class, 'icon-link')))]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE , null);
  46.  
  47. for (var i=0; i < lnks.snapshotLength; i++) {
  48. thisnode = lnks.snapshotItem(i);
  49. if (oMode) {
  50. newposts.push(thisnode.href); // den direkten Link zum ungelesen Beitrag speichern
  51. } else {
  52. newposts.push(thisnode.href.replace(/&view=unread#unread/, "")); // (bereinigten) Link zum Thread speichern
  53. }
  54. f++
  55. // falls nur die ersten x neuen Beitraege geoeffnet werden sollen, dann raus hier:
  56. if (f+1 > maxlnks && maxlnks > 0) break;
  57. }
  58.  
  59. // Button generieren, sofern noetig
  60. if (f >= showBtnIf) {
  61. // Zieldiv finden - bei phpBB 3.2 ist erster div-Abschnitt mit class=action-bar bar-top derjenige mit dem Button "NeuesThema" -> da soll's also hin
  62. var targetnode = document.evaluate("//div[@class='action-bar bar-top']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  63. if (targetnode.snapshotItem(0) === null) {
  64. // Code fuer aeltere phpBB-Versionen
  65. var targetnode = document.evaluate("//div[@class='buttons']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  66. }
  67. var btn = targetnode.snapshotItem(0).appendChild(document.createElement('a'));
  68. var stricon='</span><i class="icon fa-rocket fa-fw" aria-hidden="true"></i>';
  69. if (f > 1) {
  70. btn.innerHTML = "<span>&Ouml;ffne " + f + " neue Beitr&auml;ge "+stricon;
  71. } else {
  72. btn.innerHTML = "<span>&Ouml;ffne neuen Beitrag "+stricon;
  73. }
  74. btn.className='button';
  75. btn.id='gmphpbbnewtopics';
  76.  
  77. addEvent(btn, "click",
  78. function(e) {
  79. if (maxlnks===0) this.style.display = 'none';
  80. if (e && e.target) e.preventDefault();
  81. else window.event.returnValue = false;
  82. if (useTimeout) {
  83. var i = -1;
  84. function inner() {
  85. if(++i < f) openTab(newposts[i]);
  86. else clearInterval(timer);
  87. }
  88. var timer = setInterval(inner, tOut);
  89. } else {
  90. for (var i=0; i < newposts.length; i++)
  91. openTab(newposts[i]);
  92. }
  93. }
  94. , false);
  95. }
  96. })();
  97.