-
-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Scene Page Remember States plugin #261
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Scene Page Remember States | ||
|
||
This plugin uses local storage to rememebr what is the current active nav tab of the scenes' detail panel, and upon any page load activate the last remembered active nav tab. | ||
|
||
It also rembers the active collapsed state of the divider button and upon page load if it's true, it will automatically collapse the divider. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
(async function waitForStash() { | ||
while (!window.stash) { | ||
await new Promise((resolve) => setTimeout(resolve, 100)); | ||
} | ||
|
||
function handlePageDivider() { | ||
waitForElementClass("scene-tabs order-xl-first order-last", function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see other waitForElement comment |
||
const pageDivider = document | ||
.querySelector(".scene-divider.d-none.d-xl-block") | ||
.querySelector("button"); | ||
|
||
let isActive = localStorage.getItem("scene-page-divider"); | ||
if (isActive === null) { | ||
localStorage.setItem("scene-page-divider", "false"); | ||
isActive = false; | ||
} else { | ||
isActive = isActive === "true"; | ||
} | ||
|
||
if (isActive === true) { | ||
pageDivider.click(); | ||
} | ||
|
||
pageDivider.addEventListener("click", function () { | ||
isActive = !isActive; | ||
localStorage.setItem("scene-page-divider", isActive.toString()); | ||
}); | ||
}); | ||
} | ||
|
||
function nav() { | ||
waitForElementClass("mr-auto nav nav-tabs", function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. waitForElement(".mr-auto.nav.nav-tabs", function() { |
||
const navMenuItems = [ | ||
{ name: "Details", key: "scene-details-panel" }, | ||
{ name: "Queue", key: "scene-queue-panel" }, | ||
{ name: "Markers", key: "scene-markers-panel" }, | ||
{ name: "Filters", key: "scene-filters-panel" }, | ||
{ name: "File Info", key: "scene-file-info-panel" }, | ||
{ name: "Edit", key: "scene-edit-panel" }, | ||
]; | ||
|
||
const detailsNav = document.getElementsByClassName( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see other WaitForElement comment |
||
"mr-auto nav nav-tabs" | ||
)[0]; | ||
const hrefs = detailsNav.getElementsByTagName("a"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see other waitForElement comment |
||
|
||
// Check local storage for entries | ||
let activeKey = localStorage.getItem("detailsNavActive"); | ||
|
||
// If no entry found, create default entry | ||
if (!activeKey) { | ||
navMenuItems.forEach((item) => { | ||
if (item.name === "Details") { | ||
localStorage.setItem("detailsNavActive", item.key); | ||
} | ||
}); | ||
activeKey = "scene-details-panel"; | ||
} | ||
|
||
// Remove active class from all hrefs | ||
Array.from(hrefs).forEach((href) => { | ||
href.classList.remove("active"); | ||
}); | ||
|
||
// Add active class to the one that matches activeKey | ||
Array.from(hrefs).forEach((href) => { | ||
if (href.dataset.rbEventKey === activeKey) { | ||
href.classList.add("active"); | ||
} | ||
}); | ||
|
||
// Simulate click on active tab | ||
const activeTab = detailsNav.querySelector( | ||
`a[data-rb-event-key="${activeKey}"]` | ||
); | ||
activeTab.click(); | ||
|
||
// Add event listeners | ||
Array.from(hrefs).forEach((href) => { | ||
href.addEventListener("click", function () { | ||
// Remove active class from all hrefs | ||
Array.from(hrefs).forEach((href) => { | ||
href.classList.remove("active"); | ||
}); | ||
|
||
// Add active class to the clicked href | ||
this.classList.add("active"); | ||
|
||
// Store active key in local storage | ||
const newActiveKey = this.dataset.rbEventKey; | ||
localStorage.setItem("detailsNavActive", newActiveKey); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function main() { | ||
nav(), handlePageDivider(); | ||
} | ||
stash.addEventListener("stash:page:scene", main()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replaced by PathElementListener csLib.PathElementListener("/scene/", "", main)) |
||
})(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Scene Page Remember States | ||
description: Uses local storage to remember the state of the scene page detail panel nav bar and activate it on page load. Remembers collapse state of the divider. | ||
url: | ||
version: 0.1 | ||
ui: | ||
requires: | ||
- stashUserscriptLibrary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Needs a review. |
||
javascript: | ||
- scenePageRememberStates.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window.stash is never exposed and being a requirement should ensure it's loaded beforehand