Last active
October 25, 2024 08:38
-
-
Save poontology/0aeb3c09110cb11980c25dd858770dc9 to your computer and use it in GitHub Desktop.
Userscript utilities for stashdb.org
This file contains hidden or 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
// ==UserScript== | |
// @name stashdb-utils | |
// @namespace https://gist.github.com/poontology | |
// @version 0.1 | |
// @description Userscript utilities for stashdb.org | |
// @author poontology | |
// @match https://stashdb.org/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const $x = (xpr, ctx) => { | |
const query = document.evaluate(xpr, ctx || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE); | |
return Array(query.snapshotLength).fill(0).map((element, index) => query.snapshotItem(index)); | |
} | |
// Add button to edit pages that linkifies scene creation edits to search page | |
// (may require either reload or changing queue page to activate) | |
function addLinkifyButton() { | |
if(location.pathname.endsWith("/edits")) { | |
if(document.querySelector('nav') && !document.querySelector('#search-scenes')) { | |
document.querySelector('nav').outerHTML += '<div style="padding:8px; float:right"><button id="search-scenes" class="btn btn-secondary">Add search-links to scenes</button></div>'; | |
document.querySelector('#search-scenes').onclick = () => { | |
const sceneLst = $x('//div[starts-with(@class,"EditCard") and .//h5/text()="create scene"]'); | |
for(const scene of sceneLst) { | |
const dateEl = $x('.//div[starts-with(@class,"mb-2")][2]//div[@class="EditDiff"]', scene).pop(); | |
const studioEl = $x('.//a[starts-with(@href,"/studio")]', scene).pop(); | |
const searchTxt = encodeURIComponent(studioEl.innerText+" "+dateEl.innerText); | |
dateEl.innerHTML = '<a target="_blank" href="/search/'+ searchTxt +'">'+ dateEl.innerHTML +'</a>'; | |
} | |
} | |
} | |
} | |
} | |
// TODO: MutationObserver would be nicer | |
window.navigation.addEventListener("navigate", e => addLinkifyButton()); | |
window.addEventListener('load', e => addLinkifyButton()); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment