Last active
December 11, 2015 06:58
-
-
Save 3100/4562463 to your computer and use it in GitHub Desktop.
a Greasemonkey script file to sort rooms of AsakusaSatellite's main page in date order.
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 sort_as | |
// @namespace 3100 | |
// @description ASのルームを更新順序順に変更する | |
// @include http://as.iplwiki.info/ | |
// @version 1.0.2 | |
// ==/UserScript== | |
(function (){ | |
var changeTextForSort = function(text) { | |
var date_str_arr = text.split(' '); //cf. ["2013-01-28","12:58","pm"] | |
var time = date_str_arr[1].split(':'); | |
if (time[0] == '12'){ | |
date_str_arr[1] = "00:" + date_str_arr[1]; | |
} | |
return date_str_arr[0] + date_str_arr[2] + date_str_arr[1]; | |
}; | |
var getUpdateText = function(elem) { | |
var text = elem.getElementsByClassName('update').item(0).textContent; | |
return changeTextForSort(text); | |
}; | |
var toArrayWithoutHeader = function(origin) { | |
return Array.prototype.slice.call(origin, 1); | |
}; | |
var origin = document.getElementsByTagName('tr'); | |
var items = toArrayWithoutHeader(origin); | |
items.sort(function(a, b) { | |
return getUpdateText(a) <= getUpdateText(b) ? 1 : -1; | |
}); | |
var insertTarget = document.getElementsByClassName('room-list').item(0); | |
var insert = origin.item(0).outerHTML; | |
for(var i = 0; i < items.length; ++i) { | |
insert += items[i].outerHTML; | |
} | |
console.log(insert); | |
insertTarget.innerHTML = insert; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment