Skip to content

Instantly share code, notes, and snippets.

@nattaylor
Created August 19, 2014 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nattaylor/061901b63e9a58f70a8d to your computer and use it in GitHub Desktop.
Save nattaylor/061901b63e9a58f70a8d to your computer and use it in GitHub Desktop.
JavaScript snippets for parsing sites
//Sort open Quora questions by most recent
//Go through each item and give it a timestamp
jQuery(".pagedlist_item").each(function(i,e){
//Find the timestamp for each item
var ts = jQuery(e).find(".timestamp").text();
//Timestamps from the current year don't have a year
if (ts.indexOf(",")<0) {
ts += ", 2014";
ts = Date.parse(ts);
} else if (ts.indexOf("ago")>-1) {
//Todo account for "1m ago"
ts = Date.parse(ts);
}
jQuery(e).data("ts",ts);
});
//Sort based on timestmap
jQuery('.pagedlist_item').sort(function(a,b) {
return a.dataset.ts > b.dataset.ts;
}).appendTo('.Feed');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment