RyuuGames F95Zone Search Button

Adds a button to search the game title on F95Zone from RyuuGames

  1. // ==UserScript==
  2. // @name RyuuGames F95Zone Search Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description Adds a button to search the game title on F95Zone from RyuuGames
  6. // @author FunkyJustin
  7. // @license MIT
  8. // @match https://www.ryuugames.com/*
  9. // @grant none
  10. // @supportURL https://greasyfork.org/en/scripts/497408-ryuugames-f95zone-search-button/feedback
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Function to add the search button
  17. function addSearchButton() {
  18. // Get the header element with class 'td-post-title'
  19. let header = document.querySelector('header.td-post-title');
  20. if (header) {
  21. // Get the H1 element within the header
  22. let h1 = header.querySelector('h1.entry-title');
  23. if (h1 && !header.querySelector('.f95zone-search-button')) { // Check if the button already exists
  24. // Extract the game title from the H1 text
  25. let titleText = h1.textContent;
  26. let gameTitle = titleText.replace(/^\[ENG\] /, '').replace(/\s*\(RJ\d+\)\s*$/, '');
  27.  
  28. // Create the search button
  29. let searchButton = document.createElement('button');
  30. searchButton.textContent = 'Search on F95Zone';
  31. searchButton.style.marginTop = '10px';
  32. searchButton.style.display = 'block';
  33. searchButton.className = 'f95zone-search-button'; // Add a class for easier identification
  34.  
  35. // Define the search URL
  36. let searchUrl = 'https://f95zone.to/sam/latest_alpha/#/cat=games/page=1/search=' + encodeURIComponent(gameTitle);
  37.  
  38. // Add event listener to the button to open the search URL in a new tab
  39. searchButton.addEventListener('click', function() {
  40. window.open(searchUrl, '_blank');
  41. });
  42.  
  43. // Insert the button after the H1 element
  44. h1.insertAdjacentElement('afterend', searchButton);
  45. }
  46. }
  47. }
  48.  
  49. // Observe changes to the body to ensure the button is added even if content is loaded dynamically
  50. const observer = new MutationObserver(addSearchButton);
  51. observer.observe(document.body, { childList: true, subtree: true });
  52.  
  53. // Initial call in case the content is already loaded
  54. addSearchButton();
  55. })();