Оцените код мини приложения
Задание: Создать приложение для ВКонтакте, которое загружает список ваших друзей и выводит их на страницу в следующем формате: Фото, ФИО, Возраст, Дата рождения.
Друзья должны быть отсортированы по дате рождения в порядке убывания. Из-за того, что, нельзя получить возраст на прямую, пришлось немного по извращаться. http://plnkr.co/edit/zTKjQMST0XDZSDkfpcev?p=preview <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> ul{ list-style: none; overflow: hidden; width: 700px; } li{ border-bottom: 1px solid; width: 100%; display: inline-block; margin-bottom: 20px; padding-bottom: 20px; } img{ float: left; } p{ margin-left: 120px; } img.parent:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; } </style> </head> <body id='body'> <script src="http://vk.com/js/api/openapi.js"></script> <script> function foo() { var ul = document.createElement('ul'); body.appendChild(ul) VK.init({ apiId: 5580872 }); VK.Auth.login(function(response){ if(response.session){ VK.api('friends.get', {'user_id' : '26291131', 'fields' : 'bdate, photo_100'}, response => { if(response.error){ alert(response.error.error_msg); } else{ let userData = response.response; var arrAge = []; var arrAge2 = []; var age = [] var now = new Date(); var god = now.getFullYear() var a = [] for(var h = 0; h < userData.length; h++){ if(typeof userData[h].bdate == 'string' && userData[h].bdate.split('.')[2]){ arrAge.push(userData[h].first_name + ' ' + userData[h].last_name + ' ' + (god - parseInt((userData[h].first_name + ' ' + userData[h].last_name + ' ' + userData[h].bdate.split('.')[2]).split(' ')[2]))) a.push((userData[h].bdate + ' ' + userData[h].photo_100).split(' ')) } } for(var c = 0; c < arrAge.length; c++){ arrAge2.push(arrAge[c].split(' ')) } arrAge2.sort(function(a, b){ return b[2] - a[2] }) for(var z = 0; z < a.length; z++){ a[z][0] = a[z][0].split('.') } a.sort(function(a, b){ return a[0][2] - b[0][2] }) for(var i = 0; i < arrAge2.length; i++){ //console.log(arrAge2[i][1] + ' ' + arrAge2[i][0] + ', ' + 'возраст ' + arrAge2[i][2] + ', дата рождения ' + a[i][0] + ' ' + a[i][1]) var li = document.createElement('li'); ul.appendChild(li) var img = document.createElement('img'); img.src=a[i][1] li.appendChild(img) var p = document.createElement('p') p.innerHTML = arrAge2[i][1] + ' ' + arrAge2[i][0] + ', ' + 'возраст ' + arrAge2[i][2] + '<br>' + ' Lата рождения ' + a[i][0] li.appendChild(p) } } }); } else{ alert('Не удалось авторизироваться') } }, 2); } foo() </script> </body> </html> |
DivMan,
http://passportjs.org/ |
Цитата:
|
Часовой пояс GMT +3, время: 15:27. |