-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm.js
199 lines (167 loc) · 5.95 KB
/
m.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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
function shoh(el, d) {
if (!el) return;
if (typeof el === 'string')
for (var el = document.querySelectorAll(el), i = 0; i < el.length; i++)
el[i].style.display = (el[i].style.display === 'none') ? d ? d : 'block' : 'none';
else if (!el.style)
for (var i = 0; i < el.length; i++)
shoh(el[i], d);
else
el.style.display = (el.style.display === 'none') ? d ? d : 'block' : 'none';
}
var locStor = function () {};
locStor.prototype.set = function () {
if(typeof arguments[1] === 'object')
window.localStorage.setItem(arguments[0], JSON.stringify(arguments[1]));
else
window.localStorage.setItem(arguments[0], arguments[1]);
}
locStor.prototype.get = function () {
try {
return JSON.parse(window.localStorage.getItem(arguments[0]));
} catch(e) {
return window.localStorage.getItem(arguments[0]);
}
}
locStor.prototype.isSet = function () {
var v = this.get(arguments[0]);
if (v !== null && typeof v !== 'undefined')
return true;
else
return false;
}
var storage = new locStor();
var options = function () {};
options.prototype.add = function (name, v) {
this[name] = {};
this[name].vDefault = v;
var keyName = 'options:' + name;
if (storage.isSet(keyName))
this[name].v = storage.get(keyName);
else {
this[name].v = v;
storage.set(keyName, v);
}
}
options.prototype.set = function (name, v) {
this[name].v = v;
storage.set('options:' + name, v);
return v;
}
options.prototype.save = function (name) {
storage.set('options:' + name, this[name].v);
}
var opt = new options();
var langList = ['en','es','ru'];
function pageBye() {
var c = document.getElementById('bye');
if (arguments[0] === false) {
document.body.style.overflowY = 'auto';
c.style.display = 'none';
} else {
document.body.style.overflowY = 'hidden';
c.style.display = 'flex';
c.style.top = window.pageYOffset + 'px';
c.style.height = window.innerHeight + 'px';
}
}
function pageLang() {
var i, j, c, l;
if (arguments.length > 0) {
l = opt.set('lang', arguments[0]);
} else {
if (opt.lang.v === 'auto') {
l = window.navigator.userLanguage || window.navigator.language || 'en';
if (langList.indexOf(l) === -1) {
if (langList.indexOf(l.split('-')[0]) > -1)
l = l.split('-')[0];
else
l = 'en';
}
} else
l = opt.lang.v;
}
var mc = [document.getElementById('mc'), document.getElementById('bye')];
for (var k = 0; k < mc.length; k++) {
c = mc[k].querySelectorAll('[lang="' + l + '"]');
if (c.length) {
for (j = 0; j < c.length; j++)
c[j].style.display = ((c[j].nodeName === 'A' || c[j].nodeName === 'SPAN') ? 'inline' : 'block');
for (i = 0; i < langList.length; i++)
if (langList[i] !== l) {
c = mc[k].querySelectorAll('[lang="' + langList[i] + '"]');
for (j = 0; j < c.length; j++)
c[j].style.display = 'none';
}
} else {
l = '';
for (i = 0; i < langList.length; i++) {
c = mc[k].querySelectorAll('[lang="' + langList[i] + '"]');
if (!l && c.length)
l = langList[i];
if (langList[i] === l)
for (j = 0; j < c.length; j++)
c[j].style.display = ((c[j].nodeName === 'A' || c[j].nodeName === 'SPAN') ? 'inline' : 'block');
else
for (j = 0; j < c.length; j++)
c[j].style.display = 'none';
}
}
}
}
function init() {
var i, j, c;
if (typeof window.matchMedia === 'function' && window.matchMedia('screen').matches)
for (i = 0; i < 40; i++)
if (!window.matchMedia('(min-resolution: ' + (96 + i * 24) + 'dpi)').matches) {
document.body.style['font-size'] = (1 + (i - 1) * 0.15) + 'em';
break;
}
c = document.getElementsByTagName('A');
for (i = 0; i < c.length; i++) {
if (c[i].href.length > 1 && (c[i].href.indexOf(document.domain) === -1
|| c[i].href.slice(0, 23) === 'https://github.com/slr/')) // FIXME temp
c[i].setAttribute('onclick', 'pageBye();');
}
opt.add('lang', 'auto');
var langSelect = document.getElementById('langSelect');
for (i = 0; i < langList.length; i++)
if (document.querySelector('[lang="' + langList[i] + '"]') !== null) {
c = document.createElement('A');
c.textContent = langList[i];
c.setAttribute('onclick', 'pageLang(\'' + langList[i] + '\');');
langSelect.appendChild(c);
}
var c = document.getElementById('mc'), ft = c.querySelector('article footer');
if (ft)
c = ft.parentNode;
else if (c.getElementsByTagName('article').length)
c = c.getElementsByTagName('article');
for (i = 0; i < langList.length; i++)
if (c.querySelector('[lang="' + langList[i] + '"]') === null)
c.insertBefore(document.getElementById('temp-no-lang').querySelector('[lang="' + langList[i] + '"]'), ft);
document.body.setAttribute('onpageshow', 'pageBye(false);');
document.body.style.display = 'block';
pageLang();
c = document.getElementsByClassName('img-ph');
for (i = 0; i < c.length; i++)
if ((j = c[i].getAttribute('data-src')) !== null) {
c[i].outerHTML = '<img src="' + j + '"'
+ ' alt="' + ((j = c[i].getAttribute('data-alt')) !== null ? j : '') + '"'
+ (j !== null ? ' title="' + j + '"' : '')
+ ' class="' + c[i].className.replace('img-ph', '').trim() + '"'
+ ' style="' + ((j = c[i].style.width) !== '' ? 'width:' + j + ';' : '')
+ ((j = c[i].style.height) !== '' ? 'height:' + j + ';' : '') + '" />';
i--;
}
c = document.getElementsByClassName('vid-ph');
for (i = 0; i < c.length; i++)
if ((j = c[i].getAttribute('data-src')) !== null) {
c[i].outerHTML = '<div class="vid ' + c[i].className.replace('vid-ph', '').trim() + '">'
+ '<iframe src="' + j + '"'
+ ((j = c[i].style.width) !== '' ? ' width="' + j + '"' : '')
+ ((j = c[i].style.height) !== '' ? ' height="' + j + '"' : '')
+ ' frameborder="0" allowfullscreen></iframe></div>';
i--;
}
}