// ==UserScript== // @name GitHub Pulse Sort By // @namespace faleij // @description adds sorting option to repo pulse // @include https://github.com/*/*/pulse // @version 1 // @grant none // @downloadURL none // ==/UserScript== /* jshint esnext:true, node:true, browser:true */ /* globals $ */ 'use strict'; function create() { // Load assignees $('li>.title').each((index, title) => $.get($(title).attr('href')).then(data => $(title).parent().append($('.assignee', $(data)).parent().css('float', 'right')))); let menu = $(`
`).prependTo('.header-with-actions'); $('input:radio[name="sortBy"]', menu).change(function () { let sort = (a,b) => $(`.${this.value}:first`, a).text() > $(`.${this.value}:first`, b).text(); if (this.value === 'num') { sort = (a,b) => parseInt($(`.${this.value}:first`, a).text().substr(1)) > parseInt($(`.${this.value}:first`, b).text().substr(1)); } if (this.value === 'time') { sort = (a,b) => new Date($(`.${this.value}:first`, a).attr('datetime')) > new Date($(`.${this.value}:first`, b).attr('datetime')); } return $('.repository-content ul').each((index, ul) => $('li', ul).sort(sort).appendTo(ul)); }); } const target = document.querySelector('#js-repo-pjax-container'); const mutationHandler = () => $('.faleijs-sort-by-menu', target).length || create(); const observer = new MutationObserver(mutationHandler); observer.observe(target, { childList: true, subtree: true }); mutationHandler();