jhult / LinkedIn Hide Non-Members from PYMK

// ==UserScript==
//
// @name        LinkedIn Hide Non-Members from PYMK
// @description Hide non-members from People You May Know on LinkedIn. These people usually show up with a name, email address, a button to "Add to network" and no profile picture.

// @namespace   http://jonathanhult.com/
// @author      Jonathan Hult
// @license     MIT

// @version     1.1
// @changelog   1.1 Updated class names and added removal on scrolling

// @match       *://*.linkedin.com/people/pymk*
//
// ==/UserScript==

	var old_scrollY = 0;
	var scroll_events = 0;
	var lastChecked = 0;
	removeAllNonMembers();
	window.scrollTo(0, 0);
	window.addEventListener('scroll', onScroll, false);
	
	function onScroll(e) {
	      var now = new Date().getTime();
	      
	      if ((now - lastChecked) > 1000) {
			var y = window.scrollY;
			// if (scroll_events === 0) old_scrollY = y; // stops only if scroll position was on 2. page
			var delta = e.deltaY || y - old_scrollY; // NOTE: e.deltaY for "wheel" event
			if (delta > 0 && (window.innerHeight + y) >= (document.body.clientHeight - window.innerHeight)) {
				  try {
					  removeAllNonMembers();
				  } catch (err) {
					  console.error(err.name + ": " + err.message);
				  }
			}
			old_scrollY = y;
			scroll_events += 1;
	      }
	}

	function removeAllNonMembers() {
		// Find all non-member cards
		var cards = document.querySelectorAll('.card.guest');

		if (typeof cards != 'undefined') {
			// Loop through each card
			for (var i = 0; i < cards.length; i++) {
				// Find the close button (the "x" button)
				var closeButton = cards[i].querySelector('.bt-close');
				
				if (closeButton !== null) {
					// Click the close button
					closeButton.click();
				}
			}
		}
	}