xenForo - New Topics

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

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