Skip to content

Instantly share code, notes, and snippets.

View michaelrhodes's full-sized avatar

Michael Rhodes michaelrhodes

View GitHub Profile
@michaelrhodes
michaelrhodes / clean-anchor-bookmarklet.js
Created February 20, 2021 02:13
Remove tracking parameters from anchor tags
javascript:!function(d){[].forEach.call(d.querySelectorAll('a'),a=>{a.setAttribute('rel','noreferrer%20noopener');(a.href=a.href.split('?').map((v,i)=>i?v.replace(/&?(ref|utm_[^=]+)=[^&]*(&|$)/g,''):v).join('?').replace(/\?$/,''))})}(document)
@michaelrhodes
michaelrhodes / yt-embedded-bookmarklet.js
Last active August 31, 2020 09:25
load youtube videos in distraction-free embedded views
javascript:(function(h,r){l(h)||(onclick=function(e,a){onclick=null;(a=e.target.closest('a'))&&l(a.href)});function%20l(h,i){(i=h&&r.test(h)&&h.replace(r,'$3'))&&(location.href='https://youtube.com/embed/'+i+'?modestbranding=1&iv_load_policy=3')}})(location.href,/^https:\/\/(www\.)?youtu(.be\/|be.com\/watch\?v=)([^\/&#\?]+).*$/)
@michaelrhodes
michaelrhodes / unicode-monospace.js
Last active January 22, 2021 12:42
[usage] str.split('').map(monospace).join('')
monospace = chr => /\s/.test(chr) ? chr : String.fromCharCode(65296 + (chr.charCodeAt(0) - 48))
@michaelrhodes
michaelrhodes / find-yt-feed-bookmarklet.js
Created August 25, 2020 03:33
find a youtube channel’s feed url
javascript:(function(d,l,h){l=d.querySelector('link[href*=channel]');h=l&&l.getAttribute('href');h&&alert('https://www.youtube.com/feeds/videos.xml?channel_id='+h.split('/').pop())%20})(document)
@michaelrhodes
michaelrhodes / gh-pages-bookmarklet.js
Created August 25, 2020 03:31
toggle between repo and gh-pages
javascript:(function(){(function(){if(/github.io$/.test(location.host)){var%20paths=location.href.match(/^.+\/\/(.+)\.github\.io\/([^\/]+)?\/?.*$/).slice(1);location.href="https://github.com/"+paths[0]+"/"+(paths[1]||'')}else%20if(location.host=="github.com"){var%20paths=location.pathname.substr(1).split("/");location.href="http://"+paths[0]+".github.io/"+paths[1]}})()})();
@michaelrhodes
michaelrhodes / ipv4-to-uint32.js
Created August 22, 2020 00:30
convert an ipv4 address into its uint32 representation
ipv4.split('.').reduce((sum, num, ndx, arr) => sum + (num * Math.pow(256, arr.length - 1 - ndx)), 0)
@michaelrhodes
michaelrhodes / detect-font-bookmarklet.js
Last active August 25, 2020 03:34
click the bookmarklet, then click the text whose font-family you wish to detect
javascript:onclick=function(t){return%20onclick=t.preventDefault(),alert(function(t){if(t){for(var%20e=document.createElement("span"),i=document.createElement("canvas"),n=i.getContext("2d"),l="",o=33;o<127;)l+=String.fromCharCode(o++);var%20a=getComputedStyle(t),c=[a.fontStyle,a.fontWeight,"16px/1"],h=a.fontFamily.split(/\s*,\s*/);e.style.font=c.concat(a.fontFamily).join("%20"),e.style.position="absolute",e.style.visibility="hidden",e.textContent=l,document.body.appendChild(e);var%20d,r,g=e.getBoundingClientRect();i.height=g.height,i.width=g.width,n.textAlign="left",n.textBaseline="top";for(var%20f,m=h.length;m--;)n.font=c.concat(h.slice(m).join(",")).join("%20"),n.fillStyle="white",n.fillRect(0,0,g.width,g.height),n.fillStyle="black",n.fillText(l,0,0),n.getImageData(0,0,g.width,g.height),(d=h.join.call(n.getImageData(0,0,g.width,g.height).data,""))!==r&&(f=h[m],r=d);return%20document.body.removeChild(e),f&&f.replace(/["']/g,"")}}(t.target))};
@michaelrhodes
michaelrhodes / grid.js
Created February 12, 2019 07:06
Grid Bookmarklet
javascript:!function(){var c="#fff",s=64,d=document,f=d.createDocumentFragment(),n=d.createElement("i"),t=Math.ceil(innerWidth/s);n.style.cssText="pointer-events:none;position:fixed;top:0;left:0;background-color:"+c,Array(t).join(" ").split(" ").forEach(function(t,i){if(i){var x=n.cloneNode(),y=n.cloneNode();x.style.cssText+="bottom:0;width:1px;transform:translateX("+s*i+"px)",y.style.cssText+="right:0;height:1px;transform:translateY("+s*i+"px)",f.appendChild(x),f.appendChild(y)}}),d.body.appendChild(f)}()

Keybase proof

I hereby claim:

  • I am michaelrhodes on github.
  • I am michaelrhodes (https://keybase.io/michaelrhodes) on keybase.
  • I have a public key whose fingerprint is 9B60 F9CE F597 16B7 0ACA F407 E021 ED18 F1DC D8FE

To claim this, I am signing this object:

function each (o, fn) {
Array.isArray(o) ? o.forEach(fn) :
Object.keys(o).forEach(function (key, i) {
fn.call(this, o[key], key, o)
})
}