Skip to content

Commit c1d1bc1

Browse files
authored
[StashRandomButton] Consistent Randomization on All Pages (#567)
1 parent 703c96a commit c1d1bc1

File tree

3 files changed

+80
-19
lines changed

3 files changed

+80
-19
lines changed

plugins/StashRandomButton/README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,43 @@ Adds a "Random" button to the Stash UI, letting you instantly jump to a random s
4040
- The button should appear on those pages.
4141

4242
## Usage
43-
Click the "Random" button in the navigation bar to jump to a random entity (scene, image, performer, studio, group, tag, or gallery) depending on your current page.
44-
- On internal entity pages (e.g., performer, studio, group, tag, gallery), the button picks a random scene or image from inside that entity.
43+
44+
Click the "Random" button in the navigation bar to instantly jump to a random item, with behavior depending on your current page:
45+
46+
- **Scenes:**
47+
- On the main scenes page, the button selects a random scene from all scenes in your library.
48+
- On a performer, studio, tag, or group *scenes* page, it picks a random scene **from within that entity**.
49+
- When viewing a scene's detail page, clicking "Random" again selects a random scene from **all scenes** (not just from the previous filter).
50+
51+
- **Groups:**
52+
- On the main groups page, the button picks a random group.
53+
- Inside a group (group's scenes page), it selects a random scene from within that group.
54+
55+
- **Galleries & Images:**
56+
- On the main galleries page, the button picks a random gallery.
57+
- Inside a gallery (gallery's page), it selects a random image from that gallery.
58+
- When viewing an individual image (image detail page), the button selects a random image from **all images in the database**, not just from the current gallery.
59+
60+
- **Performers:**
61+
- On the main performers page, it picks a random performer.
62+
- Inside a performer's page (performer's scenes), it selects a random scene from that performer.
63+
- When viewing a scene's detail page, clicking "Random" again picks a random scene from **all scenes**.
64+
65+
- **Studios:**
66+
- On the main studios page, the button picks a random studio.
67+
- Inside a studio's page (studio's scenes), it selects a random scene from that studio.
68+
- When viewing a scene's detail page, clicking "Random" again selects a random scene from **all scenes**.
69+
70+
- **Tags:**
71+
- On the main tags page, it picks a random tag.
72+
- Inside a tag's page (tag's scenes), it selects a random scene from that tag.
73+
- When viewing a scene's detail page, clicking "Random" again picks a random scene from **all scenes**, regardless of tag.
74+
75+
---
76+
77+
**Tip:** The Random button always selects from the *full library* when you are on a detail (scene or image) page, regardless of how you navigated there.
78+
79+
---
4580

4681
## Requirements
4782
- Stash version v0.27.2 or higher.
@@ -51,4 +86,11 @@ Click the "Random" button in the navigation bar to jump to a random entity (scen
5186
- Edit `random-button.js` to customize and reload plugins in Stash.
5287

5388
## Changelog
89+
- 2.0.1:
90+
- The Random button now works on scene and image detail pages: when viewing an individual scene or image, clicking "Random" selects a random scene or image from the entire database.
91+
- Improved context awareness for the Random button on all major Stash entities (scenes, performers, studios, tags, groups, galleries, images).
92+
- When inside a group, tag, studio, performer, or gallery, the button picks a random scene or image from within that entity.
93+
- When on a group, tag, studio, performer, or gallery detail page (not listing scenes/images), the Random button selects a random group, tag, studio, performer, or gallery respectively.
94+
- Updated documentation.
5495
- 2.0.0: Major upgrade! Now supports random navigation for performers, studios, groups, tags, galleries, and images (global and internal).
96+
- 1.1.0: Initial public release with support for random scenes.

plugins/StashRandomButton/random_button.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,48 @@
6666
async function randomButtonHandler() {
6767
const pathname = window.location.pathname.replace(/\/$/, '');
6868

69-
if (pathname === '/scenes') return randomGlobal('Scene', 'scenes', '/scenes/');
70-
if (pathname === '/performers') return randomGlobal('Performer', 'performers', '/performers/');
71-
if (pathname === '/groups') return randomGlobal('Group', 'groups', '/groups/');
72-
if (pathname === '/studios') return randomGlobal('Studio', 'studios', '/studios/');
73-
if (pathname === '/tags') return randomGlobal('Tag', 'tags', '/tags/');
74-
if (pathname === '/galleries') return randomGlobal('Gallery', 'galleries', '/galleries/');
75-
if (pathname === '/images') return randomGlobal('Image', 'images', '/images/');
76-
77-
// --- INTERN ---
69+
// GLOBAL
70+
if (pathname === '/scenes' || pathname === '/' || pathname === '' || pathname === '/stats' || pathname === '/settings' || pathname === '/scenes/markers' || /^\/scenes\/\d+$/.test(pathname))
71+
return randomGlobal('Scene', 'scenes', '/scenes/');
72+
73+
if (pathname === '/images' || /^\/images\/\d+$/.test(pathname))
74+
return randomGlobal('Image', 'images', '/images/');
75+
76+
if (pathname === '/performers')
77+
return randomGlobal('Performer', 'performers', '/performers/');
78+
79+
if (pathname === '/studios')
80+
return randomGlobal('Studio', 'studios', '/studios/');
81+
82+
if (pathname === '/tags')
83+
return randomGlobal('Tag', 'tags', '/tags/');
84+
85+
if (pathname === '/groups')
86+
return randomGlobal('Group', 'groups', '/groups/');
87+
88+
if (pathname === '/galleries')
89+
return randomGlobal('Gallery', 'galleries', '/galleries/');
90+
91+
// Intern
7892
let studioId = getIdFromPath(/^\/studios\/(\d+)\/scenes/);
79-
if (studioId) return randomGlobal('Scene', 'scenes', '/scenes/', { studios: { value: [studioId], modifier: "INCLUDES_ALL" } });
93+
if (studioId)
94+
return randomGlobal('Scene', 'scenes', '/scenes/', { studios: { value: [studioId], modifier: "INCLUDES_ALL" } });
8095

8196
let groupId = getIdFromPath(/^\/groups\/(\d+)\/scenes/);
82-
if (groupId) return randomGlobal('Scene', 'scenes', '/scenes/', { groups: { value: [groupId], modifier: "INCLUDES_ALL" } });
97+
if (groupId)
98+
return randomGlobal('Scene', 'scenes', '/scenes/', { groups: { value: [groupId], modifier: "INCLUDES_ALL" } });
8399

84100
let performerId = getIdFromPath(/^\/performers\/(\d+)\/scenes/);
85-
if (performerId) return randomGlobal('Scene', 'scenes', '/scenes/', { performers: { value: [performerId], modifier: "INCLUDES_ALL" } });
101+
if (performerId)
102+
return randomGlobal('Scene', 'scenes', '/scenes/', { performers: { value: [performerId], modifier: "INCLUDES_ALL" } });
86103

87104
let tagId = getIdFromPath(/^\/tags\/(\d+)\/scenes/);
88-
if (tagId) return randomGlobal('Scene', 'scenes', '/scenes/', { tags: { value: [tagId], modifier: "INCLUDES_ALL" } });
105+
if (tagId)
106+
return randomGlobal('Scene', 'scenes', '/scenes/', { tags: { value: [tagId], modifier: "INCLUDES_ALL" } });
89107

90-
let galleryId = getIdFromPath(/^\/galleries\/(\d+)/);
91-
if (galleryId) return randomGlobal('Image', 'images', '/images/', { galleries: { value: [galleryId], modifier: "INCLUDES_ALL" } });
108+
let galleryId = getIdFromPath(/^\/galleries\/(\d+)$/);
109+
if (galleryId)
110+
return randomGlobal('Image', 'images', '/images/', { galleries: { value: [galleryId], modifier: "INCLUDES_ALL" } });
92111

93112
alert('Not supported');
94113
}

plugins/StashRandomButton/random_button.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: RandomButton
22
description: Adds a button to quickly jump to a random scene, image, performer, studio, group, tag, or gallery, both on overview and internal entity pages.
3-
version: 2.0.0
4-
url: https://example.com
3+
version: 2.0.1
4+
url: https://github.com/stashapp/CommunityScripts/tree/main/plugins/StashRandomButton
55
ui:
66
requires: []
77
javascript:

0 commit comments

Comments
 (0)