-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpbb2_open_matched_topics_in_tabs.user.js
73 lines (64 loc) · 2.44 KB
/
phpbb2_open_matched_topics_in_tabs.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// ==UserScript==
// @name phpBB2 Open all matched topics in tabs
// @namespace http://www.laskikymppi.com/
// @description Inserts an Open all topics in tabs link to phpBB2 search pages.
// @include */search.php?*
// ==/UserScript==
// */
// 21-01-2009 hvrauhal
// 19-08-2008 v1.2.0 fheub http://userscripts.org/scripts/show/4681
// 21-03-2006 Copyright (c) 2006, JAPIO http://userscripts.org/scripts/show/3609
//
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
// --------------------------------------------------------------------
//
// Inserts an "Open all topics in tabs" link to phpBB2 search
// pages. Clicking the link opens all topics listed on the page in new tabs, at their last post.
//
// INSTALLATION
// First install Greasemonkey from https://addons.mozilla.org/en-US/firefox/addon/748
// Then install this script by revisiting this page
//
(function () {
function evaluateXPath(query) {
return document.evaluate(query, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}
function createNewTableCell() {
var td = document.createElement('td');
td.className = "gensmall";
td.align = "right";
td.valign = "bottom";
return td;
}
function collectAllTopicAnchors() {
return evaluateXPath("//a[contains(@href, 'viewtopic.php?p=')]");
}
function insertAfter(newElement, original) {
original.parentNode.insertBefore(newElement, original.nextSibling);
}
function openInTabs(anchors) {
var i;
for (i = 0; i < anchors.snapshotLength; i++) {
window.open(anchors.snapshotItem(i).href);
}
}
function createOpenInTabsAnchor(anchors) {
var anchor = document.createElement('a');
anchor.href = "#";
anchor.className = "gensmall";
anchor.innerHTML = 'Open all topics in tabs';
anchor.addEventListener('click', function () { openInTabs(anchors); }, true);
return anchor;
}
function lookupForumIndexCell() {
return evaluateXPath("//td/span/a[contains(@href, 'index.php')]/parent::*/parent::*").snapshotItem(0);
}
function insertActionToPage(anchors) {
var linkCell = createNewTableCell();
linkCell.appendChild(createOpenInTabsAnchor(anchors));
insertAfter(linkCell, lookupForumIndexCell());
}
insertActionToPage(collectAllTopicAnchors());
GM_log("Added open all topics in tabs to page.");
}());