Created
August 19, 2014 16:35
-
-
Save nattaylor/061901b63e9a58f70a8d to your computer and use it in GitHub Desktop.
JavaScript snippets for parsing sites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment