Skip to content

Instantly share code, notes, and snippets.

@igavrysh
Created October 13, 2017 16:02
Show Gist options
  • Save igavrysh/ad5da9120b0917d6f707795254394b62 to your computer and use it in GitHub Desktop.
Save igavrysh/ad5da9120b0917d6f707795254394b62 to your computer and use it in GitHub Desktop.
var markup = document.documentElement.innerHTML;
var htmlEnDeCode = (function() {
var charToEntityRegex,
entityToCharRegex,
charToEntity,
entityToChar;
function resetCharacterEntities() {
charToEntity = {};
entityToChar = {};
// add the default set
addCharacterEntities({
'&' : '&',
'>' : '>',
'&lt;' : '<',
'&quot;' : '"',
'&#39;' : "'"
});
}
function addCharacterEntities(newEntities) {
var charKeys = [],
entityKeys = [],
key, echar;
for (key in newEntities) {
echar = newEntities[key];
entityToChar[key] = echar;
charToEntity[echar] = key;
charKeys.push(echar);
entityKeys.push(key);
}
charToEntityRegex = new RegExp('(' + charKeys.join('|') + ')', 'g');
entityToCharRegex = new RegExp('(' + entityKeys.join('|') + '|&#[0-9]{1,5};' + ')', 'g');
}
function htmlEncode(value){
var htmlEncodeReplaceFn = function(match, capture) {
return charToEntity[capture];
};
return (!value) ? value : String(value).replace(charToEntityRegex, htmlEncodeReplaceFn);
}
function htmlDecode(value) {
var htmlDecodeReplaceFn = function(match, capture) {
return (capture in entityToChar) ? entityToChar[capture] : String.fromCharCode(parseInt(capture.substr(2), 10));
};
return (!value) ? value : String(value).replace(entityToCharRegex, htmlDecodeReplaceFn);
}
resetCharacterEntities();
return {
htmlEncode: htmlEncode,
htmlDecode: htmlDecode
};
})();
function getMatchesForRegExp(regex, markup) {
var result = [];
while ((index = markup.search(regex)) != -1) {
var m = regex.exec(markup);
markup = markup.substring(index + 1);
if (m.length > 0) {
result.push(m[0]);
}
}
return result;
}
//markup = htmlEnDeCode.htmlDecode(markup);
var encoded_query = getMatchesForRegExp(RegExp(/(encoded_query:\"\{.+?\}\")/), markup).slice(-1).pop();
var filter_ids = RegExp(/(filter_ids\s*:\s*[^}]+\})/).exec(markup).slice(-1).pop();
var encoded_title = RegExp(/(encoded_title\s*:\s*\"[^\"]*\")/).exec(markup).slice(-1).pop();
var ref_path = RegExp(/(ref_path\s*:\s*\"[^\"]*\")/).exec(markup).slice(-1).pop();
var cursor = RegExp(/BrowseScrollingPager.*(cursor:\"[^\"]*\")/).exec(markup).slice(-1).pop();
var impression_id = RegExp(/impression_id\s*:\s*(\"[^\"]+\")/).exec(markup).slice(-1).pop();
var tl_log = RegExp(/(encoded_title\s*:\s*\"[^\"]*\")/).exec(markup).slice(-1).pop();
var page_number = RegExp(/BrowseScrollingPager.*(page_number\s*:\s*\d+)/).exec(markup).slice(-1).pop();
var user_id = markup.match(RegExp(/\"USER_ID\":\"([0-9]*)\"/))[1]
var url = 'https://www.facebook.com/ajax/pagelet/generic.php/BrowseScrollingSetPagelet'
+ '?dpr=2'
+ '&data={'
+ '"view":"list",'
+ encoded_query + ','
+ encoded_title + ','
+ '"ref":"unknown",'
+ '"logger_source":"www_main",'
+ '"typeahead_sid":"",'
+ '"tl_log":false,'
+ '"impression_id":' + impression_id + ','
+ filter_ids + ','
+ '"experience_type":"grammar",'
+ '"exclude_ids":null,'
+ '"browse_location":"browse_location:browse",'
+ '"trending_source":null,'
+ ref_path + ','
+ '"is_trending":false,'
+ '"topic_id":null,'
+ '"story_id":null,'
+ '"callsite":"browse_ui:init_result_set",'
+ '"display_params":{"crct":"none"},'
+ cursor + ','
+ page_number + ','
+ '"em":false,'
+ '"tr":null}'
+ '&__user=' + user_id
+ '&__a=1'
+ '&__dyn='
+ '&__af='
+ '&__req=12'
+ '&__be='
+ '&__pc='
+ '&__rev='
+ '&__spin_r='
+ '&__spin_b='
+ '&__spin_t=';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment