-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace StashUserscriptLibrary (#319)
* replace SUL in VideoScrollWheel * rewrite stats to use cs-ui-lib - reused and simplified GQL queries * rewrite sceneCoverCropper to use cs-ui-lib * update discordPrescence to use cs-ui-lib - add websocket liveliness check - add video playback hooks * make stash-realbooru use cs-ui-lib * deprecated by https://github.com/7dJx1qP/stash-plugins/tree/main/plugins/stashBatchResultToggle * add cs-ui-lib to stashAI, applied some fixes to realbooru * update Visage to use cs-ui-lib * update themeSwitch to use cs-ui-lib * remove userscript lib --------- Co-authored-by: feederbox826 <[email protected]>
- Loading branch information
1 parent
a3d00d4
commit adade5e
Showing
22 changed files
with
408 additions
and
2,595 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
plugins/CommunityScriptsUILibrary/CommunityScriptsUILibrary.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: CommunityScriptsUILibrary | ||
description: CommunityScripts UI helper library | ||
version: 1.0.0 | ||
ui: | ||
javascript: | ||
- cs-ui-lib.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// CommunityScripts UI Library | ||
// cs-ui-lib.js | ||
(function () { | ||
// get base URL for graphQL queries | ||
const baseURL = document.querySelector("base")?.getAttribute("href") ?? "/"; | ||
|
||
// call GQL query, returns data without `data` wrapper | ||
const callGQL = (reqData) => | ||
fetch(`${baseURL}graphql`, { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify(reqData), | ||
}) | ||
.then((res) => res.json()) | ||
.then((res) => res.data); | ||
|
||
// get configuration via GQL | ||
const getConfiguration = async (pluginId, fallback) => { | ||
const query = `query Configuration { configuration { plugins }}`; | ||
const response = await callGQL({ query }); | ||
return response.configuration.plugins?.[pluginId] ?? fallback; | ||
}; | ||
|
||
// wait for key elements | ||
function waitForElement(selector, callback) { | ||
var el = document.querySelector(selector); | ||
if (el) return callback(el); | ||
setTimeout(waitForElement, 100, selector, callback); | ||
} | ||
|
||
// wait for a path match, then for key elements | ||
const PathElementListener = (path, element, callback) => { | ||
// startup location | ||
if (window.location.pathname.startsWith(path)) | ||
waitForElement(element, callback); | ||
PluginApi.Event.addEventListener("stash:location", (e) => { | ||
if (e.detail.data.location.pathname.startsWith(path)) | ||
waitForElement(element, callback); | ||
}); | ||
}; | ||
|
||
// export to window | ||
window.csLib = { | ||
callGQL, | ||
getConfiguration, | ||
waitForElement, | ||
PathElementListener, | ||
}; | ||
})(); |
Oops, something went wrong.