|
1 |
| - |
2 | 1 | function getLocalTime(nS) {
|
3 | 2 | return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
|
4 | 3 | }
|
5 |
| - function getbbdata(){ |
6 |
| - var bbsurl = "https://daodao-three.vercel.app/api?q=10" |
| 4 | +function getdddata(){ |
| 5 | + var bbsurl = "https://daodao-three.vercel.app/api?q=10" |
7 | 6 |
|
8 |
| - var httpRequest = new XMLHttpRequest();//第一步:建立所需的对象 |
9 |
| - httpRequest.open('GET', bbsurl, true);//第二步:打开连接 将请求参数写在url中 ps:"./Ptest.php?name=test&nameone=testone" |
10 |
| - httpRequest.send();//第三步:发送请求 将请求参数写在URL中 |
11 |
| - /** |
12 |
| - * 获取数据后的处理程序 |
13 |
| - */ |
14 |
| - httpRequest.onreadystatechange = function () { |
15 |
| - if (httpRequest.readyState == 4 && httpRequest.status == 200) { |
16 |
| - var json = httpRequest.responseText;//获取到json字符串,还需解析 |
17 |
| - var obj = eval('(' + json + ')'); |
18 |
| - // console.log(obj.data) |
19 |
| - const bbArray = obj.map(e => { |
20 |
| - return { |
21 |
| - 'date': getLocalTime(e.date.$date), |
22 |
| - 'content': e.content, |
23 |
| - 'from': e.from |
24 |
| - } |
25 |
| - }) |
26 |
| - const data = JSON.stringify(bbArray); |
27 |
| - generateBBHtml(JSON.parse(data)) |
28 |
| - } |
29 |
| - }; |
30 |
| - } |
| 7 | + var httpRequest = new XMLHttpRequest();//第一步:建立所需的对象 |
| 8 | + httpRequest.open('GET', bbsurl, true);//第二步:打开连接 将请求参数写在url中 ps:"./Ptest.php?name=test&nameone=testone" |
| 9 | + httpRequest.send();//第三步:发送请求 将请求参数写在URL中 |
| 10 | + /** |
| 11 | + * 获取数据后的处理程序 |
| 12 | + */ |
| 13 | + httpRequest.onreadystatechange = function () { |
| 14 | + if (httpRequest.readyState == 4 && httpRequest.status == 200) { |
| 15 | + var json = httpRequest.responseText;//获取到json字符串,还需解析 |
| 16 | + var obj = eval('(' + json + ')'); |
| 17 | + // console.log(obj.data) |
| 18 | + const bbArray = obj.map(e => { |
| 19 | + return { |
| 20 | + 'date': getLocalTime(e.date.$date), |
| 21 | + 'content': e.content, |
| 22 | + 'from': e.from |
| 23 | + } |
| 24 | + }) |
| 25 | + const data = JSON.stringify(bbArray); |
| 26 | + generateddHtml(JSON.parse(data)) |
| 27 | + } |
| 28 | + }; |
| 29 | +} |
31 | 30 |
|
32 |
| - var generateBBHtml = array => { |
33 |
| - var $dom = document.querySelector('#bber'); |
34 |
| - var result = '<section class="timeline page-1"><ul><div class="list">' |
35 |
| - console.log(array) |
| 31 | +var generateddHtml = array => { |
| 32 | + var $dom = document.querySelector('#bber'); |
| 33 | + var result = '<section class="timeline page-1"><ul><div class="list">' |
| 34 | + console.log(array) |
36 | 35 |
|
37 |
| - if (array.length) { |
38 |
| - for (let i = 0; i < array.length; i++) { |
39 |
| - var from_icon = ''; |
40 |
| - if (array[i].from == "iPhone"){ |
41 |
| - from_icon = '<i class="fas fa-mobile-alt"></i>'; |
42 |
| - }else if (array[i].from == "MacBook"){ |
43 |
| - from_icon = '<i class="fas fa-laptop"></i>'; |
44 |
| - }else if (array[i].from == "微信公众号"){ |
45 |
| - from_icon = '<i class="fab fa-weixin" style="font-size: 0.6rem"></i>'; |
46 |
| - }else{ |
47 |
| - from_icon = '<i class="fas fa-tools"></i>'; |
48 |
| - }; |
| 36 | + if (array.length) { |
| 37 | + for (let i = 0; i < array.length; i++) { |
| 38 | + var from_icon = ''; |
| 39 | + if (array[i].from == "iPhone"){ |
| 40 | + from_icon = '<i class="fas fa-mobile-alt"></i>'; |
| 41 | + }else if (array[i].from == "MacBook"){ |
| 42 | + from_icon = '<i class="fas fa-laptop"></i>'; |
| 43 | + }else if (array[i].from == "微信公众号"){ |
| 44 | + from_icon = '<i class="fab fa-weixin" style="font-size: 0.6rem"></i>'; |
| 45 | + }else{ |
| 46 | + from_icon = '<i class="fas fa-tools"></i>'; |
| 47 | + }; |
49 | 48 |
|
50 |
| - var dataTime = '<p class="datatime">'+array[i].date+'</p>' |
| 49 | + var dataTime = '<p class="datatime">'+array[i].date+'</p>' |
51 | 50 |
|
52 | 51 |
|
53 |
| - result += `<li class="item"><div>`+ dataTime + `<p class="datacont">`+ array[i].content +`</p><p class="datafrom"><small>`+ from_icon + decodeURIComponent(array[i].from) +`</small></p></div></li>`; |
54 |
| - } |
55 |
| - } else { |
56 |
| - result += '!{_p("aside.card_funds.zero")}'; |
| 52 | + result += `<li class="item"><div>`+ dataTime + `<p class="datacont">`+ array[i].content +`</p><p class="datafrom"><small>`+ from_icon + decodeURIComponent(array[i].from) +`</small></p></div></li>`; |
57 | 53 | }
|
58 |
| - result += '</div></ul></section>' |
59 |
| - |
60 |
| - var $dom = document.querySelector('#bber'); |
61 |
| - $dom.innerHTML = result; |
62 |
| - window.lazyLoadInstance && window.lazyLoadInstance.update(); |
63 |
| - window.pjax && window.pjax.refresh($dom); |
| 54 | + } else { |
| 55 | + result += '!{_p("aside.card_funds.zero")}'; |
64 | 56 | }
|
| 57 | + result += '</div></ul></section>' |
65 | 58 |
|
66 |
| - if (document.querySelector('#bber')) { |
67 |
| - getbbdata() |
68 |
| - } |
| 59 | + var $dom = document.querySelector('#bber'); |
| 60 | + $dom.innerHTML = result; |
| 61 | + window.lazyLoadInstance && window.lazyLoadInstance.update(); |
| 62 | + window.pjax && window.pjax.refresh($dom); |
| 63 | +} |
69 | 64 |
|
70 |
| - function urlToLink(str) { |
71 |
| - var re =/\bhttps?:\/\/(?!\S+(?:jpe?g|png|bmp|gif|webp|gif))\S+/g; |
72 |
| - var re_forpic =/\bhttps?:[^:<>"]*\/([^:<>"]*)(\.(jpeg)|(png)|(jpg)|(webp))/g; |
73 |
| - str =str.replace(re_forpic,function (imgurl) { |
74 |
| - return '<a href="' + imgurl + '"><img src="' + imgurl + '" /></a>'; |
75 |
| - }); |
76 |
| - str =str.replace(re,function (website) { |
77 |
| - return " <a href='" + website + "'rel='noopener' target='_blank'>↘链接↙</a> "; |
78 |
| - }); |
79 |
| - str = qqWechatEmotionParser(str) |
80 |
| - return str; |
81 |
| - } |
82 |
| - /* |
83 |
| - MIT License - http://www.opensource.org/licenses/mit-license.php |
84 |
| - For usage and examples, visit: |
85 |
| - https://tokinx.github.io/lately/ |
86 |
| - Copyright (c) 2017, Biji.IO |
87 |
| - */ |
88 |
| - var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(b){var g=0;return function(){return g<b.length?{done:!1,value:b[g++]}:{done:!0}}};$jscomp.arrayIterator=function(b){return{next:$jscomp.arrayIteratorImpl(b)}};$jscomp.makeIterator=function(b){var g="undefined"!=typeof Symbol&&Symbol.iterator&&b[Symbol.iterator];return g?g.call(b):$jscomp.arrayIterator(b)}; |
89 |
| - (function(b,g){var p=function(h){var d=h.lang||{second:"\u79d2",minute:"\u5206\u949f",hour:"\u5c0f\u65f6",day:"\u5929",month:"\u4e2a\u6708",year:"\u5e74",ago:"\u524d",error:"NaN"};h=$jscomp.makeIterator(document.querySelectorAll(h.target||".time"));for(var c=h.next();!c.done;c=h.next()){c=c.value;var a=c.dateTime;var e=c.title,f=c.innerHTML;if(!a||isNaN(new Date(a=a.replace(/(.*)[a-z](.*)\+(.*)/gi,"$1 $2").replace(/-/g,"/"))))if(e&&!isNaN(new Date(e=e.replace(/-/g,"/"))))a=e;else if(f&&!isNaN(new Date(f= |
90 |
| - f.replace(/-/g,"/"))))a=f;else break;c.title=a;a=new Date(a);a=((new Date).getTime()-a.getTime())/1E3;e=a/60;f=e/60;var k=f/24,l=k/30,m=l/12;c.innerHTML=(1<=m?Math.floor(m)+d.year:1<=l?Math.floor(l)+d.month:1<=k?Math.floor(k)+d.day:1<=f?Math.floor(f)+d.hour:1<=e?Math.floor(e)+d.minute:1<=a?Math.floor(a)+d.second:d.error)+d.ago}};var n=function(){return this||(0,eval)("this")}();"Lately"in n||(n.Lately=p)})(); |
| 65 | +if (document.querySelector('#bber')) { |
| 66 | + getdddata() |
| 67 | +} |
| 68 | + |
| 69 | +function urlToLink(str) { |
| 70 | + var re =/\bhttps?:\/\/(?!\S+(?:jpe?g|png|bmp|gif|webp|gif))\S+/g; |
| 71 | + var re_forpic =/\bhttps?:[^:<>"]*\/([^:<>"]*)(\.(jpeg)|(png)|(jpg)|(webp))/g; |
| 72 | + str =str.replace(re_forpic,function (imgurl) { |
| 73 | + return '<a href="' + imgurl + '"><img src="' + imgurl + '" /></a>'; |
| 74 | + }); |
| 75 | + str =str.replace(re,function (website) { |
| 76 | + return " <a href='" + website + "'rel='noopener' target='_blank'>↘链接↙</a> "; |
| 77 | + }); |
| 78 | + str = qqWechatEmotionParser(str) |
| 79 | + return str; |
| 80 | +} |
| 81 | +/* |
| 82 | +MIT License - http://www.opensource.org/licenses/mit-license.php |
| 83 | +For usage and examples, visit: |
| 84 | +https://tokinx.github.io/lately/ |
| 85 | +Copyright (c) 2017, Biji.IO |
| 86 | +*/ |
| 87 | +var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(b){var g=0;return function(){return g<b.length?{done:!1,value:b[g++]}:{done:!0}}};$jscomp.arrayIterator=function(b){return{next:$jscomp.arrayIteratorImpl(b)}};$jscomp.makeIterator=function(b){var g="undefined"!=typeof Symbol&&Symbol.iterator&&b[Symbol.iterator];return g?g.call(b):$jscomp.arrayIterator(b)}; |
| 88 | +(function(b,g){var p=function(h){var d=h.lang||{second:"\u79d2",minute:"\u5206\u949f",hour:"\u5c0f\u65f6",day:"\u5929",month:"\u4e2a\u6708",year:"\u5e74",ago:"\u524d",error:"NaN"};h=$jscomp.makeIterator(document.querySelectorAll(h.target||".time"));for(var c=h.next();!c.done;c=h.next()){c=c.value;var a=c.dateTime;var e=c.title,f=c.innerHTML;if(!a||isNaN(new Date(a=a.replace(/(.*)[a-z](.*)\+(.*)/gi,"$1 $2").replace(/-/g,"/"))))if(e&&!isNaN(new Date(e=e.replace(/-/g,"/"))))a=e;else if(f&&!isNaN(new Date(f= |
| 89 | + f.replace(/-/g,"/"))))a=f;else break;c.title=a;a=new Date(a);a=((new Date).getTime()-a.getTime())/1E3;e=a/60;f=e/60;var k=f/24,l=k/30,m=l/12;c.innerHTML=(1<=m?Math.floor(m)+d.year:1<=l?Math.floor(l)+d.month:1<=k?Math.floor(k)+d.day:1<=f?Math.floor(f)+d.hour:1<=e?Math.floor(e)+d.minute:1<=a?Math.floor(a)+d.second:d.error)+d.ago}};var n=function(){return this||(0,eval)("this")}();"Lately"in n||(n.Lately=p)})(); |
0 commit comments