-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
153 lines (149 loc) · 5.03 KB
/
index.html
File metadata and controls
153 lines (149 loc) · 5.03 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<meta charset=utf-8>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<title>Room intro tool</title>
<link rel="shortcut icon" href="https://play.pokemonshowdown.com/favicon.ico">
<link rel=stylesheet href="https://play.pokemonshowdown.com/style/client.css">
<link rel=stylesheet href="https://play.pokemonshowdown.com/style/sim-types.css">
<link rel=stylesheet href="https://play.pokemonshowdown.com/style/battle.css">
<link rel=stylesheet href="https://play.pokemonshowdown.com/style/utilichart.css">
<link rel=stylesheet href="https://play.pokemonshowdown.com/style/font-awesome.css">
<style>
#header h1 {
color: black;
padding-left: 0.5em;
text-shadow: 2px 2px 1px #888;
}
#html-input, #html-output {
display: block;
}
#html-input {
left: 0;
right: auto;
width: 500px;
}
#html-output {
width: auto;
right: 0;
left: 501px;
}
#html-editor {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
</style>
<div id="header" class="header">
<h1>Room intro tool</h1>
<div class="maintabbarbottom"></div>
<div class="userbar">
<button class="button" id="dark">Toggle Dark Mode</button>
</div>
</div>
<div class="ps-room ps-room-light scrollable" id="html-input">
<div id="html-editor">Feel free to modify the room intro. The changes will be visible here.</div>
</div>
<div class="ps-room ps-room-light scrollable" id="html-output">
<div class="chat-log hasuserlist">
<div class="inner">
<div class="notice"><div class="infobox infobox-limited" id="html-caja-output"></div></div>
<div class="notice">Source:</div>
<div class="notice"><div class="infobox"><code>/roomintro <span id="html-intro-code"></span></code></div></div>
<div class="notice"></div>
</div>
</div>
<ul class="userlist">
<li class="userlist-count" id="upperstaff-userlist-users" style="text-align:center;padding:2px 0"><small><span id="upperstaff-usercount-users">1</span> user</small></li>
<li><button class="userbutton username"><em class="group staffgroup">#</em><strong><em>You</em></strong></button></li>
</ul>
<div class="chat-log-add hasuserlist"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.3.3/ace.js"></script>
<script>
window.global = window
</script>
<script src="https://play.pokemonshowdown.com/js/lib/jquery-2.2.4.min.js"></script>
<script src="https://play.pokemonshowdown.com/js/lib/html-css-sanitizer-minified.js"></script>
<script src="https://play.pokemonshowdown.com/config/config.js"></script>
<script src="https://play.pokemonshowdown.com/js/battledata.js"></script>
<script>
const domParser = new DOMParser()
function parseCSS(code) {
const parsed = domParser.parseFromString(`<body>${code}`, 'text/html').body
var implDocument = document.implementation.createHTMLDocument("Temporary CSS storage")
var stylesheets = parsed.getElementsByTagName('style')
for (var i = 0; i < stylesheets.length; i++) {
var element = stylesheets[i]
// CSS element needs to be in document to be actually parsed
implDocument.body.appendChild(element)
var rules = element.sheet.cssRules
for (var j = 0; j < rules.length; j++) {
var rule = rules[j]
var elements = parsed.querySelectorAll(rule.selectorText)
for (var k = 0; k < elements.length; k++) {
var element = elements[k]
var newValue = (element.getAttribute('style') || "") + rule.style.cssText
element.setAttribute('style', newValue)
}
}
}
return parsed.innerHTML
}
var removableListeners = []
function modifyRoomIntro(action, editor) {
for (var i = 0; i < removableListeners.length; i++) {
removableListeners[i]()
}
removableListeners = []
var rawValue = editor.getSession().getValue()
localStorage.setItem('code', rawValue)
var value = parseCSS(rawValue)
var output = document.getElementById('html-caja-output')
output.innerHTML = BattleLog.sanitizeHTML(value)
var images = output.getElementsByTagName('img')
for (var i = 0; i < images.length; i++) {
var image = images[i]
var listener = function listener() {
this.setAttribute("width", this.width)
this.setAttribute("height", this.height)
updateCode(output)
}
removableListeners.push(function removeListenerIife(image, listener) {
return function removeListener() {
image.removeEventListener('load', listener)
}
}(image, listener))
image.addEventListener('load', listener)
}
updateCode(output)
}
function updateCode(output) {
document.getElementById('html-intro-code').textContent = output.innerHTML
}
var editor = ace.edit('html-editor')
var session = editor.getSession()
var Range = ace.require('ace/range').Range
session.setOption("useWorker", false)
session.setMode('ace/mode/html')
session.setUseWrapMode(true)
editor.on('change', modifyRoomIntro)
editor.selection.setRange(new Range(0, 0, true))
var code = localStorage.getItem('code')
if (code) {
editor.getSession().setValue(code)
}
editor.focus()
modifyRoomIntro(null, editor)
$('#dark').on('click', function () {
var $html = $('html')
if ($html.hasClass('dark')) {
editor.setTheme('ace/theme/textmate')
$html.removeClass('dark')
} else {
editor.setTheme('ace/theme/twilight')
$html.addClass('dark')
}
})
</script>