Advertisement
Vujin

Untitled

Oct 14th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  2. <script src="https://vk.com/js/api/openapi.js?159" type="text/javascript"></script>
  3. <script type="text/javascript">
  4. $(function(){
  5. // init your application
  6. VK.init({
  7. apiId: 6720736
  8. });
  9. // click to 'Акцио!'
  10. $('.groupBtn').on('click', function(e) {
  11. e.preventDefault();
  12.  
  13. $('.result').hide();
  14.  
  15. const regex = /^(.*?\/)+(.*)$/;
  16. const str = $('.groupInput').val();
  17.  
  18. let m;
  19. let groupId;
  20.  
  21. if ((m = regex.exec(str)) !== null) {
  22. // the result can be accessed through the `m`-variable.
  23. const strId = m[2][0] + m[2][1];
  24. groupId = (strId == 'id') ? m[2].split('id')[1] : m[2];
  25. // request to callback vk.api
  26. VK.Api.call('groups.getById', {access_token: '137ef0e7137ef0e7137ef0e7ca13187c071137e137ef0e748bddfc5c5ae612adf3b5243', group_id: groupId, fields: 'members_count', v: 5.85}, function(r) {
  27. if(r.response) {
  28. $('.groupName').text(r.response[0].name);
  29. $('.groupAvatar').text(r.response[0].photo_200);
  30. $('.groupMembers').text(r.response[0].members_count);
  31. $('.result').show();
  32. }
  33. });
  34. } else {
  35. // error display
  36. }
  37. });
  38. });
  39. </script>
  40. <input type="text" class="groupInput" placeholder="https://vk.com/testpool"><button class="groupBtn">Акцио!</button>
  41. <div class="result" style="display: none;">
  42. <ul>
  43. <li><b>Название</b>: <span class="groupName"></span></li>
  44. <li><b>Аватар</b>: <span class="groupAvatar"></span></li>
  45. <li><b>Кол-во участников</b>: <span class="groupMembers"></span></li>
  46. </ul>
  47. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement