Skip to content

Instantly share code, notes, and snippets.

@Petrivah
Created January 27, 2020 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Petrivah/3a6a2f66f6b5ff9b0ca9a8bfe8f9d1d7 to your computer and use it in GitHub Desktop.
Save Petrivah/3a6a2f66f6b5ff9b0ca9a8bfe8f9d1d7 to your computer and use it in GitHub Desktop.
BUGPOOL
// ==UserScript==
// @name BUGPOOL
// @namespace BUGPOOL
// @version 0.1
// @description Don't look at the errors, i'm shitcoder
// @author Wynell © BUGPOOL
// @match https://vk.com/*
// @grant none
// ==/UserScript==
(async function() {
'use strict';
const access_token = '8324d91c8324d91c8324d91c6c834a0494883248324d91cdd2e94c658bd68374bbce098';
const api_version = '5.103';
const fields = 'online,last_seen';
async function getUser(user_id) {
let request_uri = `https://api.vk.com/method/users.get?user_ids=${Array.isArray(user_id) ? user_id.join(',') : user_id}&fields=${fields}&access_token=${access_token}&v=${api_version}`;
let result = await fetch(request_uri);
let json = await result.json();
return json.response;
}
async function getOnlines(dialogs) {
let users = await getUser(dialogs);
let onlines = [];
for (let i of users) {
if (i.online) onlines.push(i.id);
}
return onlines;
}
function getDialogs() {
let dialogs = [];
let dialog_els = document.getElementsByClassName('nim-dialog');
for (let i of dialog_els) {
let peer = i.getAttribute('data-peer');
if (peer > 0 && peer < 2000000000) dialogs.push(peer);
}
return dialogs;
}
function getCurrent() {
return /\?sel=(\d+)/.exec(location.search)[1];
}
async function onlineCurrent() {
let current = getCurrent();
let online = await getOnlines(current);
return !!online[0];
}
function getProfile() {
return location.pathname.slice(1);
}
async function onlineProfile() {
let profile = getProfile();
let online = await getOnlines(profile);
return !!online[0];
}
function showOnlines(onlines) {
for (let i of onlines) {
document.querySelector(`[data-peer="${i}"] ._online`).className += " online";
}
}
async function updateAll() {
let dialogs = getDialogs();
let onlines = await getOnlines(dialogs);
showOnlines(onlines);
}
async function updateCurrent() {
let online = document.getElementsByClassName('_im_page_peer_online')[0];
if (await onlineCurrent()) online.innerHTML = 'Online';
else online.innerHTML = 'Offline';
}
async function updateProfile() {
let online = document.getElementsByClassName('profile_online_lv')[0];
if (await onlineProfile()) online.innerHTML = 'Online';
else online.innerHTML = 'Offline';
}
async function updateGalaxy() {
try {
updateAll();
} catch (e) {}
try {
updateCurrent();
} catch(e) {}
try {
updateProfile();
} catch(e) {}
}
setInterval(updateGalaxy, 1000);
// console.log(await getUser(31163092));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment