-
Notifications
You must be signed in to change notification settings - Fork 0
/
Old.gs
62 lines (50 loc) · 1.52 KB
/
Old.gs
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
// NOTE: You don't need this file!!!
const OLD_FIXUP_SCRIPT = `<script>
function __getRealLocation() {
var l = null;
google.script.url.getLocation(function(location) {
l = location;
});
return l;
}
function __getHostFromUrlString(url) {
var tmp = document.createElement('a');
tmp.href = url;
return tmp.host;
}
function __getVistingUrl() {
return (new URLSearchParams(__getRealLocation().search)).get("url");
}
async function __fixupElement(e, attr, url) {
// Find URL for the real content
if (url.indexOf("//") >= 0) {
// we should be okay
}
else if (url.startsWith("/")) {
// relative to domain, need to do hacky shit
url = __getHostFromUrlString(__getVistingUrl()) + "/" + url;
}
else {
// just append it; it should work
url = __getVistingUrl() + url;
}
// Fetch the content
let result = await fetch(__getRealLocation().path + "?url=" + url + "&json=1");
if (!result) { console.log("Did not fetch: ", url); return; }
// Parse the result
result = JSON.parse(result);
// Set attribute to inline data
e.setAttribute(attr, "data:" + result["headers"]["Content-Type"] + ";base64," + btoa(result["content"]));
}
function __fixup() {
let e = document.getElementsByTagName("*");
for (let i = 0; i < e.length; i++) {
let current = e[i];
let val = current.getAttribute("src");
if (val) {
__fixupElement(current, "src", val);
}
}
}
__fixup();
</script>`;