-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtiohighlightjs.user.js
94 lines (76 loc) · 2.54 KB
/
tiohighlightjs.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// ==UserScript==
// @name TIO Highlight.js
// @namespace http://tampermonkey.net/
// @version 0.6.1
// @description Adds Highlight.js to TIO.
// @author Teh Flamin' Taco
// @match https://tio.run/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Your code here...
var s_pretty = document.createElement("script");
s_pretty.setAttribute("src","https://a-ta.co/highlight.pack.js");
document.body.append(s_pretty);
var editors = ["header","code","footer"].map(z=>document.getElementById(z));
var holder = document.getElementById('interpreter');
for(var i=0; i < editors.length; i++){
(function(i){
var e = editors[i];
var div = document.createElement('div');
div.setAttribute('class', 'text_area_holder');
holder.insertBefore(div, e);
var syntax = document.createElement('pre');
syntax.setAttribute('class', 'syntax');
div.append(syntax);
div.append(e);
var oldCode = '';
var update = function(){
if(e.value != oldCode){
syntax.textContent = e.value;
syntax.setAttribute('class', 'syntax '+(window.languages[window.languageId].prettify||window.languageId));
oldCode = e.value;
window.hljs.highlightBlock(syntax);
}
}
e.addEventListener("input", update);
s_pretty.addEventListener("load", update);
})(i);
}
var c_style = document.createElement('style');
c_style.innerHTML = `#header, #footer, #code{
font-weight:0;
color:rgba(255,255,255,0.0);
caret-color:#FFF;
}
.syntax{
font-family: 'DejaVu Sans Mono';
font-size: 16px;
padding: 0 !important;
float:left;
width: calc(100% - 12px);
height:0;
margin: 0;
border:0 !important;
pointer-events: none;
position:relative;
display:block;
top:5px;
left:6px;
overflow:visible;
white-space: pre-wrap; /* Since CSS 2.1 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
.syntax span{
font-weight:normal;
}`;
var css_pretty = document.createElement('link');
css_pretty.setAttribute('href', '//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/railscasts.min.css');
css_pretty.setAttribute('rel', 'stylesheet');
document.body.append(css_pretty);
document.body.append(c_style);
})();