Created
December 3, 2014 03:43
-
-
Save traktraktrugui/691564e1756c9d057413 to your computer and use it in GitHub Desktop.
Ordenate Pluralsight courses by date ascending
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
// ==UserScript== | |
// @name Order Pluralsight Courses | |
// @version 1.1 | |
// @description Ordena o cursos da pluralsight por data | |
// @match http://*www.pluralsight.com/* | |
// @require http://code.jquery.com/jquery-latest.js | |
// @copyright 2014+, Rods | |
// ==/UserScript== | |
var s_ajaxListener = new Object(); | |
s_ajaxListener.tempOpen = XMLHttpRequest.prototype.open; | |
s_ajaxListener.count = 0; | |
s_ajaxListener.callback = function () { | |
$("h3[ng-show='author']").after(function() { return "<h5 style=\"cursor: pointer;\" id=\"__reordenar\"><i class=\"fi-refresh\" style=\"margin: 0px 10px 0px 5px;\"></i>Reordenar!</h5>"; }); | |
$("#__reordenar").on("click", function() { | |
ReordernarFunc(); | |
}); | |
} | |
XMLHttpRequest.prototype.open = function(a,b) { | |
if (!a) var a=''; | |
if (!b) var b=''; | |
s_ajaxListener.tempOpen.apply(this, arguments); | |
s_ajaxListener.method = a; | |
s_ajaxListener.url = b; | |
if (a.toLowerCase() == 'get') { | |
s_ajaxListener.data = b.split('?'); | |
s_ajaxListener.data = s_ajaxListener.data[1]; | |
s_ajaxListener.count++; | |
if (s_ajaxListener.count === 8){ | |
s_ajaxListener.callback(); | |
} | |
} | |
} | |
var mon = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]; | |
var rg = new RegExp(/(\d{2}\b|\d{4}\b)/g); | |
function ReordernarFunc(){ | |
$("ul>li:nth-child(1) div.ng-binding").css("width", "100px"); | |
$("ul>li:nth-child(2) p.ng-binding").css("width", "55px"); | |
$("ul>li:nth-child(3) p.ng-binding").css("width", "120px"); | |
var __Curses = $("li>p").contents() | |
.filter(function(){ | |
if(this.length > 7) return this; | |
}).parent().parent().parent().parent().parent().parent(); | |
$("li>p").contents() | |
.filter(function(){ | |
if(this.length > 7) return this; | |
}).parent().parent().parent().parent().parent().parent().remove(); | |
for (var i = 0, len = __Curses.length - 1; i < len; i++) | |
{ | |
var d1 = ConvertDate($(__Curses[i]).find("li>p").contents().filter(function(){ if(this.length > 7) return this;}).text()); | |
var d2 = ConvertDate($(__Curses[i + 1]).find("li>p").contents().filter(function(){ if(this.length > 7) return this;}).text()); | |
} | |
var __CursesSorted = __Curses.sort(SorterDate); | |
$(".medium.text-center").parent().append(__CursesSorted) | |
} | |
function ConvertDate(dt){ | |
var d; | |
mon.map(function(element, i){ | |
if(dt.toLowerCase().indexOf(element) > -1) { | |
d = new Date(dt.match(rg)[1], i, dt.match(rg)[0]); | |
} | |
}); | |
return d; | |
} | |
function SorterDate(d1, d2){ | |
var _d1 = ConvertDate($(d1).find("li>p").contents().filter(function(){ if(this.length > 7) return this;}).text()); | |
var _d2 = ConvertDate($(d2).find("li>p").contents().filter(function(){ if(this.length > 7) return this;}).text()); | |
if (_d1 > _d2){ | |
return -1 | |
}else{ | |
return 1 | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment