Skip to content

Instantly share code, notes, and snippets.

@asm256
Created April 1, 2016 08:53
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 asm256/3721961ab684ffd42f550c92f629007c to your computer and use it in GitHub Desktop.
Save asm256/3721961ab684ffd42f550c92f629007c to your computer and use it in GitHub Desktop.
なろうのランキングを最終更新日順に並び替える
// ==UserScript==
// @name NarouRankingSorter
// @namespace @asm__
// @description 「ランキングBEST」の部分をクリックするとなろうのランキングを並び替える
// @include http://noc.syosetu.com/rank/list/type/*
// @include http://yomou.syosetu.com/rank/genrelist/type/*
// @include http://yomou.syosetu.com/rank/list/type/*
// @version 1
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js
// ==/UserScript==
function naroudate_to_datestr(str){
// 最終更新日:2016年 04月 01日 00時 00分 : のくた
// 最終更新日:2016年 03月 21日 00時 00分 635,064文字 : なろう
return str.replace(/最終更新日:/,'').replace(/分.*$/,'分').
replace(/[年月]\s*/g,"/").replace(/[日分]/g," ").replace(/時\s*/,":")+" GMT+09:00";
}
function lastmodify(target){
// console.log(naroudate_to_datestr(target));
return new Date(naroudate_to_datestr(target));
}
$(function(){
var rank_h = $("div.rank_h");
var rank_table = $("table.rank_table");
var rank_list = $(".ranking_inbox");
//var bar = $("div.move_bar");
/*
console.log(rank_h)
console.log(rank_table)
console.log(rank_list)
/**/
var rank = rank_h.map(function(i,obj){
return [[obj,rank_table[i]]];
});
// console.table(rank)
var backup = null;
var sorted = rank.sort(
function(a,b){
return lastmodify(b[1].textContent.trim().split("\n").pop()) - lastmodify(a[1].textContent.trim().split("\n").pop());
}
).map(
function(i,obj){
return [obj[0],obj[1]];
}
);
// console.dir(sorted)
// なろうとノクタでなぜかクラス名が違う
$(".rank_h2 , .h2_rank").click(function(){
if(backup == null){
backup = rank_list.html();
// console.log("sort");
rank_list.html($(sorted));
}
else{
var b = backup;
backup = null;
rank_list.html(b);
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment