Last active
May 6, 2023 06:52
-
-
Save ishikawam/6a57599a70471b7fabfa4d37e95d112f to your computer and use it in GitHub Desktop.
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 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
How can I use this in Slack application? (MacOS)