Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Filters meetup.com pages based on a given regex of linked member profiles. Useful for finding language exchange partners.
/* Initial definitions */
var regex_positive = /(france|french|paris|bonjour|salut|montr.al)/i;
var regex_negative = /(china|korea|spain|japan|taiwan|venezuela|costa rica|chile|vietnam|russia|honduras|brazil|iran|m.xico|czech|sweden|saudi|turkey|germany|india|argentina|colombia|netherlands|philippines)/i;
var now = new Date().getTime();
var ten_seconds = 10 * 1000;
var one_day = 86400 * 1000;
var one_week = one_day * 7;
/* Clear junk from the page */
jQuery("#chapterHeader, p").remove();
/* Find the member links */
var urls = {};
jQuery("a[href*=member]").each(function() {
var element = jQuery(this);
var match = element.attr("href").match(/(.*\/members?\/[0-9]+)/);
if (match) {
urls[match[1]] = true;
element.css({display: "inline-block", background: "#0ff"}).find("img").css({opacity: 0.5});
}
});
/* The function that highlights the content */
function addOverview(element, content) {
var rating = 0;
if (content.profileQuestionsText.match(regex_positive)) rating += 4;
if (content.profileQuestionsText.match(regex_negative)) rating -= 4;
if (content.profileAsideText.match(regex_positive)) rating += 1;
if (content.profileAsideText.match(regex_negative)) rating -= 1;
element.css({background: "hsl(" + (Math.max(0, rating) * 20) +", 80%, 50%)"});
if (rating < 0) element.parents(".memberInfo").remove();
}
/* Attach our extra content to each block */
jQuery.each(urls, function(url) {
var matchingElements = jQuery("a[href^='"+url+"']");
/* Try to use the cached value */
var timedContent = localStorage[url] ? JSON.parse(localStorage[url]) : null;
if (timedContent && timedContent.expires > now) {
jQuery.each(matchingElements, function(index, element) {
addOverview(jQuery(element), timedContent);
});
}
/* Otherwise, getting the linked page's content and parse it out */
else {
jQuery.get(url, function(data) {
var remotePage = jQuery(data);
var content = {};
content.expires = now + one_week;
content.profileQuestionsText = jQuery("#D_memberProfileQuestions", remotePage).text().replace(/\s+/g, ' ');
content.profileAsideText = jQuery("#D_memberProfileAside", remotePage).text().replace(/\s+/g, ' ');
localStorage[url] = JSON.stringify(content);
jQuery.each(matchingElements, function(index, element) {
addOverview(jQuery(element), content);
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.