Open All Gallery Images

Opens all the posts on a page in a new tab.

  1. // ==UserScript==
  2. // @name Open All Gallery Images
  3. // @namespace http://userscripts.org/users/478287
  4. // @description Opens all the posts on a page in a new tab.
  5. // @include http*://*e621.net/*
  6. // @exclude https://e621.net/post/show/*
  7. // @include https://inkbunny.net/submissionsviewall.php*
  8. // @exclude https://inkbunny.net/submissionview.php*
  9. // @include http*://*booru.*/*
  10. // @exclude http*://*booru.*/post/show/*
  11. // @exclude http*://*booru.*/index.php?page=post&s=view&id=*
  12. // @include http*://*rule34.xxx/*
  13. // @exclude http*://*rule34.xxx/index.php?page=post&s=view&id=*
  14. // @include http://thedoujin.com/index.php/categories/*
  15. // @exclude http://thedoujin.com/index.php/pages/*
  16. // @version 1.2.3
  17. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  18. // @copyright 2012-2015, Soraya Elcar (http://userscripts.org/users/soraya)
  19. // @grant GM_openInTab
  20. // @grant GM_registerMenuCommand
  21. // ==/UserScript==
  22.  
  23.  
  24. var base_button_label = "Open all images in tabs!";
  25.  
  26. function contains(a, obj) {
  27. var i = a.length;
  28. while (i--) {
  29. if (a[i] === obj) {
  30. return true;
  31. }
  32. }
  33. return false;
  34. }
  35.  
  36. function getElementByXpath(path) {
  37. return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  38. }
  39.  
  40. function get_all_posts() {
  41. // Gets all links to posts pages from the current page.
  42. var regex = new RegExp(/\/post\/show\/\d+|page=post&s=view&id=\d+|\/pages\/\d+|submissionview\.php/),
  43. links = [],
  44. all_links = document.getElementsByTagName("a"),
  45. link;
  46.  
  47. for(var i=0; i<all_links.length; i++) {
  48. href = all_links[i].href;
  49. if (regex.test(href)) {
  50. if (!(contains(links, href))) {
  51. links.push(href);
  52. }
  53. }
  54. }
  55. return links;
  56. }
  57.  
  58. function open_all_in_tabs() {
  59. // Open all the links in the current posts page as new tabs.
  60. var all_links = get_all_posts().reverse();
  61.  
  62. for (var i=0; i<all_links.length; i++) {
  63. window.setTimeout(GM_openInTab, 500*i, all_links[i]);
  64. }
  65.  
  66. // Set the button to green and let the user know we're done opening tabs.
  67. var button = document.getElementById("openAllImagesInTabsButton");
  68. button.style.background = '#00FF00';
  69. button.value = base_button_label + " (Done.)";
  70. button.disabled = false;
  71. }
  72.  
  73. function do_button() {
  74. // Disable the button so people don't get 100000 tabs.
  75. var button = document.getElementById("openAllImagesInTabsButton");
  76. button.disabled = true;
  77. button.style.background = '#FF0000';
  78. button.value = base_button_label + " (Working...)";
  79.  
  80. // Now load all the images:
  81. open_all_in_tabs();
  82.  
  83. }
  84.  
  85.  
  86. function inject_button() {
  87. var button = document.createElement("input");
  88. button.id = "openAllImagesInTabsButton";
  89. button.value = base_button_label;
  90. button.type = 'button';
  91. button.onclick = do_button;
  92. var targets = [document.getElementById("navbar"),
  93. getElementByXpath('/html/body/div[1]/div'),
  94. getElementByXpath('/html/body/center/div/div[5]/div[2]/div[4]'),
  95. getElementByXpath('/html/body/div[5]/div[3]'),
  96. getElementByXpath('/html/body/div[6]/div[3]'),
  97. getElementByXpath('//*[@id="main-menu"]'),
  98. ];
  99. console.log(targets);
  100. for (var index in targets) {
  101. var target = targets[index];
  102. if (target === null) {
  103. continue;
  104. }
  105. console.log(target);
  106. target.appendChild(button);
  107. }
  108. }
  109.  
  110. window.addEventListener("load", function(e) {
  111. GM_registerMenuCommand("Open all in tabs!", open_all_in_tabs, 'a');
  112. inject_button();
  113. }, false);
  114.  
  115. $(document).ready(function() {
  116. inject_button();
  117. });