-
-
Notifications
You must be signed in to change notification settings - Fork 144
/
bookmarklet.js
32 lines (32 loc) · 1.27 KB
/
bookmarklet.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
var request = new XMLHttpRequest();
request.open("GET", "https://jenil.github.io/bulmaswatch/api/themes.json", true);
request.onreadystatechange = function() {
var done = 4,
ok = 200;
if (request.readyState == done && request.status == ok) {
if (request.responseText) {
var BS = JSON.parse(request.responseText);
console.log('bulmaswatch', BS.version);
var themes = BS.themes;
var select = '<span class="select" id="theme-switcher"><select>';
select += '<option value="default" selected="">Select theme</option>';
for (var i = 0; i < themes.length; i++) {
select += '<option value="' + themes[i].css + '">' + themes[i].name + '</option>'
}
select += '</select></span>';
var temp = document.createElement('div');
temp.innerHTML = select;
document.body.appendChild(temp.firstChild);
document.querySelector('#theme-switcher').style = 'position:fixed;top:0;right:0;z-index:9900';
var l = document.createElement("link");
l.rel = "stylesheet";
l.href = "";
l.id = 'bulmaswatch-css';
document.body.appendChild(l);
document.querySelector('#theme-switcher select').addEventListener("change", function() {
l.href = this.value;
});
}
}
};
request.send(null);