Skip to content

Instantly share code, notes, and snippets.

@joshparkerj
Created July 3, 2022 20:46
Show Gist options
  • Save joshparkerj/e00174e844b6275d394ef9307e1a2718 to your computer and use it in GitHub Desktop.
Save joshparkerj/e00174e844b6275d394ef9307e1a2718 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name creation settings
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Get the settings from json api. No UI changes.
// @author Josh Parker
// @match https://creator.nightcafe.studio/my-creations
// @icon https://www.google.com/s2/favicons?sz=64&domain=nightcafe.studio
// @grant none
// ==/UserScript==
(function settingsOnMyCreations() {
const autoScroll = () => setInterval(() => window.scroll(0, window.scrollY + 200), 1000);
const handleScrollKey = (() => {
let scrolling = false;
let intervalId = null;
return () => {
if (scrolling) {
clearInterval(intervalId);
scrolling = false;
} else {
intervalId = autoScroll();
scrolling = true;
}
};
})();
const everything = [];
const cardSelector = `#__next div.css-16jqqjd + div > .css-0 > div`;
const { buildId } = JSON.parse(document.querySelector('#__NEXT_DATA__').textContent);
const captureMyCreations = () => {
const cards = document.querySelectorAll(cardSelector);
cards.forEach(async (card) => {
const cardA = card.querySelector('a');
if (!cardA || card.classList.contains('checked-for-creation-settings')) return;
card.classList.add('checked-for-creation-settings');
const { href } = cardA;
if (!href.includes('creator.nightcafe.studio/creation')) return;
const creationId = href.match(/creator.nightcafe.studio\/creation\/(.*)/)[1];
const dataHref = window.location.href.replace('my-creations', `_next/data/${buildId}/creation/${creationId}.json?cid=${creationId}`);
const response = await fetch(dataHref);
const data = await response.json();
const {
algorithm, likedBy, promptWeights, prompts, resolution, runtime, seed, preset, id, isPublic, preventCopies
} = data.pageProps.initialJob;
if (isPublic && !preventCopies) {
everything.push({ algorithm, likes: likedBy?.length, promptWeights, prompts, resolution, runtime, seed, preset, url: `https://creator.nightcafe.studio/creation/${id}` });
}
});
};
const mo = new MutationObserver(captureMyCreations);
mo.observe(document.querySelector('#__next'), { childList: true, subtree: true });
captureMyCreations();
document.addEventListener('keydown', ({ code }) => {
if (code === 'KeyP') {
console.log(JSON.stringify(everything));
} else if (code === 'KeyS') {
handleScrollKey();
}
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment