Skip to content

Instantly share code, notes, and snippets.

View karlgroves's full-sized avatar

Karl Groves karlgroves

View GitHub Profile
@karlgroves
karlgroves / gist:0b03befad2af598a870e0bc8695fe132
Created June 3, 2021 17:50
Post the content of a local file to Tenon APIV2 using Axios and Node
// Obvs you have you `npm install axios`
const axios = require('axios');
const fs = require('fs');
const env = 'https://tenon.io/api/v2/'; // NOTE: if you have a private instance of Tenon, you'd change the domain part of this value
const username = 'YOUR_EMAIL_GOES_HERE';
const password = 'PASSWORD_GOES_HERE';
const projectID = 'PROJECTID_GOES_HERE';
const sourceFile = './file.html'; // replace with the path to the file you want to send to Tenon
@karlgroves
karlgroves / gist:fabaf3720feae436a052f956ae089bb6
Last active February 9, 2021 19:38
Bulk "Unlike" in Twitter
/**
* UNLIKE
* Navigate to your "likes"
* Open devtools & go to Console
* Paste this snippet in & hit Enter
*/
setInterval(() => {
for (const d of document.querySelectorAll('div[data-testid="unlike"]')) {
d.click()
}
@karlgroves
karlgroves / textOnly.js
Created January 20, 2016 17:31
Strip CSS classes, style attributes, and stylesheets and replace images with their alt attributes
$(document).ready(function(){
$('*').removeClass();
$('*').removeAttr('style');
$('link[rel="stylesheet"]').remove();
$('img').each(function () {
$(this).replaceWith(
$(this).attr('alt')
@karlgroves
karlgroves / gist:cdd532edbe957851f719
Created June 24, 2015 12:13
Uncompressed Tenon Bookmarklet
javascript:(function () {
var html = document.documentElement.innerHTML;
/**
* the iframe's onload event is triggered twice: once when appending it to the document,
* and once when the form finishes submitting and the new URL is loaded
*/
var loaded = 0;
var iframe = document.createElement('iframe');
@karlgroves
karlgroves / gist:1d73f80f2a0dcc78f82f
Created June 24, 2015 02:40
*Super* rudimentary bookmarklet for testing document source with Tenon
javascript:(function(){var html=document.documentElement.innerHTML;var loaded=0;var iframe=document.createElement('iframe');iframe.name='bookmarklet-'+Math.floor((Math.random()*10000)+1);iframe.style.display='none';iframe.onload=function(){if(++loaded==1){return}document.body.removeChild(iframe)};var form=document.createElement('form');form.method="POST";form.action="https://tenon.io/api/";form.target=iframe.name;var hidden=document.createElement('input');hidden.type='hidden';hidden.name='key';hidden.value='ADD_YOUR_API_KEY_HERE';var store=document.createElement('input');store.type='hidden';store.name='store';store.value='1';var textarea=document.createElement('textarea');textarea.name='src';textarea.value=html;form.appendChild(hidden);form.appendChild(store);form.appendChild(textarea);iframe.appendChild(form);document.body.appendChild(iframe);form.submit()})();
@karlgroves
karlgroves / Focus Bookmarklet
Created January 31, 2014 17:57
Add this bookmarklet to your browser. Activate the bookmarklet and as you tab through the site you should see a red border around whatever gets focus
javascript:(function(){var%20ua=navigator.userAgent.toLowerCase(),ie=ua.indexOf(%22msie%22)!=-1?ua.substr(ie+5,1):0,outlineProp=ie%3C8?%22border%22:%22outline%22,activeItem;function%20styleFocus(e){if(activeItem){activeItem.style[outlineProp]=%22%22;}activeItem=e.target||e.srcElement;if(activeItem){activeItem.style[outlineProp]=%22solid%202px%20red%22;}}if(document.addEventListener){document.addEventListener(%22focus%22,styleFocus,true);}else{document.attachEvent(%22onfocusin%22,styleFocus);}}());
@karlgroves
karlgroves / focusable
Created December 24, 2013 14:58
Found this and thought it looked interesting. I saw it at http://test.cita.illinois.edu/aria/tabpanel/tabpanel2.php#lsc1 and in that page they cite "ajpiano on the jQuery forums." Untested but seems sane
// focusable is a small jQuery extension to add a :focusable selector. Credit to ajpiano on the jQuery forums.
//
$.extend($.expr[':'], {
focusable: function(element) {
var nodeName = element.nodeName.toLowerCase();
var tabIndex = $(element).attr('tabindex');
// the element and all of its ancestors must be visible
if (($(element)[(nodeName == 'area' ? 'parents' : 'closest')](':hidden').length) == true) {
return false;
/**
* cleans up strings so they can be used in URLS
* @author "Borek" - attributed to a post located at:
* http://drupal.org/node/63924
* @param string $string the string we're cleaning
* @return string the input string, ready to go
*/
function pathauto_cleanstring($string)
{
@karlgroves
karlgroves / gist:7545632
Created November 19, 2013 13:49
PHP function to get the MIME type of a remote file.
function getRemoteMimeType($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
# get the content type
return curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
}
@karlgroves
karlgroves / gist:7544592
Created November 19, 2013 12:24
Get DOM path of an element
function getDomPath(el) {
var stack = [];
while ( el.parentNode != null ) {
console.log(el.nodeName);
var sibCount = 0;
var sibIndex = 0;
for ( var i = 0; i < el.parentNode.childNodes.length; i++ ) {
var sib = el.parentNode.childNodes[i];
if ( sib.nodeName == el.nodeName ) {
if ( sib === el ) {