0%

BiugleJS

BiugleJS 前端武器库(持续更新)

biugleJS — CSS

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
/** 
autor: doubleam
introduction: biugle.css
**/
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
doubleam get 20191126
*/
/* 使用bootstrap的话,他默认使用了normalize.css,二者有些差别,不过你可以后引用bootstrap,也可以不引用此文件(reset.css) */
/* 推荐引入:
<script type="text/javascript" src="jquery/jquery.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="biugleJS/js/biugle.min.js"></script>
<link type="text/css" rel="stylesheet" href="biugleJS/css/biugle.min.css">
<link type="text/css" rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="fontawesome/css/fontawesome.min.css">
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}

/* biugle */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.biu-row{
display: flex;
flex-direction: row;
}
.biu-row-re{
display: flex;
flex-direction: row-reverse;
}
.biu-col{
display: flex;
flex-direction: column;
}
.biu-col-re{
display: flex;
flex-direction: column-reverse;
}
.biu-row-center{
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.biu-col-center{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.biu-jus-center{
justify-content: center;
}
.biu-jus-start{
justify-content: flex-start;
}
.biu-jus-end{
justify-content: flex-end;
}
.biu-jus-around{
justify-content: space-around;
}
.biu-jus-between{
justify-content: space-between;
}
.biu-jus-evenly{
justify-content: space-evenly;
}
.biu-items-center{
align-items: center;
}
.biu-items-start{
align-items: flex-start;
}
.biu-items-end{
align-items: flex-end;
}
.biu-items-baseline{
align-items: baseline;
}
.biu-items-stretch{
align-items: stretch;
}
.biu-content-center{
align-content: center;
}
.biu-content-start{
align-content: flex-start;
}
.biu-content-end{
align-content: flex-end;
}
.biu-content-around{
align-content: space-around;
}
.biu-content-between{
align-content: space-between;
}
.biu-content-evenly{
align-content: space-evenly;
}
.biu-content-stretch{
align-content: stretch;
}
.biu-wrap-no{
flex-wrap: nowrap;
}
.biu-wrap-yes{
flex-wrap: wrap;
}
.biu-wrap-re{
flex-wrap: wrap-reverse;
}

/* others */
.biu-img-360{
transition-property: all;
transition-duration: 1.35s;
}
.biu-img-360:hover{
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-transform: rotate(360deg);
transform: rotate(360deg);
}
.biu-img-666:hover{
transform: rotate(666turn);
transition-delay: 1s;
transition-property: all;
transition-duration: 59s;
transition-timing-function: cubic-bezier(.34,0,.84,1);
-moz-transition-timing-function: cubic-bezier(.34,0,.84,1);/* Firefox 4 */
-webkit-transition-timing-function: cubic-bezier(.34,0,.84,1);/* Safari 和 Chrome */
-o-transition-timing-function: cubic-bezier(.34,0,.84,1);/* Opera */
}
.biu-footer{
width: 100%;
display: block;
text-align: center;
position: fixed;
bottom: 0;
left: 0;
font-weight: bolder;
font-size: 1rem;
padding: 0.5%;
color: white;
background-color: rgba(0,0,0,0.15);
}
.biu-footer>span>a{
text-decoration: none;
}
.biu-footer>span>a:hover{
color: chocolate;
text-decoration: underline;
}
.biu-dialog{
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
background-color:rgba(0,0,0,0.3);
z-index: 999;
display: none;
}
#dark-theme-img{
width: 3vw;
height: 3vw;
position: fixed;
z-index: 999;
left: -1.5vw;
top: 0;
transition-duration: 0.6s;
}
#dark-theme-img:hover{
transform: rotate(360deg);
left: 0;
width: 3.5vw;
height: 3.5vw;
}
@media (max-width: 999px) {
#dark-theme-img {
display: none;
}
}
/* CHROME浏览器中自定义滚动条样式 */
/* 滚动条的宽度 */
::-webkit-scrollbar {
width:0.6vw;
height:0.6vw;
background-color:rgba(255,255,255,0.1);
}
/* ::-webkit-scrollbar-track-piece滚动条凹槽的颜色,还可以设置边框属性。 */
::-webkit-scrollbar-track {
-webkit-box-shadow:inset 0 0 0.6rem rgba(0,0,0,0.3);
background-color:#888;
}
::-webkit-scrollbar-track-piece{
background-color:#999;
}
/* 滚动小条的设置 */
::-webkit-scrollbar-thumb {
-webkit-box-shadow:inset 0 0 0.6rem rgba(0,0,0,.3);
background-color:#2f2f2f;
}
::-webkit-scrollbar-thumb:hover{
background-color:chocolate;
}
body{
cursor: url(./cursor/a/default.cur),default;
}
a:hover,button:hover,img:hover,code:hover,pre:hover,samp:hover,kbd:hover,menu:hover,nav:hover,footer:hover,ruby:hover,rp:hover,rt:hover,h1:hover,h2:hover,h3:hover,h4:hover,h5:hover{
cursor: url(./cursor/a/pointer.cur),pointer;
}

biugleJS — 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
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
/** 
autor: doubleam
introduction: biugle.js
**/

Date.prototype.format = function (fmt) {
let o = {
'M+': this.getMonth() + 1, //月份
'd+': this.getDate(), //日
'h+': this.getHours(), //小时
'm+': this.getMinutes(), //分
's+': this.getSeconds(), //秒
'q+': Math.floor((this.getMonth() + 3) / 3), //季度
'S': this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (let k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return fmt;
};

/**
* 伪夜间模式
*/
/*
* @type Number 遮罩指数
*/
var brightness = 0;
let div;
function cover(brightness) {
if (typeof (div) === 'undefined') {
div = document.createElement('div');
div.setAttribute('style', 'position:fixed;top:0;left:0;outline:50000px solid;z-index:99999;');
document.body.appendChild(div);
} else {
div.style.display = '';
}
div.style.outlineColor = 'rgba(0,0,0,' + brightness + ')';
}
window.addEventListener('keydown', function (e) {//事件监听
if (e.altKey && e.keyCode === 90) {//Alt+Z 关灯
cover(brightness = 0.3);
}
if (e.altKey && e.keyCode === 88) {//Alt+X 开灯
cover(brightness = 0);
}
if (e.altKey && e.keyCode === 38) {//Alt+↑ 亮度调高
if (brightness - 0.05 > 0.05) {
cover(brightness -= 0.05);
}
}
if (e.altKey && e.keyCode === 40) {//Alt+↓ 亮度调低
if (brightness + 0.05 < 0.95) {
cover(brightness += 0.05);
}
}
}, false);
let darkImg = document.querySelector("#dark-theme-img");
if (darkImg !== null) {
darkImg.setAttribute("title", "【Alt+↑/↓】调节亮度哦~");
darkImg.addEventListener('click', function () {
if (brightness === 0) {
cover(brightness = 0.3);
} else {
cover(brightness = 0);
}
});
}


/**
* ---------------BiugleJS Start---------------
*/
function Biugle() {
var _proto = Biugle.prototype;

/**
* 人性化时间(完美版)
* @param {date} date 时间
* @returns {String} 字串或者时间
*/
_proto.timeSince = (date) => {
if (!date) {
return;
}
let dateTS = new Date(date.replace(/-/g, '/'));
let seconds = Math.floor((new Date() - dateTS) / 1000);
let interval = Math.floor(seconds / 31536000);
interval = Math.floor(seconds / 2592000);
interval = Math.floor(seconds / 86400);
if (interval >= 4) {
return dateTS.format('yyyy-MM-dd hh:mm');
}
if (interval >= 1) {
return interval + " 天前";
}
interval = Math.floor(seconds / 3600);
if (interval >= 1) {
return interval + " 小时前";
}
interval = Math.floor(seconds / 60);
if (interval >= 1) {
return interval + " 分钟前";
}
return "刚刚";
};

/**
* 时间格式化
* @param {type} date 时间
* @returns {String} 格式化后的时间
*/
_proto.timeFormat = (date, formater = null) => {
if (!date) {
return;
}
let dateTS = new Date(date.replace(/-/g, '/'));
return dateTS.format(formater || 'yyyy-MM-dd hh:mm');
};

/**
* 当前时间
* @param {Number} type 1-2-3代表不同的格式
* @returns {String} 当前时间字串
*/
_proto.nowTime = (type = 1) => {
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
let hour = date.getHours();
let minute = date.getMinutes();
let second = date.getSeconds();
hour = (hour < 10) ? ("0" + hour) : hour;
minute = (minute < 10) ? ("0" + minute) : minute;
second = (second < 10) ? ("0" + second) : second;
if (type === 1) {
return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
}
if (type === 2) {
return year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second;
}
if (type === 3) {
return year + "年" + month + "月" + day + "日" + " " + hour + ":" + minute + ":" + second;
}
};

/**
* 过去某个点到现在过去的时间
* @param {date} date 过去的时间
* @returns {object} 天、时、分、秒及其内容
*/
_proto.date2Now = (date) => {
if (!date) {
return;
}
let now = new Date();
let run = new Date(date);
let runTime = (now - run) / 1000,
days = Math.floor(runTime / 60 / 60 / 24),
hours = Math.floor(runTime / 60 / 60 - (24 * days)),
minutes = Math.floor(runTime / 60 - (24 * 60 * days) - (60 * hours)),
seconds = Math.floor((now - run) / 1000 - (24 * 60 * 60 * days) - (60 * 60 * hours) - (60 * minutes));
if (String(hours).length === 1) {
hours = "0" + hours;
}
if (String(minutes).length === 1) {
minutes = "0" + minutes;
}
if (String(seconds).length === 1) {
seconds = "0" + seconds;
}
let runTimes = {"days": days, "hours": hours, "minutes": minutes, "seconds": seconds};
return runTimes;
};

/**
* 现在到未来某个点的剩余时间
* @param {date} date 截止日期
* @returns {object} 天、时、分、秒及其内容
*/
_proto.now2Date = (date) => {
if (!date) {
return;
}
let startDate = new Date();
let endDate = new Date(date);
let t = endDate.getTime() - startDate.getTime();
let d = 0,
h = 0,
m = 0,
s = 0;
if (t >= 0) {
d = Math.floor(t / 1000 / 3600 / 24);
h = Math.floor(t / 1000 / 60 / 60 % 24);
m = Math.floor(t / 1000 / 60 % 60);
s = Math.floor(t / 1000 % 60);
}
let hasTimes = {"days": d, "hours": h, "minutes": m, "seconds": s};
return hasTimes;
};

/**
* 控制台打印信息
* @param {String} siteName 网站名称
* @param {String} siteUrl 网站地址
* @param {String} email 联系邮箱
* @param {String} info 网站简介
*/
_proto.consoleInfo = (siteName = "biugle", siteUrl = "https://www.biugle.cn", email = "biugle@163.com", info = "hello biugle!") => {
console.log(`%c网站名称%c${siteName}`, "line-height:28px;padding:4px;background:#a1afc9;color:#000;font-size:16px;margin-right:15px", "color:#3fa9f5;line-height:28px;font-size:16px;");
console.log(`%c网站地址%c${siteUrl}`, "line-height:28px;padding:4px;background:#a1afc9;color:#000;font-size:16px;margin-right:15px", "color:#00bc12;line-height:28px;font-size:16px;");
console.log(`%c联系邮箱%c${email}`, "line-height:28px;padding:4px;background:#a1afc9;color:#000;font-size:16px;margin-right:15px", "color:#ff9900;line-height:28px;font-size:16px;");
console.log(`%c${info}`, "line-height:28px;padding:5px;color:#fff;font-weight:bolder;font-size:16px;background-color:chocolate;color:#fff;");
if (window.console && window.console.log) {
console.log(`%c页面加载消耗了 %c${(Math.round(100 * performance.now()) / 100 / 1e3).toFixed(2)}s`, "background:#fff;color:#333;text-shadow: 0 0 2px #eee, 0 0 3px #eee, 0 0 3px #eee, 0 0 2px #eee, 0 0 3px #eee;", "color:tomato;font-weight:bolder;");
localStorage.getItem("access") || localStorage.setItem("access", (new Date).getTime());
let e = new Date(parseInt(localStorage.getItem("access")));
let o = `${e.getFullYear()}${e.getMonth() + 1}${e.getDate()}日`;
let t = 0;
localStorage.getItem("hit") ? t = parseInt(localStorage.getItem("hit")) : localStorage.setItem("hit", 0);
localStorage.setItem("hit", ++t);
console.log(`%c这是你自 %c${o} %c以来第 %c${t} %c次在本站打开控制台,你想知道什么秘密吗~`, "", "color:chocolate;font-weight:bolder;", "", "color:chocolate;font-weight:bolder;", "");
}
};

/**
* 选项卡离开提示
* @param {String} leaveInfo 离开时显示内容
* @param {String} comeInfo 进入时显示内容
*/
_proto.setTitleStatus = (leaveInfo = " (╥﹏╥) 你快回来 ~ ", comeInfo = " (∩_∩) 欢迎回来 ~ ") => {
let OriginTitle = document.title;
let titleTime;
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'hidden') {
document.title = leaveInfo;
clearTimeout(titleTime);
} else {
document.title = comeInfo + OriginTitle;
titleTime = setTimeout(function () {
document.title = OriginTitle;
}, 1500);
}
});
};

/**
* 添加复制内容
* @param {String} content 内容来源、版权信息等。
*/
_proto.addCopyEvent = (content = "www.biugle.cn") => {
document.addEventListener('copy', function (event) {
var clipboardData = event.clipboardData || window.clipboardData;
if (!clipboardData) {
return;
}
var text = window.getSelection().toString();
if (text) {
event.preventDefault();
clipboardData.setData('text/plain', text + `\n\n\n${content}`);
}
});
};

/**
* 格式化字符串,转实体字符,去前后空格。
* @param {String} str 待格式化字符串
* @returns {String} 格式化后的字符串
*/
_proto.strFormat = (str) => {
str = str.toString().replace(/^\s+|\s+$/g, "");
let div = document.createElement('div');
div.textContent = str;
let formatString = div.innerHTML;
return formatString;
};

/**
* 去除空格
* @param {String} str 待去空格的字符串
* @param {Number} type 1:去前后空格,2:去前空格,3:去后空格,4:去所有空格
* @returns {String} 格式化后的字符串
*/
_proto.noSpace = (str, type = 1) => {
switch (type) {
case 1:
return str = str.toString().replace(/^\s+|\s+$/g, "");
case 2:
return str = str.toString().replace(/^\s/, '');
case 3:
return str = str.toString().replace(/(\s$)/g, "");
case 4:
return str = str.toString().replace(/\s+/g, "");
default:
return str;
}
};

/**
* 大小写转换
* @param {String} str 待转换的字符串
* @param {Number} type 1:全部大写,2:全部小写,3:首字母大写,4:首页母小写
* @returns {String} 转换后的字符串
*/
_proto.charSet = (str, type = 1) => {
switch (type) {
case 1:
return str.toString().toUpperCase();
case 2:
return str.toString().toLowerCase();
case 3:
return str.toString().replace(/^(\w)(\w+)/, function (v, v1, v2) {
return v1.toUpperCase() + v2.toLowerCase();
});
case 4:
return str.toString().replace(/^(\w)(\w+)/, function (v, v1, v2) {
return v1.toLowerCase() + v2.toUpperCase();
});
default:
return str;
}
};

/**
* 元素填充内容
* @param {String} key 选择器
* @param {type} value 值
*/
_proto.dataTo = (key, value) => {
key = document.querySelector(key.toString().replace(/_/g, '-'));
key.innerHTML = value;
key.value = value;
return this;
};

/**
* 转化字符串
* @param {String} str 待转化字符串
* @returns {String} 转化后字符串
*/
_proto.nl2br = (str) => {
let breakTag = '<br />';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '' + breakTag + '$2');
};

/**
* 格式化运算表达式(----------重复符号问题bug未解决----------)
* @param {String} text 格式化前表达式
* @returns {String} 格式化后的表达式
*/
_proto.formatExp = (text) => {
let reg = /[.0-9]/;
let tempText = "";
let numTemp = [];
let charTemp = [];
let len = text.length;
for (let i = 0, j = 0; i < len; i++) {
if (i === 0 && !reg.test(text[0])) {
numTemp[0] = "";
charTemp[0] = text[0];
j++;
} else if (i === 0 && reg.test(text[0]) && len === 1) {
numTemp[0] = text[i];
charTemp[0] = "";
} else if (i !== len - 1 && reg.test(text[i])) {
tempText += text[i];
} else if (i !== len - 1 && !reg.test(text[i])) {
numTemp[j] = parseFloat(tempText);
tempText = "";
charTemp[j] = text[i];
j++;
} else if (i === len - 1 && reg.test(text[len - 1]) && len > 1) {
tempText += text[i];
numTemp[j] = parseFloat(tempText);
numTemp[j + 1] = "";
tempText = "";
charTemp[j] = "";
} else if (i === len - 1 && !reg.test(text[len - 1]) && len > 1) {
numTemp[j] = parseFloat(tempText);
numTemp[j + 1] = "";
tempText = "";
charTemp[j] = text[i];
}
}
text = "";
let leng = charTemp.length;
for (let i = 0; i < leng; i++) {
if (leng > 1 && i === leng - 1) {
text += numTemp[i] + charTemp[i] + numTemp[i + 1];
} else {
text += numTemp[i] + charTemp[i];
}
}
text = String(text);
return text;
};

/**
* 取数组或者对象的第一个值
* @param {object/array} objOarray 数组或者对象
* @returns {type} 第一个值
*/
_proto.firstVal = (objOarray) => {
for (let key in objOarray) {
let result = objOarray[key];
return result;
}
};

/**
* 获取一定范围的随机数
* @param {Number} min 最小值
* @param {Number} max 最大值
* @returns {Number} 生成的随机数
*/
_proto.getRandNum = (min = 0, max = 10) => {
return Math.floor(min + Math.random() * (max - min + 1));
};

/**
* 随机生成颜色
* @returns {String} 随机生成的颜色
*/
_proto.getRandColor = () => {
return '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).slice(-6);
};

/**
* 插入某元素到指定Element之前
* @param {Element} newElement 某元素
* @param {Element} targetElement 指定元素
*/
_proto.insertAfter = (newElement, targetElement) => {
let parent = targetElement.parentNode;
if (parent.lastElementChild === targetElement) {
parent.appendChild(newElement);
} else {
parent.insertBefore(newElement, targetElement.nextElementSibling);
}
};

/**
* 设置cookie
* @param {String} name 存Cookie的变量名
* @param {type} value 变量的值
* @param {Number} days 有效期
*/
_proto.setCookie = (name, value, days) => {
days = days || 30; //没有设置有效期,默认有效期是30天
var exp = new Date(); //获取当前日期
exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000); //设置过期日期
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
};

/**
* 获取cookie
* @param {type} name 存Cookie的变量名
*/
_proto.getCookie = (name) => {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr === document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
};

/**
* 删除cookie
* @param {type} name 存Cookie的变量名
*/
_proto.delCookie = (name) => {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if (cval !== null)
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString() + ";path=/";
};

/**
* 获取浏览器类型和版本
* @returns {String} 浏览器类型和版本
*/
_proto.getExplore = () => {
let sys = {},
ua = navigator.userAgent.toLowerCase(),
s;
(s = ua.match(/rv:([\d.]+)\) like gecko/)) ? sys.ie = s[1] :
(s = ua.match(/msie ([\d\.]+)/)) ? sys.ie = s[1] :
(s = ua.match(/edge\/([\d\.]+)/)) ? sys.edge = s[1] :
(s = ua.match(/firefox\/([\d\.]+)/)) ? sys.firefox = s[1] :
(s = ua.match(/(?:opera|opr).([\d\.]+)/)) ? sys.opera = s[1] :
(s = ua.match(/chrome\/([\d\.]+)/)) ? sys.chrome = s[1] :
(s = ua.match(/version\/([\d\.]+).*safari/)) ? sys.safari = s[1] : 0;
// 根据关系进行判断
if (sys.ie) {
return ('IE: ' + sys.ie);
}
if (sys.edge) {
return ('EDGE: ' + sys.edge);
}
if (sys.firefox) {
return ('Firefox: ' + sys.firefox);
}
if (sys.chrome) {
return ('Chrome: ' + sys.chrome);
}
if (sys.opera) {
return ('Opera: ' + sys.opera);
}
if (sys.safari) {
return ('Safari: ' + sys.safari);
}
return 'UnkonwnExplore';
};

/**
* 获取操作系统类型
* @return {String} 操作系统类型
*/
_proto.getOS = () => {
let userAgent = 'navigator' in window && 'userAgent' in navigator && navigator.userAgent.toLowerCase() || '';
let vendor = 'navigator' in window && 'vendor' in navigator && navigator.vendor.toLowerCase() || '';
let appVersion = 'navigator' in window && 'appVersion' in navigator && navigator.appVersion.toLowerCase() || '';
if (/mac/i.test(appVersion)) {
return 'MacOSX';
}
if (/win/i.test(appVersion)) {
return 'Windows';
}
if (/linux/i.test(appVersion)) {
return 'Linux';
}
if (/iphone/i.test(userAgent) || /ipad/i.test(userAgent) || /ipod/i.test(userAgent)) {
return 'Ios';
}
if (/android/i.test(userAgent)) {
return 'Android';
}
if (/win/i.test(appVersion) && /phone/i.test(userAgent)) {
return 'WindowsPhone';
}
return 'UnknowOS';
};

/**
* 判断数组或者对象是否为空
* @param {type} obj 数组或者对象
* @returns {Boolean}
*/
_proto.isEmptyObject = (obj) => {
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
return false;
}
return !Object.keys(obj).length;
};

/**
* 判断是否为邮箱地址
* @param {String} str 邮箱地址
* @return {Boolean}
*/
_proto.isEmail = (str) => {
return /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(str);
};

/**
* 判断是否为身份证号
* @param {String|Number} str 身份证号
* @return {Boolean}
*/
_proto.isIdCard = (str) => {
return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(str);
};

/**
* 判断是否为手机号
* @param {String|Number} str 手机号
* @return {Boolean}
*/
_proto.isPhoneNum = (str) => {
return /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/.test(str);
};

/**
* 判断是否为URL地址
* @param {String} str URL地址
* @return {Boolean}
*/
_proto.isUrl = (str) => {
return /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i.test(str);
};

/**
* rmb现金额转大写
* @param {Number} n reb金额
* @return {String} 转化结果
*/
_proto.rmbUpper = (n) => {
let fraction = ['角', '分'];
let digit = [
'零', '壹', '贰', '叁', '肆',
'伍', '陆', '柒', '捌', '玖'
];
let unit = [
['元', '万', '亿'],
['', '拾', '佰', '仟']
];
let head = n < 0 ? '欠' : '';
n = Math.abs(n);
let s = '';
let fraLen = fraction.length;
for (let i = 0; i < fraLen; i++) {
s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
}
s = s || '整';
n = Math.floor(n);
for (let i = 0; i < unit[0].length && n > 0; i++) {
var p = '';
for (let j = 0; j < unit[1].length && n > 0; j++) {
p = digit[n % 10] + unit[1][j] + p;
n = Math.floor(n / 10);
}
s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
}
return head + s.replace(/(零.)*零元/, '元')
.replace(/(零.)+/g, '零')
.replace(/^整$/, '零元整');
};

/**
* ---------------BiugleJS End---------------
*/
}

/**
* 实体化BiugleJS----->$biu
*/
var $biu = new Biugle();

更多内容

bulb