Skip to content

Instantly share code, notes, and snippets.

View audacitus's full-sized avatar

Audacitus audacitus

View GitHub Profile
@oliyh
oliyh / image-url-to-data-uri.js
Created November 7, 2015 22:17
Convert an image url to a data URI without canvas
// hard won knowledge from http://stackoverflow.com/questions/20035615/using-raw-image-data-from-ajax-request-for-data-uri
var xmlHTTP = xhr.XMLHttpRequest();
xmlHTTP.open('GET', url, true);
xmlHTTP.responseType = 'arraybuffer';
xmlHTTP.onload = function(e) {
var arr = new Uint8Array(this.response);
var raw = String.fromCharCode.apply(null,arr);
var b64 = base64.encode(raw);
var dataURL="data:image/png;base64," + b64;
};
@ps-team
ps-team / Append stylesheet to iframe.js
Created October 27, 2017 10:07
Append stylesheet to iframe contents (e.g. Twitter widget) - this is filthy, but it works well when no other option is available.
$(document).ready(function(){
setTimeout(function() {
var iframe = document.getElementsByTagName('iframe')[0],
iframeDoc = iframe.contentWindow.document;
var otherhead = iframeDoc.getElementsByTagName("head")[0];
var css = document.createElement("link");
css.type = "text/css";
css.rel = "stylesheet";
css.href = "/SiteElements/Stylesheets/twitter-widget.css";