Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name Slack Code Syntax Highlighter
// @namespace M_Ishikawa
// @version 0.1
// @description Click code block, highlight it.
// @author Masayuki Ishikawa
// @match https://*.slack.com/*
// @grant none
// ==/UserScript==
/**
* Thanks for highlight.js.
*/
(function() {
'use strict';
// 'monokai-sublime', 'xcode', 'darcula', 'solarized-dark', 'solarized-light', 'github', 'github-gist', 'xcode', 'androidstudio', ... and more.
// @see https://highlightjs.org/static/demo/
let theme = 'monokai';
$('body').prepend(`<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>`);
$('body').prepend($('<style/>').load('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/' + theme + '.min.css'));
$(window).on('click', function(e) {
if ($(e.target).prop('tagName') !== 'PRE' || ! $(e.target).hasClass('c-mrkdwn__pre') || $(e.target).attr('data-highlighted')) {
return;
}
$(e.target).wrapInner('<code/>');
$(e.target).attr('data-highlighted', true);
hljs.highlightBlock(e.target);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.