Skip to content

Instantly share code, notes, and snippets.

@jaywick
Created March 19, 2018 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaywick/b2d29c794424644e3101c455fbb6bf12 to your computer and use it in GitHub Desktop.
Save jaywick/b2d29c794424644e3101c455fbb6bf12 to your computer and use it in GitHub Desktop.
Twitter basic markdown support
// ==UserScript==
// @name Twitter Markdown
// @namespace twitter.cm
// @version 0.1
// @description Display basic markdown in twitter
// @author jaywick
// @match https://twitter.com/*
// @license MIT
// @grant none
// ==/UserScript==
var applyStyle = function(css) {
var head = document.getElementsByTagName('head')[0];
if (!head) { return; }
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
};
(function() {
'use strict';
applyStyle(`
code {
font-family: monospace,monospace;
font-size: 1em;
font-size: 13px;
padding: 1px 6px;
background: #F3E5F5;
color: #9C27B0;
border-radius: 2px;
}
`);
Object.values(document.querySelectorAll('.tweet-text'))
.forEach(x => x.innerHTML = x.innerHTML
.replace(/`(.+)`/g, '<code>$1</code>')
.replace(/\b_(.+)_\b/g, '<em>$1</em>')
.replace(/\b\*(.+)*\b/g, '<strong>$1</strong>'));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment