Skip to content

Instantly share code, notes, and snippets.

Chris Goddard chrisgoddard

Block or report user

Report or block chrisgoddard

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@chrisgoddard
chrisgoddard / delete-likes.js
Last active Jul 25, 2019
Delete liked tweets
View delete-likes.js
// run in console at twitter.com/username/likes (replace username with your username)
(function(document,window) {
function clearlikes(){
    window.scrollTo(0,document.body.scrollHeight);
    Array.from(document.querySelectorAll('[data-testid="unlike"]')).forEach(function(el){
     el.click();
    })
    setTimeout(clearlikes, 5000);
}
clearlikes();
@chrisgoddard
chrisgoddard / gtm-utilities.js
Last active Aug 1, 2019
Google Tag Manager Utility Library
View gtm-utilities.js
function(){
"use strict";
/**
* Constants
*/
var VERSION = '2.1';
@chrisgoddard
chrisgoddard / code.js
Created Jun 24, 2018
object to query string
View code.js
function buildQueryParams(params){
return Object.keys(params).map(function(key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
}).join('&');
}
@chrisgoddard
chrisgoddard / regex-reference.txt
Created Jun 21, 2018
domain filter regex reference
View regex-reference.txt
www.domain.com | ^www\.resmed\.com$
www.domain.com | ^www\d?\.resmed\.com$
www3.domain.com |
www.domain.com | ^(www\d?\.)?resmed\.com$
www3.domain.com |
domain.com |
@chrisgoddard
chrisgoddard / patterns
Created Oct 25, 2016
Useful regex patterns
View patterns
Extract domain from string (with or without protocol)
[?:http(s)?:\/\/]?([a-z0-9\-]+\.?[a-z0-9\-]+\.[a-z]{2,3})
View json-ld-gtm.html
<script>
(function(){
var data = {
"@context": "http://schema.org",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{Page URL}}
},
"headline": {{SCHEMA - Article Headline}},
View detect-mobile.js
/**
* Simple regex/user agent mobile checker
* about 99% accurate when compared to 175k sessions in GA
*/
function isMobile()
{
return window.navigator.match(/Mobi|Touch|OperaMini|Android/)
}
@chrisgoddard
chrisgoddard / find-overflow.js
Created Oct 12, 2015
Find unintended body overflow
View find-overflow.js
var docWidth = document.documentElement.offsetWidth;
[].forEach.call(
document.querySelectorAll('*'),
function(el) {
if (el.offsetWidth > docWidth) {
console.log(el);
}
}
);
View Useful Utility Functions
function getUrlParam(url, param) {
var match = url.match('(?:\\?|&)' + param + '=([^&#]*)');
return (match && match.length == 2) ? decodeURIComponent(match[1]) : '';
}
@chrisgoddard
chrisgoddard / load
Created Jun 19, 2015
Async Script Loader
View load
(function(a,b,c,e,d){a=b.createElement(c);
b=b.getElementsByTagName(c)[0];
a.async=1;d&&(a.onload=d);a.src=e;b.parentNode.insertBefore(a,b)
})(window,document,"script","//example.com/script", function callback(){});
You can’t perform that action at this time.