-
Notifications
You must be signed in to change notification settings - Fork 5
/
tiogoogleprettify.user.js
86 lines (73 loc) · 2.36 KB
/
tiogoogleprettify.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
// ==UserScript==
// @name TIO Prettify
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Adds Google Prettyprint 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://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.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', 'prettyprint syntax');
div.append(syntax);
div.append(e);
editors[i] = {
textarea : e,
div : div,
syntax : syntax
};
var oldCode = '';
var update = function(){
if(e.value != oldCode){
syntax.textContent = e.value;
syntax.setAttribute('class', 'prettyprint syntax');
oldCode = e.value;
}
PR.prettyPrint();
}
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.3)
}
.syntax{
width:100%;
font-family: 'DejaVu Sans Mono';
height:0;
font-size: 16px;
padding: 0 !important;
float:left;
width: 100%;
margin: 0;
border:0 !important;
pointer-events: none;
z-index: 1000;
position:relative;
display:block;
top:5px;
left:6px;
}`;
document.body.append(c_style);
var css_pretty = document.createElement('link');
css_pretty.setAttribute('href', 'https://jmblog.github.io/color-themes-for-google-code-prettify/themes/tomorrow-night.min.css');
css_pretty.setAttribute('rel', 'stylesheet');
document.body.append(css_pretty);
})();