Skip to content

Instantly share code, notes, and snippets.

View ricealexander's full-sized avatar

Alex Rice ricealexander

View GitHub Profile
@ricealexander
ricealexander / long-selector.css
Created April 15, 2020 21:26
Longest CSS Selector I've written. Adds focus effects to custom radio buttons.
#theme #ctl00_AllegMain_MODETABLE td:focus-within input[type="radio"] + label::before,
#theme #ctl00_AllegMain_UPGRADETABLE td:focus-within input:not([value="ALLEGOTHER"]) + label,
#theme #ctl00_AllegMain_UPGRADETABLE td:focus-within input[value="ALLEGOTHER"] + label::before {
border-color: #222;
}
@ricealexander
ricealexander / comment-stripper.txt
Last active May 21, 2020 19:31
Regex for stripping comments in a file
# Match all comments
\n?\s*\/\/\s.*
# \n? optional-linebreak for matching comments on their own line
# \s* matches any number of spaces preceeding //
# \/\/ matches //
# \s matches a single space after //. Lack of a space may indicate non-comment usage of //
# .* matches the content of the comment until the end of the current line
@ricealexander
ricealexander / isolateEventListener.js
Last active April 7, 2020 23:05
SPA can load custom scripts. We do not have control of the SPA otherwise. These files can isolate recurring code so it does not persist from page to page
(function() {
// Isolate Event Listener so it is safe to use
// current URL is checked each time the event listener is activated
// if a different page is loaded, the event will destroy itself the next time it is active
// In this demo, we are able to completely isolate this behavior inside
// an abstraction called createIsolatedEvent, which is fully reusable
@ricealexander
ricealexander / google-site-customization.css
Created April 3, 2020 18:53
A few rules which drastically improves the appearance of Google Sites theme
#sites-chrome-everything {
background: #f9fbfc;
}
#sites-header-title {
height: 80px;
}
#sites-chrome-page-wrapper-inside #sites-chrome-header-wrapper {
background: none;
@ricealexander
ricealexander / remove-promotions.js
Created April 3, 2020 18:49
Remove promoted content on different platforms
// Remove Twitter Promoted Tweets
window.addEventListener('scroll', _event => {
[ ...document.querySelectorAll('h2') ]
.filter(heading => heading.textContent.includes("Promoted Tweet"))
.map(heading => heading.parentElement.parentElement)
.forEach(promotion => promotion.remove())
})
// Remove LinkedIn Promoted Posts
window.addEventListener('scroll', _event => {
@ricealexander
ricealexander / collect-corepub-links.js
Created April 3, 2020 18:34
Instructions for gathering URLs from CorePub's limited feed
@ricealexander
ricealexander / matchesCaseInsensitive.js
Created April 3, 2020 18:29
Compares strings to determine whether they are all the same, case-insensitively
const matchesCaseInsensitive = (first, ...rest) => {
if (rest.length === 0) {
throw new Error(`Expected at least 2 arguments`)
}
const target = first.toLowerCase()
return rest.every(value => value.toLowerCase() === target)
}
@ricealexander
ricealexander / stlpr-analytics-bundle.js
Last active February 14, 2020 20:07
Bundle Analytics
(function(){
var scriptOrder = 0
function loadScript (src) {
// create script
var script = document.createElement("script")
script.async = true
script.src = src
// insert script into the top of the document
@ricealexander
ricealexander / top-navigation.json
Created February 6, 2020 21:21
A hacky, but straight-forward and flexible, representation of STLPR's navigation
[
{"News Topics": {
"dropdown": [
{"Arts & Culture": "https://news.stlpublicradio.org/term/arts-culture"},
{"Economy & Innovation": "https://news.stlpublicradio.org/term/economy-innovation"},
{"Education": "https://news.stlpublicradio.org/term/education-0"},
{"Health, Science, Environment": "https://news.stlpublicradio.org/term/health-science"},
{"Politics & Issues": "https://news.stlpublicradio.org/term/politics-issues"},
{"Metro East Coverage": "https://news.stlpublicradio.org/topic/metro-east-coverage"},
{"Rolla-Region Coverage": "https://news.stlpublicradio.org/topic/rolla-region-coverage"},
@ricealexander
ricealexander / stripTags.js
Created January 31, 2020 21:15
Strip HTML Tags
const stripTags = string => {
const temp = document.createElement('div')
temp.innerHTML = string.replace(/<br[^>]*>/gi, ' ')
return temp.textContent
}