-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.html
182 lines (160 loc) · 5.57 KB
/
index.html
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Embed draw.io in Notion</title>
<style>
html {
font-family: Arial, Helvetica, sans-serif;
}
.form-container {
display: flex;
align-items: center;
justify-content: center;
}
.container {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#form {
display: flex;
flex-direction: column;
gap: 20px;
align-items: center;
}
#draw-iframe {
width: 100%;
height: 100%;
border: 0;
}
input[type="submit"] {
user-select: none;
transition: background 20ms ease-in 0s;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
white-space: nowrap;
height: 36px;
border-radius: 3px;
color: white;
font-size: 14px;
line-height: 1;
padding-left: 12px;
padding-right: 12px;
font-weight: 500;
background: rgb(225, 98, 89) none repeat scroll 0% 0%;
border: 1px solid rgb(190, 86, 67);
box-shadow: rgba(15, 15, 15, 0.1) 0px 1px 2px;
text-align: center;
width: 90px;
}
input[type="url"],
input[type="text"] {
font-size: inherit;
line-height: inherit;
border: medium none;
background: rgba(0, 0, 0, 0)
url("data:image/svg+xml;base64,PHN2ZyBvcGFjaXR5PSIuNyIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2aWV3Qm94PSIwIDAgNTAgNTAiPjxwYXRoIGQ9Ik0zOCA1MEgxMkM1LjQgNTAgMCA0NC42IDAgMzhWMTJDMCA1LjQgNS40IDAgMTIgMGgyNmM2LjYgMCAxMiA1LjQgMTIgMTJ2MjZjMCA2LjYtNS40IDEyLTEyIDEyeiIgZmlsbD0iIzNkMzY0ZiIvPjxwYXRoIGQ9Ik0zMi40IDM1LjdjLTEuMi44LTMuMiAxLjQtNS4xIDEuNC00LjEgMC02LjYtMS42LTYuNi01LjhWMjNoLTMuMXYtNC40aDMuMXYtNGw2LjEtMS43djUuN2g1LjRWMjNoLTUuNHY3LjJjMCAxLjcuOSAyLjQgMi40IDIuNCAxLjEgMCAxLjktLjMgMi42LS44bC42IDMuOXoiIGZpbGw9IiNmZmYiLz48L3N2Zz4=")
no-repeat scroll 97% center / 16px;
width: 300px;
display: inline-block;
resize: none;
padding: 0px;
cursor: auto;
box-shadow: rgba(15, 15, 15, 0.1) 0px 0px 0px 1px inset,
rgba(15, 15, 15, 0.1) 0px 1px 1px inset;
font-size: 15px;
line-height: 26px;
padding: 4px 10px;
outline: none;
color: rgb(4, 4, 4);
border-radius: 3px;
}
.hide {
display: none !important;
}
.disclaimer {
color: #bbb;
font-size: 0.8em;
text-align: center;
line-height: 1.5;
}
.disclaimer a {
color: #bbb;
}
</style>
</head>
<body>
<div class="container form-container">
<div id="form">
<div id="form-entry">
<input
type="url"
placeholder="draw.io Embed URL"
id="embedUrl"
name="embedUrl"
/>
<input type="submit" value="Go" onclick="onGoClick()" />
</div>
<div id="form-result" class="hide">
<span>Embed this URL in Notion:</span>
<input type="url" readonly id="finalUrl" name="finalUrl" />
<input type="submit" value="Copy" onclick="onCopyClick()" />
</div>
<p class="disclaimer">
This website is in no way affiliated with Notion or draw.io<br/><a href="https://github.com/ivankahl/drawio-notion-embed" target="_blank">GitHub</a> • <a href="https://ivankahl.com/" target="_blank">Ivan Kahl</a>
</p>
</div>
<iframe id="draw-iframe" class="hide" src=""></iframe>
</div>
<script>
// From https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return "";
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
// From https://stackoverflow.com/questions/23425909/javascript-jquery-get-root-url-of-website
function getBaseUrl() {
return window.location.href.match(/^.*\//);
}
function copy(elementId) {
/* Get the text field */
var copyText = document.getElementById(elementId);
/* Select the text field */
copyText.select();
copyText.setSelectionRange(0, 99999); /*For mobile devices*/
/* Copy the text inside the text field */
document.execCommand("copy");
/* Alert the copied text */
alert("Copied the text: " + copyText.value);
}
const url = getParameterByName("u");
if (url) {
document.querySelector(".container").classList.remove("form-container");
document.getElementById("form").classList.add("hide");
const iframe = document.getElementById("draw-iframe");
iframe.setAttribute("src", url);
iframe.classList.remove("hide");
}
function onGoClick() {
const url = document.getElementById("embedUrl").value;
let finalUrl = getBaseUrl() + "?u=" + encodeURIComponent(url);
document.getElementById("finalUrl").value = finalUrl;
document.getElementById("form-result").classList.remove("hide");
}
function onCopyClick() {
copy("finalUrl");
}
</script>
</body>
</html>