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