Sleazy Fork is available in English.

Gelbooru "Index" Button

Adds an "Index" button on post pages, allowing you to return to a search starting from the ID of the current post you're on

  1. // ==UserScript==
  2. // @name Gelbooru "Index" Button
  3. // @namespace https://gelbooru.com/
  4. // @version 1.0
  5. // @description Adds an "Index" button on post pages, allowing you to return to a search starting from the ID of the current post you're on
  6. // @match https://gelbooru.com/index.php?page=post&s=view*
  7. // @icon https://gelbooru.com/favicon.ico
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. if (location.hostname !== 'gelbooru.com') return;
  16.  
  17. const url = new URL(window.location.href);
  18. const urlParams = url.searchParams;
  19.  
  20. const currentId = urlParams.get('id');
  21. if (!currentId) return; // If no post ID, do nothing
  22.  
  23. urlParams.delete('id');
  24. urlParams.set('s', 'list');
  25.  
  26. const rawTags = urlParams.get('tags') || '';
  27. let decodedTags = decodeURIComponent(rawTags);
  28.  
  29. const newIdSearch = 'id:=<' + currentId;
  30.  
  31. const idSearchRegex = /id:=<\d+/i;
  32. if (idSearchRegex.test(decodedTags)) {
  33. decodedTags = decodedTags.replace(idSearchRegex, newIdSearch);
  34. } else {
  35. decodedTags = decodedTags.trim();
  36. if (decodedTags) decodedTags += ' ';
  37. decodedTags += newIdSearch;
  38. }
  39.  
  40. urlParams.set('tags', decodedTags.trim());
  41.  
  42. const finalUrl = `${url.origin}${url.pathname}?${urlParams.toString()}`;
  43.  
  44. const box = document.createElement('div');
  45. box.className = 'alert alert-info';
  46. box.style.textAlign = 'center';
  47. box.style.margin = '10px 0px';
  48. box.style.padding = '10px';
  49.  
  50. const indexLink = document.createElement('a');
  51. indexLink.textContent = 'Index';
  52. indexLink.href = finalUrl;
  53.  
  54. box.appendChild(indexLink);
  55.  
  56. const navContainers = document.querySelectorAll('.alert.alert-info');
  57. if (navContainers.length > 0) {
  58. navContainers[navContainers.length - 1].insertAdjacentElement('afterend', box);
  59. } else {
  60. const mainBody = document.querySelector('.mainBodyPadding');
  61. if (mainBody) mainBody.appendChild(box);
  62. }
  63. })();