-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext.js
More file actions
66 lines (66 loc) · 1.97 KB
/
ext.js
File metadata and controls
66 lines (66 loc) · 1.97 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
/* <nowiki>
*
* @module demeter/ext.js
* @description Oasis design wrapper and userscripting extension for FANDOM Discussions.
* @author Speedit
* @license CC-BY-SA 3.0
*
*/
(function(xhr, ext, rel) {
// Script variables.
var api = 'https://api.github.com/repos/speeditor/demeter/releases/latest';
/**
* @function ext.import
*/
ext.init = function() {
ext.tag = JSON.parse(this.responseText).tag_name;
['js', 'css'].forEach(ext.import);
};
// Script import logic (grants access to the browser context).
/**
* Import application script from Github.
* @function ext.import
* @param {string} c File extension.
*/
ext.import = function(c) {
var p = 'https://cdn.rawgit.com/speeditor/demeter/' + ext.tag +'/app.' + c;
for (var n in ext.opts[c])
rel[c].setAttribute(n, ext.opts[c][n]);
switch (c) {
case 'css':
rel.css.disabled = true;
rel.css.href = p;
break;
case 'js':
rel.js.async = true;
rel.js.src = p;
rel.js.onload = function() {
rel.css.disabled = false;
};
break;
}
document.head.appendChild(rel[c]);
};
/**
* Element attributes for imports.
* @member {Object} ext.opts
*/
ext.opts = {
'css': {
'rel': 'stylesheet',
'type': 'text/css',
'crossorigin': 'anonymous'
},
'js': {
'type': 'text/javascript',
'crossorigin': 'anonymous'
}
};
// Script bootloader (fetches script version).
xhr.onload = ext.init;
xhr.open('GET', api);
xhr.send();
}(new XMLHttpRequest(), {}, {
css: document.createElement('link'),
js: document.createElement('script')
}));