phpBB New Topics

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

当前为 2017-01-19 提交的版本,查看 最新版本

  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/
  11. // @supportURL https://github.com/ardiman/userscripts/issues
  12. // @version 1.0.8
  13. // @date 2017-01-19
  14. // ==/UserScript==
  15.  
  16. (function (){
  17.  
  18. // Konfiguration
  19. var maxlnks = 0; // 0=open all new threads, 10=open first 10 new threads
  20. var showBtnIf = 1; // 0=button will always be shown, 5=show only, if there are more than 4 new threads
  21. var useTimeout = true; // don't attempt delay on thread-read cookie setting - YMMV - the timeout delay didn't work for me, so =false
  22. var tOut = 800; // set timeout in milliseconds for opening (cookies won't be stored if too low!)
  23. var oMode = false; // =true: show first *unread* post, =false: show first post/beginning of thread
  24. // Ende der Konfiguration
  25.  
  26. /* x-browser event register */
  27. function addEvent(elm, evType, fn, useCapture) {
  28. if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true; }
  29. else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r; }
  30. else { elm['on' + evType] = fn; }
  31. }
  32.  
  33. /* x-browser open tab */
  34. function openTab(url) {
  35. if (typeof GM_openInTab != 'undefined') GM_openInTab(url);
  36. // if (typeof GM_openInTab != 'undefined') chromeWin.openNewTabWith(url,url,null,true);
  37. else if (typeof PRO_openInTab != 'undefined') PRO_openInTab(url,2);
  38. else window.open(url);
  39. }
  40.  
  41. var f = 0;
  42. var newposts = new Array();
  43. // alle Links zu neuen Beitraegen finden
  44. 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);
  45.  
  46. for (var i=0; i < lnks.snapshotLength; i++) {
  47. thisnode = lnks.snapshotItem(i);
  48. if (oMode) {
  49. newposts.push(thisnode.href); // den direkten Link zum ungelesen Beitrag speichern
  50. } else {
  51. newposts.push(thisnode.href.replace(/&view=unread#unread/, "")); // (bereinigten) Link zum Thread speichern
  52. }
  53. f++
  54. // falls nur die ersten x neuen Beitraege geoeffnet werden sollen, dann raus hier:
  55. if (f+1 > maxlnks && maxlnks > 0) break;
  56. }
  57.  
  58. // Button generieren, sofern noetig
  59. if (f >= showBtnIf) {
  60. // 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
  61. var targetnode = document.evaluate("//div[@class='action-bar bar-top']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  62. if (targetnode.snapshotItem(0) === null) {
  63. // Code fuer aeltere phpBB-Versionen
  64. var targetnode = document.evaluate("//div[@class='buttons']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  65. }
  66. var btn = targetnode.snapshotItem(0).appendChild(document.createElement('button'));
  67. if (f > 1) {
  68. btn.innerHTML = "&Ouml;ffne " + f + " neue Beitr&auml;ge";
  69. } else {
  70. btn.innerHTML = "&Ouml;ffne neuen Beitrag";
  71. }
  72. btn.id='gmphpbbnewtopics';
  73. btn.style.background='#EEEEEE';
  74. btn.style.color='#BC2A4D';
  75. btn.style.fontWeight='bold';
  76. btn.style.fontSize='0.9em';
  77. btn.style.height='25px';
  78. btn.style.padding='0px 8px';
  79. addEvent(btn, "click",
  80. function(e) {
  81. if (maxlnks===0) this.style.display = 'none';
  82. if (e && e.target) e.preventDefault();
  83. else window.event.returnValue = false;
  84. if (useTimeout) {
  85. var i = -1;
  86. function inner() {
  87. if(++i < f) openTab(newposts[i]);
  88. else clearInterval(timer);
  89. }
  90. var timer = setInterval(inner, tOut);
  91. } else {
  92. for (var i=0; i < newposts.length; i++)
  93. openTab(newposts[i]);
  94. }
  95. }
  96. , false);
  97. }
  98. })();
  99.