// ==UserScript== // @name Stash Performer Markers Tab // @namespace https://github.com/7dJx1qP/stash-userscripts // @description Adds a Markers link to performer pages // @version 0.1.0 // @author 7dJx1qP // @match http://localhost:9999/* // @grant unsafeWindow // @require https://raw.githubusercontent.com/7dJx1qP/stash-userscripts/master/src\StashUserscriptLibrary.js // ==/UserScript== (function () { 'use strict'; const { stash, Stash, waitForElementId, waitForElementClass, waitForElementByXpath, getElementByXpath, createElementFromHTML, } = unsafeWindow.stash; async function getPerformerMarkersCount(performerId) { const reqData = { "operationName": "FindSceneMarkers", "variables": { "scene_marker_filter": { "performers": { "value": [ performerId ], "modifier": "INCLUDES_ALL" } } }, "query": `query FindSceneMarkers($filter: FindFilterType, $scene_marker_filter: SceneMarkerFilterType) { findSceneMarkers(filter: $filter, scene_marker_filter: $scene_marker_filter) { count } }` } return stash.callGQL(reqData); } const markersTabId = 'performer-details-tab-markers'; stash.addEventListener('page:performer:details', function () { waitForElementClass("nav-tabs", async function (className, el) { const navTabs = el.item(0); if (!document.getElementById(markersTabId)) { const performerId = window.location.pathname.replace('/performers/', ''); const markersCount = (await getPerformerMarkersCount(performerId)).data.findSceneMarkers.count; const markerTab = createElementFromHTML(`Markers${markersCount}`) navTabs.appendChild(markerTab); const performerName = document.querySelector('.performer-head h2').innerText; const markersUrl = `${window.location.origin}/scenes/markers?c=${JSON.stringify({"type":"performers","value":[{"id":performerId,"label":performerName}],"modifier":"INCLUDES_ALL"})}` markerTab.href = markersUrl; } }); }); })();