Skip to content

Instantly share code, notes, and snippets.

@Artalus
Last active October 25, 2018 12:08
Show Gist options
  • Save Artalus/3d71a6e294bac15bebc221622f495224 to your computer and use it in GitHub Desktop.
Save Artalus/3d71a6e294bac15bebc221622f495224 to your computer and use it in GitHub Desktop.
A Tampermonkey / Greasemonkey script to hide commentaries (replies) to posts in a specific VKontakte public.
// ==UserScript==
// @name VK hide replies
// @namespace artalus
// @version 1.0
// @description Hide all replies for a specified public
// @author Artalus
// @match https://vk.com/*
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// ==/UserScript==
(function() {
'use strict';
const PUBLICS = ['dayzstandalone']; // hide posts from publics whose id contains one of those keywords
const DONT_HIDE = ['45608811_587703']; // don't hide posts with those ids
function isActuallyPost(x) {
// to use 'div._post_content' and ignore 'div.reply_wrap._reply_content._post_content.clear_fix'
return x.getAttribute('class') === '_post_content';
}
function shouldHide(x) {
let post_id = x.getElementsByClassName('post_link')[0].href;
if (DONT_HIDE.some(d => post_id.includes(d))) {
return false;
}
let public_id = x.getElementsByClassName('post_image')[0].href;
return PUBLICS.some(p => public_id.includes(p));
}
function getReplies(x) {
return Array.from(x.getElementsByClassName('replies'));
}
function remove(x) {
if (x)
x.parentNode.removeChild(x)
}
function killItWithFire(posts) {
Array.from(posts)
.filter(isActuallyPost)
.filter(shouldHide)
.flatMap(getReplies)
.forEach(remove);
}
waitForKeyElements("._post_content", killItWithFire);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment