-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fdf0df
commit 57a254f
Showing
7 changed files
with
168 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
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); | ||
}); | ||
}()); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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;}'); | ||
}()); |