Skip to content

Instantly share code, notes, and snippets.

@floydpink
Last active April 4, 2017 00:08
Show Gist options
  • Save floydpink/3934c8c765c5ce67efcbd05508756fdc to your computer and use it in GitHub Desktop.
Save floydpink/3934c8c765c5ce67efcbd05508756fdc to your computer and use it in GitHub Desktop.
SMC Webfonts Bookmarklet
var fonts = [{
name: 'meera',
font: 'Meera'
}, {
name: 'rachana',
font: 'Rachana'
}, {
name: 'dyuthi',
font: 'Dyuthi'
}, {
name: 'raghumalayalam',
font: 'RaghuMalayalam'
}, {
name: 'chilanka',
font: 'Chilanka'
}, {
name: 'keraleeyam',
font: 'Keraleeyam'
}, {
name: 'manjari',
font: 'Manjari'
}, {
name: 'suruma',
font: 'Suruma'
}, {
name: 'uroob',
font: 'Uroob'
}, {
name: 'karumbi',
font: 'Karumbi'
}, {
name: 'anjali',
font: 'AnjaliOldLipi'
}];
var setFonts = (function () {
return function (selectedFontName) {
if (!selectedFontName) return;
var selectedFonts = fonts.filter(function (f) {
return f.font === selectedFontName;
});
if (selectedFonts.length !== 1) return alert('Incorrect font name!');
var selectedFont = selectedFonts[0];
var head = document.getElementsByTagName('head')[0],
link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
link.href = '//cdn.jsdelivr.net/smc-webfonts/0.0.1/fonts/' + selectedFont.name + '.min.css';
head.appendChild(link);
var styleInPage = function (css, newStyle) {
if (typeof getComputedStyle == 'undefined')
getComputedStyle = function (elem) {
return elem.currentStyle;
};
var val, who, hoo, values = {},
nodes = document.body.getElementsByTagName('*'),
L = nodes.length;
for (var i = 0; i < L; i++) {
who = nodes[i];
if (who.style) {
hoo = '#' + (who.id || who.nodeName + '(' + i + ')');
val = who.style.fontFamily || getComputedStyle(who, '')[css];
if (val && val.indexOf('FontAwesome') === -1 && val.indexOf(newStyle) === -1) {
who.style.fontFamily = newStyle + ',' + val;
if (!values[val]) {
values[val] = [];
}
values[val].push(hoo);
}
}
}
return values;
};
styleInPage('fontFamily', selectedFont.font);
};
})();
var fontNames = fonts.map(function (f) {
return f.font;
}).sort();
setFonts(prompt('Type in a font name from the below list:\n\n' + fontNames.join(', ')));
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-4869398-10', 'auto');
ga('send', 'pageview');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment