Skip to content

Instantly share code, notes, and snippets.

@jaywick
Created June 7, 2018 04:36
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/4a8c0d8b96346dd151586d94333ed90c to your computer and use it in GitHub Desktop.
Save jaywick/4a8c0d8b96346dd151586d94333ed90c to your computer and use it in GitHub Desktop.
// ==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