Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Commit

Permalink
Update to version 0.4.5, fixes various "Classic mode" bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabacab committed Feb 24, 2016
1 parent 6b19680 commit f7ad8b2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 30 deletions.
7 changes: 7 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ That said, since this script is public domain, it's entirely use-at-your-own-ris

## Change log

* Version 0.4.5
* [Bugfix](https://github.com/meitar/fetlife-aslsearch/issues/27): Proactively check for removal of the search form and re-attach it if needed.
* Bugfix: Fix "Classic mode" searches to correctly parse FetLife's newer HTML blocks. This fixes issues many users experienced with the script not returning correct results in "Classic" mode.
* Bugfix: Switch to new Google Spreadsheet back-end for Predator Alert Tool for FetLife integration, because apparently Google is a pro-rape company? See [the commit log message here](https://github.com/meitar/fetlife-aslsearch/commit/6b1968089db3b472e67119a655cfa4c1ea7835fc) for more details:
* Google flagged the PAT-FetLife spreadsheet database as "inappropriate" and revoked its "sharing" permission, effectively censoring survivors of sadomasochistic rapes from communicating with one another. Such survivor-to-survivor communication is the explicit purpose of the Predator Alert Tool suite of browser plugins, which depend on Google's Spreadsheets service to share data between one another in a way that the social networks in question cannot censor (which they have done).
* It is unfortunate that a company like Google considers rape survivors to be doing something "inappropriate" when they try to warn their peers that they have been sexually abused in an effort to prevent others from falling victim to predators.
* Please consider voicing your displeasure at Google's explicit pro-rape stance on this issue in whatever way you can. Google can be reached here: https://www.google.com/contact/
* Version 0.4.4.4
* [Bugfix](https://github.com/meitar/fetlife-aslsearch/issues/22): Fix an issue for Google Chrome users where event listeners on `window` object would occasionally fail to run. This should fix the missing "A/S/L?" checkbox for Chrome users.
* Version 0.4.4.3
Expand Down
91 changes: 61 additions & 30 deletions fetlife-age-sex-location-search.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
// ==UserScript==
// @name FetLife ASL Search (Extened Edition)
// @version 0.4.4.4
// @version 0.4.5
// @namespace http://maybemaimed.com/playground/fetlife-aslsearch/
// @updateURL https://github.com/meitar/fetlife-aslsearch/raw/master/fetlife-age-sex-location-search.user.js
// @description Allows you to search for FetLife profiles based on age, sex, location, and role.
Expand Down Expand Up @@ -422,7 +422,7 @@ FL_ASL.getKinkstersFromURL = function (url) {
'onload': function (response) {
var parser = new DOMParser();
var doc = parser.parseFromString(response.responseText, 'text/html');
var els = doc.querySelectorAll('.user_in_list');
var els = doc.querySelectorAll('.fl-member-card');
var fl_profiles = [];
for (var i = 0; i < els.length; i++) {
fl_profiles.push(FL_ASL.scrapeUserInList(els[i]));
Expand Down Expand Up @@ -485,7 +485,7 @@ FL_ASL.getKinkstersFromURL = function (url) {
};

/**
* Determines whether a "user_in_list" block matches the searched-for parameters.
* Determines whether a "fl-member-card" block matches the searched-for parameters.
*
* @return True if block matches all search parameters, false otherwise.
*/
Expand All @@ -509,7 +509,7 @@ FL_ASL.matchesSearchParams = function (el) {
}

// Does block match gender/sex selection?
if (-1 === search_params.sex.indexOf(FL_ASL.getSex(el))) {
if (-1 === search_params.sex.indexOf(FL_ASL.getGender(el))) {
return false;
}

Expand All @@ -522,30 +522,41 @@ FL_ASL.matchesSearchParams = function (el) {
return true;
};

FL_ASL.getSex = function (el) {
var x = el.querySelector('.quiet').innerHTML;
var sex = x.match(/^\d\d(\S*)/);
return sex[1];
};

FL_ASL.getGender = function (el) {
var parsed = FL_ASL.scrapeUserInList(el);
if (parsed.gender) {
return parsed.gender;
} else {
return '';
}
}
FL_ASL.getAge = function (el) {
var x = el.querySelector('.quiet').innerHTML;
var age = x.match(/^\d\d/);
return parseInt(age);
var parsed = FL_ASL.scrapeUserInList(el);
if (parsed.age) {
return parseInt(parsed.age);
} else {
return '';
}
};

FL_ASL.getRole = function (el) {
var x = el.querySelector('.quiet').innerHTML;
var role = x.match(/ (.*)$/);
return role[1];
var parsed = FL_ASL.scrapeUserInList(el);
if (parsed.role) {
return parsed.role;
} else {
return '';
}
};
FL_ASL.getLocationString = function (el) {
return el.querySelector('em').innerHTML;
if (el.querySelector('.fl-member-card__location')) {
return el.querySelector('.fl-member-card__location').innerHTML.trim();
} else {
return '';
}
};

FL_ASL.displayResult = function (el) {
var id = el.querySelector('a').getAttribute('href').match(/\d+$/);
var name = el.querySelector('.large a').childNodes[0].nodeValue;
var id = FL_ASL.scrapeUserInList(el).user_id;
var name = FL_ASL.scrapeUserInList(el).nickname;
var a = document.createElement('a');
a.href = 'https://fetlife.com/conversations/new?with=' + id;
a.innerHTML = '(send ' + name + ' a message)';
Expand Down Expand Up @@ -831,6 +842,17 @@ FL_ASL.attachSearchForm = function () {
prog = document.createElement('p');
prog.setAttribute('id', FL_ASL.CONFIG.progress_id);
FL_ASL.CONFIG.search_form.appendChild(prog);

// Re-attach the search form after page load if for "some reason" it is not here.
// See https://github.com/meitar/fetlife-aslsearch/issues/27
window.addEventListener('DOMContentLoaded', function () {
setInterval(function () {
if (!window.document.querySelector('#fetlife_asl_search_ui_container')) {
FL_ASL.attachSearchForm();
}
}, 2000)
}
);
};

// ****************************************************
Expand All @@ -853,6 +875,9 @@ FL_ASL.GAS.ajaxPost = function (data) {
},
'onload': function (response) {
FL_ASL.log('POST response received: ' + response.responseText);
},
'onerror': function (response) {
FL_ASL.log('Error POSTing to ' + url + ', response received: ' + response.responseText);
}
});
};
Expand Down Expand Up @@ -1089,26 +1114,32 @@ FL_ASL.scrapeProfile = function (user_id) {
}
FL_ASL.scrapeUserInList = function (node) {
// Deal with location inconsistencies.
var loc_parts = jQuery(node).find('.small').first().text().split(', ');
var loc_parts = jQuery(node).find('.fl-member-card__location').first().text().split(', ');
var locality = ''; var region = ''; var country = '';
if (2 === loc_parts.length) {
locality = loc_parts[0];
region = loc_parts[1];
} else if (1 === loc_parts.length) {
country = loc_parts[0];
}

var profile_data = {
'user_id': jQuery(node).find('a').first().attr('href').match(/\d+$/)[0],
'nickname': jQuery(node).find('img').first().attr('alt'),
'age': jQuery(node).find('.quiet').first().text().match(/^\d+/)[0],
'gender': jQuery(node).find('.quiet').first().text().match(/[^\d ]+/)[0],
'role': jQuery(node).find('.quiet').first().text().match(/ (.*)$/)[1],
'location_locality': locality,
'location_region': region,
'location_country': country,
'location_locality': locality.trim(),
'location_region': region.trim(),
'location_country': country.trim(),
'avatar_url': jQuery(node).find('img').first().attr('src')
};
var member_info = jQuery(node).find('.fl-member-card__info').text().trim();
if (member_info.match(/^\d+/) instanceof Array) {
profile_data['age'] = member_info.match(/^\d+/)[0].trim();
}
if (member_info.match(/[^\d ]+/) instanceof Array) {
profile_data['gender'] = member_info.match(/[^\d ]+/)[0].trim();
}
if (member_info.match(/ (.*)$/) instanceof Array) {
profile_data['role'] = member_info.match(/ (.*)$/)[1].trim();
}
for (var k in profile_data) {
if ('' === profile_data[k]) {
delete profile_data[k];
Expand Down Expand Up @@ -1136,8 +1167,8 @@ FL_ASL.main = function () {
FL_ASL.log('Scraping profile ' + m[1]);
fl_profiles.push(FL_ASL.scrapeProfile(m[1]));
}
if (document.querySelectorAll('.user_in_list').length) {
jQuery('.user_in_list').each(function () {
if (document.querySelectorAll('.fl-member-card').length) {
jQuery('.fl-member-card').each(function () {
fl_profiles.push(FL_ASL.scrapeUserInList(this));
});
}
Expand Down

0 comments on commit f7ad8b2

Please sign in to comment.