-
Notifications
You must be signed in to change notification settings - Fork 0
/
emet.tmpl.js
56 lines (47 loc) · 2.19 KB
/
emet.tmpl.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
/*
@@@@@@@@ @@@@@@ @@@ @@@@@@@@ @@@@@@@@@@
@@@@@@@@@ @@@@@@@@ @@@ @@@@@@@@ @@@@@@@@@@@
!@@ @@! @@@ @@! @@! @@! @@! @@!
!@! !@! @!@ !@! !@! !@! !@! !@!
!@! @!@!@ @!@ !@! @!! @!!!:! @!! !!@ @!@
!!! !!@!! !@! !!! !!! !!!!!: !@! ! !@!
:!! !!: !!: !!! !!: !!: !!: !!:
:!: !:: :!: !:! :!: :!: :!: :!:
::: :::: ::::: :: :: :::: :: :::: ::: ::
:: :: : : : : : :: : : : :: :: : :
This script will run a golem when loaded, but only on
a headless Chrome and only one per webstrate.
You can can control this golem with the following
commands:
To *reload* the golem, i.e. reset its state and run it
again:
$ curl https://{{ .BaseURL }}/golem/v1/reset/<webstrate-id>
To *kill* the golem (the golem will respawn the next
time the page is loaded):
$ curl https://{{ .BaseURL }}/golem/v1/kill/<webstrate-id>
*/
(function(){
if (!/headless/i.exec(navigator.userAgent)) {
// You're human, probably.
// Send request to spawn golem, multiple requests
// for the same webstrate will be ignored
var spawnRequest = new XMLHttpRequest();
spawnRequest.onreadystatechange = function() {
if (spawnRequest.readyState === XMLHttpRequest.DONE) {
if (spawnRequest.status === 200) {
console.log("Golem spawned for "+webstrate.webstrateId);
} else {
console.warn("Golem could not be spawned - "+spawnRequest.responseText);
}
}
};
spawnRequest.open('GET', 'https://{{ .BaseURL }}/golem/v1/spawn/'+webstrate.webstrateId, true);
spawnRequest.send();
} else {
// You're a golem, most likely.
// Bootstrap yourself. Rise!
window.setTimeout(function() {
new Function(document.querySelector(".golem,#emet").textContent)();
}, 5000);
}
})();