Skip to content

Instantly share code, notes, and snippets.

@MaxXx1313
Last active April 4, 2021 14:41
Show Gist options
  • Save MaxXx1313/4b2a1ca73521e34a24505f266ff532b2 to your computer and use it in GitHub Desktop.
Save MaxXx1313/4b2a1ca73521e34a24505f266ff532b2 to your computer and use it in GitHub Desktop.
Remove promoted posts and ads on vk.com (tampermonkey script)
// ==UserScript==
// @name Remove VK ads
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Remove VK advertisement
// @author maxxx1313
// @match https://vk.com/*
// @grant none
// @runat document-end
// ==/UserScript==
(function() {
'use strict';
// remove left
var adsleft = document.getElementById('ads_left');
if(adsleft){
adsleft.remove();
}
watchElementByID('feed_rows');
watchElementByID('page_wall_posts');
function watchElementByID(id){
var el = document.getElementById(id);
if(!el) return;
// remove romoted posts
var m = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(mutation.type=='childList' /*&& mutation.target.className == '_feed_rows'*/){
// console.log(mutation);
removePromotedPosts(mutation.target);
}
});
});
m.observe(el, {childList:true, subtree:true});
removePromotedPosts(el);
}
function removePromotedPosts(node){
if(!node) return;
node.querySelectorAll('.feed_block_articles').forEach(function(e){
if (e){
e.closest('.feed_row').remove();
}
});
node.querySelectorAll('.post._ads_promoted_post_data_w').forEach(function(e){
if (e){
// e.closest('.post').remove();
e.remove();
}
});
node.querySelectorAll('.wall_marked_as_ads').forEach(function(e){
if (e){
e.closest('.post').remove();
}
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment