Created
March 19, 2018 22:55
-
-
Save jaywick/b2d29c794424644e3101c455fbb6bf12 to your computer and use it in GitHub Desktop.
Twitter basic markdown support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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