-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
307 lines (307 loc) · 9.9 KB
/
Copy pathapp.js
File metadata and controls
307 lines (307 loc) · 9.9 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
"use strict";
// // WRAPPER
// function textFilter(node: Node) {
// if (
// [
// 'p',
// 'span',
// 'label',
// 'a',
// 'h1',
// 'h2',
// 'h3',
// 'h4',
// 'h5',
// 'h6',
// 'td',
// 'li',
// 'section',
// 'div',
// 'input',
// 'button',
// 'label',
// 'b',
// 'strong',
// 'em',
// 'pre',
// 'footer',
// 'cite',
// 'time',
// 'abbr',
// 'del',
// 'sub',
// 'dd',
// 'dt',
// 'legend',
// 'q',
// 'mark',
// 'samp',
// 'ins',
// 'var',
// 'i',
// 'dfn',
// 'code'
// ].includes(node.parentElement!.localName)
// ) {
// return NodeFilter.FILTER_ACCEPT;
// } else {
// return NodeFilter.FILTER_SKIP;
// }
// }
// function getTextNodes(): Node[] {
// var walk = document.createTreeWalker(
// document.body,
// NodeFilter.SHOW_TEXT,
// { acceptNode: textFilter },
// true
// );
// var n,
// a = [];
// while ((n = walk.nextNode())) a.push(n);
// return a;
// }
// function shouldWrap(className: string) {
// return document.getElementsByClassName(className).length === 0;
// }
// function wrapCharacters(className: string): Promise<string> {
// return new Promise((resolve, reject) => {
// // Get all text nodes in DOM
// let textNodes = getTextNodes();
// for (let textNode of textNodes) {
// // Split node up into individual letters
// let text = textNode.textContent;
// let textArray = text?.split('');
// // Generate the new element for each letter.
// textArray?.map((char: string) => {
// const elemChar = document.createElement('span');
// const isEmptySpace = char === ' ' || char === '\n';
// elemChar.textContent = char;
// if (!isEmptySpace) {
// elemChar.setAttribute('class', className);
// }
// textNode.parentNode?.insertBefore(elemChar, textNode);
// return elemChar;
// });
// textNode.parentNode?.removeChild(textNode);
// }
// resolve(className);
// });
// }
// function deployWrapperFunction(
// className: string,
// wrapperFunc: (el: HTMLSpanElement) => any
// ) {
// const elems = document.getElementsByClassName(className);
// for (let index = 0; index < elems.length; index++) {
// const element = elems[index] as HTMLSpanElement;
// wrapperFunc(element);
// }
// }
// // RANSOMIFY
// const hex2Rgb = function (hex: string) {
// const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
// return result
// ? {
// r: parseInt(result[1], 16),
// g: parseInt(result[2], 16),
// b: parseInt(result[3], 16)
// }
// : { r: 0, g: 0, b: 0 };
// };
// function luminance(r: number, g: number, b: number) {
// const a = [r, g, b].map(function (v) {
// v /= 255;
// return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
// });
// return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
// }
// function contrast(
// rgb1: { r: number; g: number; b: number },
// rgb2: { r: number; g: number; b: number }
// ) {
// const lum1 = luminance(rgb1.r, rgb1.g, rgb1.b);
// const lum2 = luminance(rgb2.r, rgb2.g, rgb2.b);
// const brightest = Math.max(lum1, lum2);
// const darkest = Math.min(lum1, lum2);
// return (brightest + 0.05) / (darkest + 0.05);
// }
// function setFontColors(elemChar: HTMLSpanElement) {
// let fontColor = randomColorGen();
// let fontBackgroundColor = randomColorGen();
// while (contrast(hex2Rgb(fontColor), hex2Rgb(fontBackgroundColor)) < 6) {
// fontColor = randomColorGen();
// fontBackgroundColor = randomColorGen();
// }
// elemChar.style.setProperty('color', fontColor);
// elemChar.style.setProperty('background-color', fontBackgroundColor);
// }
// function getRandomFromArray(array: string[]) {
// return array[Math.floor(Math.random() * array.length)];
// }
// function randomPixelSizeGen(multiplier: number, sizeFloor: number) {
// const randomNum = Math.floor(Math.random() * multiplier);
// return randomNum > sizeFloor
// ? randomNum.toString() + 'px'
// : sizeFloor.toString() + 'px';
// }
// function randomColorGen() {
// const colorArray = [
// '#ffaf12',
// '#34558b',
// '#4ec5a5',
// '#565d47',
// '#798fa8',
// '#fd823e',
// '#117893',
// '#f0daa4',
// '#eaac9d',
// '#a2553a',
// '#72617d',
// '#b49c73',
// '#3b3d4b',
// '#eff0f1',
// '#a09d9c'
// ];
// return getRandomFromArray(colorArray);
// }
// function randomFontCapitalizationGen() {
// return Math.round(Math.random()) === 1 ? 'uppercase' : 'lowercase';
// }
// function randomFontGen() {
// const fonts = [
// 'Agency FB',
// 'Albertina',
// 'Antiqua',
// 'Architect',
// 'Arial',
// 'BankFuturistic',
// 'BankGothic',
// 'Blackletter',
// 'Blagovest',
// 'Calibri',
// 'Comic Sans MS',
// 'Consolas',
// 'Courier',
// 'Cursive',
// 'Decorative',
// 'Fantasy',
// 'Fraktur',
// 'Frosty',
// 'Garamond',
// 'Georgia',
// 'Helvetica',
// 'Impact',
// 'Minion',
// 'Modern',
// 'Monospace',
// 'Open Sans',
// 'Palatino',
// 'Perpetua',
// 'Roman',
// 'Sans-serif',
// 'Serif',
// 'Script',
// 'Swiss',
// 'Tahoma',
// 'Times',
// 'Times New Roman',
// 'Tw Cen MT',
// 'Verdana'
// ];
// return getRandomFromArray(fonts);
// }
// function randomRotationGen(): string {
// return `rotate(${Math.random() * 4 - Math.random() * 4}deg)`;
// }
// function ransomify(spanEl: HTMLSpanElement) {
// setFontColors(spanEl);
// spanEl.style.setProperty('font-family', randomFontGen());
// spanEl.style.setProperty('text-transform', randomFontCapitalizationGen());
// spanEl.style.setProperty('top', randomPixelSizeGen(3, 1));
// spanEl.style.setProperty('left', randomPixelSizeGen(3, 1));
// spanEl.style.setProperty('right', randomPixelSizeGen(3, 1));
// spanEl.style.setProperty('bottom', randomPixelSizeGen(3, 1));
// spanEl.style.setProperty('font-size', randomPixelSizeGen(20, 15));
// spanEl.style.setProperty('transform', randomRotationGen());
// spanEl.style.setProperty('display', 'inline-block');
// spanEl.style.setProperty('padding', '0 1px;');
// spanEl.style.setProperty('box-shadow', '0px 1px 0px 0px #0000003');
// }
// async function ransomifyAll(className: string) {
// if (shouldWrap(className)) {
// await wrapCharacters(className);
// deployWrapperFunction(className, ransomify);
// } else {
// deployWrapperFunction(className, ransomify);
// }
// }
// // SLOWLY LOSE IT
// function getRandomDistance(): number {
// const factor = 4;
// let num = Math.random() * factor;
// num *= Math.floor(Math.random() * 2) === 1 ? 1 : -1;
// return num;
// }
// function moveRandomly(el: HTMLElement) {
// const directions = ['top', 'left'];
// for (const prop of directions) {
// const pos = el.style[prop as any];
// const pos_ =
// parseInt(pos.substr(0, pos.length - 2)) + getRandomDistance();
// el.style.setProperty(prop, `${pos_}px`);
// }
// }
// function genRandomMoves(className: string) {
// const elems = document.getElementsByClassName(className);
// window.setInterval(function () {
// const el = elems[
// Math.floor(Math.random() * elems.length)
// ] as HTMLElement;
// moveRandomly(el);
// console.log('Moved element');
// console.log(el.style.getPropertyValue('top') === '');
// }, 5);
// }
// function slowlyLoseIt(spanEl: HTMLSpanElement) {
// spanEl.style.setProperty('position', 'relative');
// spanEl.style.setProperty('top', '0px');
// spanEl.style.setProperty('left', '0px');
// }
// async function slowlyLoseItAll(className: string) {
// if (shouldWrap(className)) {
// await wrapCharacters(className);
// deployWrapperFunction(className, slowlyLoseIt);
// genRandomMoves(className);
// } else {
// deployWrapperFunction(className, slowlyLoseIt);
// genRandomMoves(className);
// }
// }
// // SOLAR FLARES
// function selectForFlare(className: string) {
// const elems = document.getElementsByClassName(className);
// window.setInterval(function () {
// const el = elems[
// Math.floor(Math.random() * elems.length)
// ] as HTMLElement;
// solarFlare(el);
// }, 1000);
// }
// function solarFlare(spanEl: HTMLSpanElement) {
// spanEl.style.setProperty('transition', 'box-shadow 1s');
// spanEl.style.setProperty('box-shadow', '0 0 1000px 500px yellow');
// window.setTimeout(function () {
// spanEl.style.setProperty('box-shadow', 'none');
// }, 1000);
// }
// async function solarFlareAll(className: string) {
// if (shouldWrap(className)) {
// await wrapCharacters(className);
// selectForFlare(className);
// } else {
// selectForFlare(className);
// }
// }
// // ransomifyAll('all-chars');
// // slowlyLoseItAll('all-chars');
// // solarFlareAll('all-chars');