Skip to content

Commit

Permalink
add some things that I hadn't committed over the past several months
Browse files Browse the repository at this point in the history
  • Loading branch information
joshparkerj committed May 11, 2023
1 parent 9ecdec0 commit 86222cc
Show file tree
Hide file tree
Showing 23 changed files with 1,204 additions and 136 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ deploy
file-sizes
nightcafe/result*
nightcafe-result
nightcafe/*.csv
nightcafe/*.csv
nightcafe/*.txt
nightcafe/*.json
nightcafe/prompts/
ts-hello-world/
.DS_Store
50-rando-ticker-symbols.json
where-am-i.py
22 changes: 22 additions & 0 deletions egs/arrow-nav.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ==UserScript==
// @name Arrow Key Navigation
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Arrow Key Navigation
// @author Josh Parker
// @match https://www.egscomics.com/comic/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=egscomics.com
// @grant none
// ==/UserScript==

(function arrowKeyNavigation() {
const next = () => document.querySelector('a.cc-next').click();
const previous = () => document.querySelector('a.cc-prev').click();
document.addEventListener('keydown', ({ code }) => {
if (code === 'ArrowRight') {
next();
} else if (code === 'ArrowLeft') {
previous();
}
});
}());
177 changes: 177 additions & 0 deletions itch/duotrigordle-solve.user.js

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions netflix/delete-element.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// ==UserScript==
// @name Delete Element
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Delete Element (with undo)
// @author Josh Parker
// @match http*://**/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=qwant.com
// @grant none
// ==/UserScript==

(function deleteElement() {
const remove = (element) => { element.style.setProperty('display', 'none'); };

// let prevBoxShadow;

const addBorder = (element) => {
// prevBoxShadow = element.style.getPropertyValue('box-shadow');
element.style.setProperty('box-shadow', '0px 0px 1px 1px red');
};

const removeBorder = (element) => {
element.style.removeProperty('box-shadow');
/*
if (prevBoxShadow) {
element.style.setProperty('box-shadow', prevBoxShadow);
} */
};

const elementStack = [];
let hoveredElement;

// eslint-disable-next-line no-extend-native
Array.prototype.peek = function peek() { return this[this.length - 1]; };

// not pressing d
const mouseoverHandler = ({ target }) => {
hoveredElement = target;
};

// pressing d
const mouseoverHandlerWithBorder = ({ target }) => {
removeBorder(hoveredElement);
hoveredElement = target;
addBorder(hoveredElement);
};

const clickHandler = (event) => {
event.preventDefault();
const { target } = event;
elementStack.push(target);
remove(target);
};

const undo = () => {
const element = elementStack.pop();
element?.style.removeProperty('display');
};

const { body } = document;
body.addEventListener('mouseover', mouseoverHandler);

document.addEventListener('keydown', ({ code }) => {
if (code === 'KeyD') {
body.removeEventListener('mouseover', mouseoverHandler);
body.addEventListener('mouseover', mouseoverHandlerWithBorder);
document.addEventListener('click', clickHandler);
addBorder(hoveredElement);
}

if (code === 'KeyZ') {
undo();
}
});

document.addEventListener('keyup', ({ code }) => {
if (code === 'KeyD') {
document.removeEventListener('click', clickHandler);
body.addEventListener('mouseover', mouseoverHandler);
body.removeEventListener('mouseover', mouseoverHandlerWithBorder);
removeBorder(hoveredElement);
}
});
}());
25 changes: 25 additions & 0 deletions netflix/log-element.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ==UserScript==
// @name Console Log Element
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Console Log Element
// @author Josh Parker
// @match http*://**/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=netflix.com
// @grant none
// ==/UserScript==

(function consoleLogElement() {
const logElement = ({ target }) => console.log(target);
document.addEventListener('keydown', ({ code }) => {
if (code === 'KeyL') {
document.addEventListener('click', logElement);
}
});

document.addEventListener('keyup', ({ code }) => {
if (code === 'KeyL') {
document.removeEventListener('click', logElement);
}
});
}());
46 changes: 46 additions & 0 deletions nightcafe/artist-name-collections.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ==UserScript==
// @name Get Collections
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Show the collections that the artist name belongs to
// @author Josh Parker
// @match https://aiartcreation.fandom.com/wiki/Artist_Directory_(Volcano_Comparison)
// @icon https://www.google.com/s2/favicons?sz=64&domain=fandom.com
// @grant none
// ==/UserScript==

(function getCollections() {
const css = `
.wikia-gallery-item > .lightbox-caption > p {
margin: 0;
}
.wikia-gallery-item > .lightbox-caption > p:nth-child(1) {
border-top: solid black 1px;
}
`;

const style = document.createElement('style');
style.appendChild(new Text(css));
document.body.appendChild(style);

const hrefs = [...document.querySelectorAll('li > a[href^="/wiki/Collection"]')].map((e) => e.href);

const parser = new DOMParser();

hrefs.forEach(async (href) => {
const response = await fetch(href);
const htmlText = await response.text();
const dom = parser.parseFromString(htmlText, 'text/html');
const artistNames = [...dom.querySelectorAll('div.lightbox-caption')].map((e) => e.textContent);
const title = dom.querySelector('h1#firstHeading').textContent.trim().match(/Collection: (.*)/)[1];
console.log(title);
console.log(artistNames);
artistNames.forEach((artistName) => {
const artistLightboxCaption = [...document.querySelectorAll('div.lightbox-caption')].find((div) => div.textContent.includes(artistName));
const paragraph = document.createElement('p');
paragraph.appendChild(new Text(title));
artistLightboxCaption.appendChild(paragraph);
});
});
}());
44 changes: 44 additions & 0 deletions nightcafe/collection-sort.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// ==UserScript==
// @name Nightcafe Collection Sort
// @namespace http://tampermonkey.net/
// @version 0.1
// @description collections to the top of the list if their names are in the prompts or title.
// @author Josh Parker
// @match https://creator.nightcafe.studio/creation/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=nightcafe.studio
// @grant none
// ==/UserScript==

(function collectionSort() {
const containerSelector = '#modals .modal-body';
const collectionSelector = `${containerSelector} label`;

const sort = () => {
const container = document.querySelector(containerSelector);
const collections = document.querySelectorAll(collectionSelector);
if (container.classList.contains('sorted') || !collections.length) return;

container.classList.add('sorted');

const textPrompts = [...document.querySelectorAll('#__next div[itemprop=mainEntity] p')]
.filter((e) => e.textContent.includes('weight'))
.map((e) => e.textContent.replace(/weight.*/, ''));

const title = document.querySelector('body #__next [itemprop=mainEntity] h1:nth-child(1)').textContent;
const text = `${textPrompts.join(' ')} ${title}`;

const collectionStart = document.querySelector('.css-1ngh2e5');

collections.forEach((collection) => {
const collectionName = collection.textContent;
if (text.includes(collectionName)) {
const collectionClone = collection.cloneNode(true);
collectionStart.insertAdjacentElement('afterend', collectionClone);
}
});
};

const mo = new MutationObserver(sort);

mo.observe(document.querySelector('body'), { childList: true, subtree: true });
}());
21 changes: 21 additions & 0 deletions nightcafe/get-searchable-prompt-text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default function getSearchablePromptText(dom) {
const selector = '#__next [itemprop=mainEntity] .css-1gzn9ne > .css-ntik0p > .css-q8r9lz';
const descriptiveElement = dom.querySelector(selector);

if (!descriptiveElement) throw new Error('No descriptive element found');

descriptiveElement.querySelectorAll('style').forEach((styleElement) => {
styleElement.parentNode.removeChild(styleElement);
});

const textPrompts = descriptiveElement.textContent.match(/"[^"]*/g)
.filter((t) => !t.includes('weight')).map((t) => t.slice(1))
.reduce((acc, e) => acc + e, '');

const searchableText = textPrompts.normalize('NFKD')
.replace(/[\u0300-\u036f]/g, '').toLocaleLowerCase()
.replace(/\s+/g, ' ')
.replace(/[^\s\w\d]+/g, '');

return searchableText;
}
5 changes: 5 additions & 0 deletions nightcafe/get-two-word-combos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function getTwoWordCombos(s) {
const re = /\w+\W+\w+/g;

return s.match(re)?.concat(s.replace(/\w+/, '').match(re));
}
102 changes: 102 additions & 0 deletions nightcafe/nightcafe-artist-names.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// ==UserScript==
// @name Night Cafe Get Top Creations using artist names.
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Josh Parker
// @match https://creator.nightcafe.studio/explore*
// @icon https://www.google.com/s2/favicons?sz=64&domain=nightcafe.studio
// @grant none
// ==/UserScript==

(function nightCafe() {
const parser = new DOMParser();
const artistInitializer = () => ({ filter: new Set() });
const artistSerializer = (artist) => { const { filter, ...noFilter } = artist; return noFilter; };
const jsonOutput = {
'Alex Hirsch': artistInitializer(),
'Albert Gleizes': artistInitializer(),
'Alphonse Mucha': artistInitializer(),
'Amanda Sage': artistInitializer(),
'Ben Bocquelet': artistInitializer(),
'Bernie Wrightson': artistInitializer(),
Canaletto: artistInitializer(),
'Caspar David Friedrich': artistInitializer(),
'Claude Monet': artistInitializer(),
'Dan Mumford': artistInitializer(),
'Dan Witz': artistInitializer(),
'Edward Hopper': artistInitializer(),
'Ferdinand Knab': artistInitializer(),
'Georgy Kurasov': artistInitializer(),
'Gerald Brom': artistInitializer(),
'Greg Rutkowski': artistInitializer(),
'Guido Borelli': artistInitializer(),
'Gustav Klimt': artistInitializer(),
'Gustave Doré': artistInitializer(),
'H.R. Giger': artistInitializer(),
'J.G. Quintel': artistInitializer(),
'James Gurney': artistInitializer(),
'Jean Tinguely': artistInitializer(),
'Jim Burns': artistInitializer(),
'Josephine Wall': artistInitializer(),
'Julia Pott': artistInitializer(),
Kandinsky: artistInitializer(),
'Kelly Freas': artistInitializer(),
'Leonid Afremov': artistInitializer(),
'Max Ernst': artistInitializer(),
Moebius: artistInitializer(),
'Pablo Amaringo': artistInitializer(),
'Pablo Picasso': artistInitializer(),
'Pendleton Ward': artistInitializer(),
Picasso: artistInitializer(),
'Pino Daeni': artistInitializer(),
'Rafael Santi': artistInitializer(),
'Rebecca Sugar': artistInitializer(),
'Roger Dean': artistInitializer(),
'Salvador Dali': artistInitializer(),
'Steven Belledin': artistInitializer(),
'Steven Hillenberg': artistInitializer(),
'Studio Ghibli': artistInitializer(),
'Thomas Kinkade': artistInitializer(),
'Tim Burton': artistInitializer(),
'Van Gogh': artistInitializer(),
'Wadim Kashin': artistInitializer(),
'Wes Anderson': artistInitializer(),
'Zdzisław Beksiński': artistInitializer(),
};

const fetchDetails = async (node) => {
const author = node.querySelector('[rel=author]')?.href;
const creationLink = node.querySelector('[href^="/creation"]')?.href;
if (creationLink && author && !filter.has(author)) {
filter.add(author);
console.log(filter.size);
const fetchResponse = await fetch(creationLink);
const textResponse = await fetchResponse.text();
const dom = parser.parseFromString(textResponse, 'text/html');
const descriptiveElement = dom.querySelector('#__next [itemprop=mainEntity] .css-1gzn9ne > .css-ntik0p > .css-q8r9lz');
if (descriptiveElement) {
descriptiveElement.querySelectorAll('style').forEach((styleElement) => {
styleElement.parentNode.removeChild(styleElement);
});

jsonOutput[creationLink] = descriptiveElement.textContent.match(/"[^"]*/g).filter((t) => !t.includes('weight')).map((t) => t.slice(1));
}

if (filter.size >= 64) {
console.log(JSON.stringify(jsonOutput));
alert('YOUR JSON IS READY BABY! PLEASE CHECK CONSOLE!');
}
}
};

const mutationObserverCallback = (mutationList) => {
mutationList.forEach(({ addedNodes }) => {
addedNodes.forEach(fetchDetails);
});
};

const mo = new MutationObserver(mutationObserverCallback);

mo.observe(document.querySelector('#__next > div'), { subtree: true, childList: true });
}());
Loading

0 comments on commit 86222cc

Please sign in to comment.