Rule34 Combined Script

Combines functionality: Open all links in a div and download highest resolution MP4 video.

  1. // ==UserScript==
  2. // @name Rule34 Combined Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Combines functionality: Open all links in a div and download highest resolution MP4 video.
  6. // @author Your Name
  7. // @match *://*rule34*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. // ---------------------------
  15. // Functionality 1: Open all links in a specific div
  16. // ---------------------------
  17. const targetDivSelector = '.thumbs.clearfix'; // CSS 선택자
  18.  
  19. document.addEventListener('keydown', (event) => {
  20. if (event.key === '`') {
  21. const targetDiv = document.querySelector(targetDivSelector);
  22. if (!targetDiv) {
  23. alert('대상 div를 찾을 수 없습니다.');
  24. return;
  25. }
  26.  
  27. const links = targetDiv.querySelectorAll('a[href]');
  28. if (links.length === 0) {
  29. alert('열 URL이 없습니다.');
  30. return;
  31. }
  32.  
  33. links.forEach(link => {
  34. const url = link.href;
  35. if (url) window.open(url, '_blank');
  36. });
  37. }
  38. });
  39.  
  40. // ---------------------------
  41. // Functionality 2: Download the highest resolution MP4 from rule34video.com
  42. // ---------------------------
  43. if (window.location.href.startsWith('https://rule34video.com/video')) {
  44. window.addEventListener('load', () => {
  45. const links = document.querySelectorAll('a.tag_item');
  46.  
  47. if (!links || links.length === 0) {
  48. console.log("No video links found.");
  49. return;
  50. }
  51.  
  52. let bestLink = null;
  53. let bestResolution = 0;
  54.  
  55. links.forEach(link => {
  56. const text = link.textContent.trim();
  57. if (text.includes('MP4')) {
  58. const resolutionMatch = text.match(/(\d+)p/);
  59. if (resolutionMatch) {
  60. const resolution = parseInt(resolutionMatch[1], 10);
  61. if (resolution > bestResolution) {
  62. bestResolution = resolution;
  63. bestLink = link;
  64. }
  65. }
  66. }
  67. });
  68.  
  69. if (bestLink) {
  70. const downloadUrl = bestLink.href;
  71. console.log(`Best video found: ${downloadUrl}`);
  72. const anchor = document.createElement('a');
  73. anchor.href = downloadUrl;
  74. anchor.download = '';
  75. document.body.appendChild(anchor);
  76. anchor.click();
  77. document.body.removeChild(anchor);
  78. } else {
  79. console.log("No suitable MP4 video found.");
  80. }
  81. });
  82. }
  83. })();