Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
- <script src="https://vk.com/js/api/openapi.js?159" type="text/javascript"></script>
- <script type="text/javascript">
- $(function(){
- // init your application
- VK.init({
- apiId: 6720736
- });
- // click to 'Акцио!'
- $('.groupBtn').on('click', function(e) {
- e.preventDefault();
- $('.result').hide();
- const regex = /^(.*?\/)+(.*)$/;
- const str = $('.groupInput').val();
- let m;
- let groupId;
- if ((m = regex.exec(str)) !== null) {
- // the result can be accessed through the `m`-variable.
- const strId = m[2][0] + m[2][1];
- groupId = (strId == 'id') ? m[2].split('id')[1] : m[2];
- // request to callback vk.api
- VK.Api.call('groups.getById', {access_token: '137ef0e7137ef0e7137ef0e7ca13187c071137e137ef0e748bddfc5c5ae612adf3b5243', group_id: groupId, fields: 'members_count', v: 5.85}, function(r) {
- if(r.response) {
- $('.groupName').text(r.response[0].name);
- $('.groupAvatar').text(r.response[0].photo_200);
- $('.groupMembers').text(r.response[0].members_count);
- $('.result').show();
- }
- });
- } else {
- // error display
- }
- });
- });
- </script>
- <input type="text" class="groupInput" placeholder="https://vk.com/testpool"><button class="groupBtn">Акцио!</button>
- <div class="result" style="display: none;">
- <ul>
- <li><b>Название</b>: <span class="groupName"></span></li>
- <li><b>Аватар</b>: <span class="groupAvatar"></span></li>
- <li><b>Кол-во участников</b>: <span class="groupMembers"></span></li>
- </ul>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement