Skip to content

Instantly share code, notes, and snippets.

@mraliscoder
Created June 17, 2022 04:44
Show Gist options
  • Save mraliscoder/637910fce32df191cd0035719ff541e6 to your computer and use it in GitHub Desktop.
Save mraliscoder/637910fce32df191cd0035719ff541e6 to your computer and use it in GitHub Desktop.
Script for adding someone's audio to one playlist (VK)
/*
1. Open VK page like https://vk.com/audios<ID>
2. Scroll down to load all music
3. Press F12
4. Paste this code to Console
5. Press Enter
6. Wait.
Do not interact with tab!!
Tested on Google Chrome
*/
const sleep = ms => new Promise(r => setTimeout(r, ms));
const time = ((500 * 5) + 100) / 1000;
let failed = 0;
(async function() {
let audios = document.querySelectorAll(".audio_page__audio_rows_list > *");
for (let i = 0; i < audios.length; i++) {
let audio = audios[i];
console.clear();
console.log("Processing: " + audio.querySelector(".audio_row__title_inner").innerText + " (" + (i + 1) + "/" + audios.length + ")");
console.log("Work done: " + Math.floor((i * 100) / audios.length) + "%");
let audioLeft = audios.length - i;
let timeLeft = audioLeft * time;
let hour = Math.floor(timeLeft / 3600)
let min = Math.floor((timeLeft - hour * 3600) / 60)
let sec = Math.floor(timeLeft - hour * 3600 - min * 60)
console.log("Estimated time: " + (hour > 0 ? hour + " h, " : "") + (min > 0 ? min + " m, " : "") + sec + " s.");
if (failed > 0) console.log("Failed: " + failed);
// Show buttons
audio.onmouseover();
audio.scrollIntoView(false);
await sleep(500);
// Click on "More" button
let audioMoreElement = audio.querySelector(".audio_row__action_more");
if (audioMoreElement !== null) {
audioMoreElement.click();
try {
// Click on "Add to playlist" to show all playlists
let actions = document.querySelector(".audio_row__more_action_add_to_playlist");
await sleep(500);
actions.click();
await sleep(500);
// Click on the first playlist in the list to add audio in it
let playlistbutton = document.querySelectorAll(".audio_row__action_playlist");
playlistbutton[1].click();
await sleep(500);
// Remove "More" menu
let tmp = document.querySelector("._audio_row__tt");
tmp.parentNode.removeChild(tmp);
// For some reasons :)
await sleep(500);
} catch(e) {
failed = failed + 1;
}
} else {
failed = failed + 1;
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment