Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
joshparkerj committed Nov 25, 2021
1 parent 2fdf0df commit 57a254f
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 27 deletions.
53 changes: 53 additions & 0 deletions goodreads/series-csv.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// ==UserScript==
// @name series csv
// @namespace http://tampermonkey.net/
// @version 0.1
// @description goodreads data in tabular and csv format
// @author Josh Parker
// @match https://www.goodreads.com/series/*
// @icon https://www.google.com/s2/favicons?domain=goodreads.com
// @grant none
// ==/UserScript==

(function userScript() {
let csv = 'title,author,rating,ratings,reviews,date,editions';
const table = document.createElement('table');
const thead = document.createElement('thead');
const tbody = document.createElement('tbody');
const headerRow = document.createElement('tr');
csv.split(',').forEach((heading) => {
const th = document.createElement('th');
th.textContent = heading;
headerRow.appendChild(th);
});

thead.appendChild(headerRow);
table.appendChild(thead);
table.appendChild(tbody);
document.querySelectorAll('.responsiveBook').map((rb) => {
const title = rb.querySelector('.gr-h3 span[itemprop="name"]').textContent;
const author = rb.querySelector('span[itemprop="author"]').textContent;
const rating = rb.querySelector('.communityRating__starsWrapper ~ .gr-metaText').textContent;
const allTextContent = rb.textContent;
const matches = allTextContent.match(/(?<ratings>[\d,]+) Ratings[^\d\w]*((?<reviews>[\d,]+) Reviews)?[^\d\w]*(published (?<date>\d+))?[^\d\w]*((?<editions>\d+) editions)?/);
return {
title,
author,
rating,
...matches.groups,
};
}).map(({
title, author, rating, ratings, reviews, date, editions,
}) => `\n"${title}","${author}","${rating}","${ratings}","${reviews || 0}","${date || 'unknown'}","${editions || 1}"`)
.forEach((row) => {
csv += row;
const bodyRow = document.createElement('tr');
row.split(',').forEach((d) => {
const td = document.createElement('td');
td.textContent = d.replaceAll('"', '');
bodyRow.appendChild(td);
});

tbody.appendChild(bodyRow);
});
}());
18 changes: 8 additions & 10 deletions rainbowify/zalgoify.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
// @grant none
// ==/UserScript==

(function () {
'use strict';

(function zalgoifyUserScript() {
const body = document.querySelector('body');
const existingTextManips = document.querySelector('body > div.josh-text-manips');
const joshTextManips = existingTextManips || document.createElement('div');
Expand All @@ -23,26 +21,26 @@
zalgoifyButton.innerText = 'zalgoify';

// zalgo chars from https://codepen.io/aranromperson/pen/OgOJzX
const zalgoChars = ["̍", "̎", "̄", "̅", "̿", "̑", "̆", "̐", "͒", "͗", "͑", "̇", "̈", "̊", "͂", "̓", "̈́", "͊", "͋", "͌", "̃", "̂", "̌", "̀", "́", "̋", "̏", "̒", "̓", "̔", "̽", "̉", "̾", "͆", "̚", "̖", "̗", "̘", "̙", "̜", "̝", "̞", "̟", "̠", "̤", "̥", "̦", "̩", "̪", "̫", "̬", "̭", "̮", "̯", "̰", "̱", "̲", "̳", "̹", "̺", "̻", "̼", "ͅ", "͇", "͈", "͉", "͍", "͎", "͓", "͚", "̣", "̕", "̛", "̀", "́", "͘", "̡", "̢", "̧", "̨", "̴", "̵", "̶", "͏", "͜", "͝", "͞", "͟", "͠", "͢", "̸", "̷", "͡", "҉"];
const zalgoChars = ['̍', '̎', '̄', '̅', '̿', '̑', '̆', '̐', '͒', '͗', '͑', '̇', '̈', '̊', '͂', '̓', '̈́', '͊', '͋', '͌', '̃', '̂', '̌', '̀', '́', '̋', '̏', '̒', '̓', '̔', '̽', '̉', '̾', '͆', '̚', '̖', '̗', '̘', '̙', '̜', '̝', '̞', '̟', '̠', '̤', '̥', '̦', '̩', '̪', '̫', '̬', '̭', '̮', '̯', '̰', '̱', '̲', '̳', '̹', '̺', '̻', '̼', 'ͅ', '͇', '͈', '͉', '͍', '͎', '͓', '͚', '̣', '̕', '̛', '̀', '́', '͘', '̡', '̢', '̧', '̨', '̴', '̵', '̶', '͏', '͜', '͝', '͞', '͟', '͠', '͢', '̸', '̷', '͡', '҉'];

const changeTextToZalgoText = function changeTextToZalgoText(element) {
const e = element;
const randZalg = () => zalgoChars[Math.floor(Math.random() * zalgoChars.length)];
const randZalgs = () => [0, 1, 2, 3, 4].map(() => randZalg());
const elementLength = element.textContent.length;
element.textContent = element.textContent.split('').map((c, i) => c + randZalgs().join('')).join('');
e.textContent = e.textContent.split('').map((c) => c + randZalgs().join('')).join('');
};

const zalgoify = function zalgoify({ target }) {
body.removeEventListener('mousedown', zalgoify);

const singleLetterSpans = target.textContent.split('').map(c => {
const singleLetterSpans = target.textContent.split('').map((c) => {
const singleLetterSpan = document.createElement('span');
singleLetterSpan.textContent = c;
return singleLetterSpan;
});

target.textContent = '';
singleLetterSpans.forEach(span => target.appendChild(span));
singleLetterSpans.forEach((span) => target.appendChild(span));

const zalgoifyMouseover = ({ target: mouseoverTarget }) => {
if (mouseoverTarget.tagName === 'SPAN') {
Expand All @@ -56,7 +54,7 @@
target.removeEventListener('mouseup', zalgoifyMouseup);
target.removeEventListener('mouseover', zalgoifyMouseover);
const text = target.textContent;
const classNames = [...target.childNodes].map(node => node.className);
const classNames = [...target.childNodes].map((node) => node.className);
const selectionStart = classNames.indexOf('selected');
const selectionEnd = classNames.lastIndexOf('selected') + 1;
target.innerHTML = `${text.slice(0, selectionStart)}<span class='zalgo-text'>${text.slice(selectionStart, selectionEnd)}</span>${text.slice(selectionEnd)}`;
Expand All @@ -78,4 +76,4 @@
}

document.styleSheets[0].insertRule('.josh-text-manips {position: fixed;background-color: lightgrey;padding: 5px 10px;top: 62px;right: 10px;border-radius: 16px;box-shadow: 2px 2px 1px black;}');
})();
}());
5 changes: 4 additions & 1 deletion text-effect/text-effect.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// @grant none
// ==/UserScript==

(function userScript() {
(function textEffectUserScript() {
const effectify = function effectify(buttonText, effectClassName, applyTextEffect) {
const textEffectButton = document.createElement('button');
textEffectButton.innerText = buttonText;
Expand Down Expand Up @@ -146,6 +146,9 @@
joshTextManips.appendChild(zanyifyButton);

// const fidgetifyButton = effectify('fidgetify', 'fidget-text', )
const blinkifyButton = effectify('blinkify', 'blink-text', (element) => {

})

addCSSRule('body > div#josh-text-manips { position: fixed; background-color: lightgrey; padding: 5px 10px; top: 62px; right: 10px; border-radius: 16px; box-shadow: 2px 2px 1px black; z-index: 2; display: grid; grid-template-columns: 1fr 1fr 1fr; }');
addCSSRule('body > div#josh-text-manips > button { grid-column: span 1; }');
Expand Down
17 changes: 8 additions & 9 deletions washington-post-better-colors/wapo-better-colors.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@
// @grant none
// ==/UserScript==

(function () {
'use strict';

(function wapoBetterColorsUserScript() {
const bodyElement = [...document.getElementsByTagName('body')][0];

bodyElement.style.setProperty('text-shadow', 'rgb(127 204 102) 1px 1px 1px, rgb(204 102 127) -1px -1px 1px');
bodyElement.style.setProperty('background-image', 'linear-gradient(45deg, #33ccff, #cc33ff)');

const changeTextToRainbowText = function changeTextToRainbowText(element) {
const elementLength = element.textContent.length;
const singleLetterSpans = element.textContent.split('').map((c, i) => {
const e = element;
const elementLength = e.textContent.length;
const singleLetterSpans = e.textContent.split('').map((c, i) => {
const singleLetterSpan = document.createElement('span');
singleLetterSpan.textContent = c;
singleLetterSpan.style.setProperty('color', `hsl(${360 * i / elementLength} 100% 50%)`);
singleLetterSpan.style.setProperty('color', `hsl(${(360 * i) / elementLength} 100% 50%)`);
return singleLetterSpan;
});

element.textContent = '';
singleLetterSpans.forEach(span => element.appendChild(span));
e.textContent = '';
singleLetterSpans.forEach((span) => e.appendChild(span));
};

const mainHeading = document.querySelector('.main-content h1');
Expand All @@ -36,4 +35,4 @@
changeTextToRainbowText(mainHeading);

changeTextToRainbowText(document.querySelector('h1#main-content'));
})();
}());
4 changes: 2 additions & 2 deletions wavify/wave-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ div {

@keyframes wave {
from {
transform: translateY(0);
transform: rotate(0);
}

25% {
transform: translateY(-100%);
transform: rotate(360deg);
}

50% {
Expand Down
14 changes: 9 additions & 5 deletions wiki-category-page-views/fiddle.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ const getPageViewsThisMonth = function getPageViewsThisMonth() {

const lastMonthDate = `${thisYear}${lastMonth.toString().padStart(2, '0')}01`;

const pageViewUrls = [...categoryLinks].map(a => `${apiUrl}${a.href.match(/[^\/]*$/)[0]}/monthly/${lastMonthDate}/${today}`);

Promise.all(pageViewUrls.map(url => fetch(url).then(r.json()).then(json => json.items[0].views)))
.then(results => results.forEach((views, i) => categoryLinks[i].innerText += ` (${views} page views this month)`));
}
const pageViewUrls = [...categoryLinks].map((a) => `${apiUrl}${a.href.match(/[^/]*$/)[0]}/monthly/${lastMonthDate}/${today}`);

Promise.all(pageViewUrls.map((url) => (
fetch(url)
.then((r) => r.json())
.then((json) => json.items[0].views)
)))
.then((results) => results.forEach((views, i) => { categoryLinks[i].innerText += ` (${views} page views this month)`; }));
};

getPageViewsThisMonthButton.addEventListener('click', getPageViewsThisMonth);

Expand Down
84 changes: 84 additions & 0 deletions zany/zanyify.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// ==UserScript==
// @name Zanyify
// @namespace http://tampermonkey.net/
// @version 0.1
// @description twist the text for a zany effect
// @author Josh Parker
// @match https://www.washingtonpost.com/*
// @match https://www.google.com/*
// @match https://en.wikipedia.org/wiki/*
// @match https://www.tampermonkey.net/*
// @icon https://www.google.com/s2/favicons?domain=washingtonpost.com
// @grant none
// ==/UserScript==

(function zanyifyUserScript() {
const body = document.querySelector('body');
const existingTextManips = document.querySelector('body > div.josh-text-manips');
const joshTextManips = existingTextManips || document.createElement('div');
joshTextManips.className = 'josh-text-manips';
const zanyifyButton = document.createElement('button');
zanyifyButton.innerText = 'zanyify';

const changeTextToZanyText = function changeTextToZanyText(element) {
const e = element;
const singleLetterSpans = e.textContent.split('').map((c) => {
const singleLetterSpan = document.createElement('span');
singleLetterSpan.textContent = c;
singleLetterSpan.style.setProperty('transform', `rotate(${Math.random() / 2 - 0.25}turn)`);
return singleLetterSpan;
});

e.textContent = '';
singleLetterSpans.forEach((span) => e.appendChild(span));
};

const zanyify = function zanyify({ target }) {
const e = target;
body.removeEventListener('mousedown', zanyify);

const singleLetterSpans = e.textContent.split('').map((c) => {
const singleLetterSpan = document.createElement('span');
singleLetterSpan.textContent = c;
return singleLetterSpan;
});

e.textContent = '';
singleLetterSpans.forEach((span) => e.appendChild(span));

const zanyifyMouseover = ({ target: mouseoverTarget }) => {
const f = mouseoverTarget;
if (f.tagName === 'SPAN') {
f.className = 'selected';
}
};

e.addEventListener('mouseover', zanyifyMouseover);

const zanyifyMouseup = () => {
e.removeEventListener('mouseup', zanyifyMouseup);
e.removeEventListener('mouseover', zanyifyMouseover);
const text = e.textContent;
const classNames = [...e.childNodes].map((node) => node.className);
const selectionStart = classNames.indexOf('selected');
const selectionEnd = classNames.lastIndexOf('selected') + 1;
e.innerHTML = `${text.slice(0, selectionStart)}<span class='zany-text'>${text.slice(selectionStart, selectionEnd)}</span>${text.slice(selectionEnd)}`;
changeTextToZanyText(e.querySelector('span.zany-text'));
zanyifyButton.removeAttribute('disabled');
};

e.addEventListener('mouseup', zanyifyMouseup);
};

zanyifyButton.addEventListener('click', () => {
zanyifyButton.setAttribute('disabled', true);
body.addEventListener('mousedown', zanyify);
});

joshTextManips.appendChild(zanyifyButton);
if (!existingTextManips) {
body.appendChild(joshTextManips);
}

document.styleSheets[0].insertRule('.josh-text-manips {position: fixed;background-color: lightgrey;padding: 5px 10px;top: 62px;right: 10px;border-radius: 16px;box-shadow: 2px 2px 1px black;}');
}());

0 comments on commit 57a254f

Please sign in to comment.