-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOpen All Gallery Images.user.js
123 lines (103 loc) · 3.95 KB
/
Open All Gallery Images.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// ==UserScript==
// @name Open All Gallery Images
// @namespace http://userscripts.org/users/478287
// @description Opens all the posts on a page in a new tab.
// @include http*://*e621.net/*
// @exclude https://e621.net/post/show/*
// @include https://inkbunny.net/submissionsviewall.php*
// @exclude https://inkbunny.net/submissionview.php*
// @include http*://*booru.*/*
// @exclude http*://*booru.*/post/show/*
// @exclude http*://*booru.*/index.php?page=post&s=view&id=*
// @include http*://*rule34.xxx/*
// @exclude http*://*rule34.xxx/index.php?page=post&s=view&id=*
// @include http://thedoujin.com/index.php/categories/*
// @exclude http://thedoujin.com/index.php/pages/*
// @version 1.2.3
// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @copyright 2012-2015, Soraya Elcar (http://userscripts.org/users/soraya)
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// @downloadURL https://update.greasyfork.org/scripts/12062/Open%20All%20Gallery%20Images.user.js
// @updateURL https://update.greasyfork.org/scripts/12062/Open%20All%20Gallery%20Images.meta.js
// ==/UserScript==
var base_button_label = "Open all images in tabs!";
function contains(a, obj) {
var i = a.length;
while (i--) {
if (a[i] === obj) {
return true;
}
}
return false;
}
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function get_all_posts() {
// Gets all links to posts pages from the current page.
var regex = new RegExp(/\/post\/show\/\d+|page=post&s=view&id=\d+|\/pages\/\d+|submissionview\.php/),
links = [],
all_links = document.getElementsByTagName("a"),
link;
for(var i=0; i<all_links.length; i++) {
href = all_links[i].href;
if (regex.test(href)) {
if (!(contains(links, href))) {
links.push(href);
}
}
}
return links;
}
function open_all_in_tabs() {
// Open all the links in the current posts page as new tabs.
var all_links = get_all_posts().reverse();
for (var i=0; i<all_links.length; i++) {
window.setTimeout(GM_openInTab, 500*i, all_links[i]);
}
// Set the button to green and let the user know we're done opening tabs.
var button = document.getElementById("openAllImagesInTabsButton");
button.style.background = '#00FF00';
button.value = base_button_label + " (Done.)";
button.disabled = false;
}
function do_button() {
// Disable the button so people don't get 100000 tabs.
var button = document.getElementById("openAllImagesInTabsButton");
button.disabled = true;
button.style.background = '#FF0000';
button.value = base_button_label + " (Working...)";
// Now load all the images:
open_all_in_tabs();
}
function inject_button() {
var button = document.createElement("input");
button.id = "openAllImagesInTabsButton";
button.value = base_button_label;
button.type = 'button';
button.onclick = do_button;
var targets = [document.getElementById("navbar"),
getElementByXpath('/html/body/div[1]/div'),
getElementByXpath('/html/body/center/div/div[5]/div[2]/div[4]'),
getElementByXpath('/html/body/div[5]/div[3]'),
getElementByXpath('/html/body/div[6]/div[3]'),
getElementByXpath('//*[@id="main-menu"]'),
];
console.log(targets);
for (var index in targets) {
var target = targets[index];
if (target === null) {
continue;
}
console.log(target);
target.appendChild(button);
}
}
window.addEventListener("load", function(e) {
GM_registerMenuCommand("Open all in tabs!", open_all_in_tabs, 'a');
inject_button();
}, false);
$(document).ready(function() {
inject_button();
});