VK Infinite Scroll Cleaner

Clear old part of posts after loading new one. Helps with memory problems on low spec PCs.

  1. // ==UserScript==
  2. // @name VK Infinite Scroll Cleaner
  3. // @name:ru VK Infinite Scroll Cleaner
  4. // @namespace http://vk.com
  5. // @version 0.1.2b
  6. // @description Clear old part of posts after loading new one. Helps with memory problems on low spec PCs.
  7. // @description:ru Удаляет старые посты при загрузке новых. Помогает с потреблением ОЗУ на слабых ПК.
  8. // @author 7KiLL
  9. // @match *://vk.com/*
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. var wall; //Posts selectors
  16. var count; //Number of posts
  17. //Number of posts is higher than actual by 2. Simple thing, but improves UX as well.
  18. //Favorites - 19/page
  19. //Feed - 11/page
  20. if(/fave/i.test(location.href)) {
  21. console.log('Fav detected');
  22. count = 21;
  23. wall = '.wall_posts.all ._post';
  24. }
  25. if(/feed/i.test(location.href)) {
  26. console.log('feed detected');
  27. count = 13;
  28. wall = '#feed_rows .feed_row';
  29. }
  30. setInterval(function(){
  31. var current = document.querySelectorAll(wall).length;
  32. if(current>count)
  33. clearFeed();
  34. }, 100);
  35.  
  36. function clearFeed() {
  37. var len = document.querySelectorAll(wall).length;
  38. while(len > count) {
  39. document.querySelectorAll(wall)[0].remove();
  40. len = document.querySelectorAll(wall).length;
  41. }
  42. window.scrollTo(0, 350); //Average height of post. Skips first post of previous page that you have seen and probably
  43. //focus you on last one that you haven't seen fully.
  44. }
  45. })();