-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrokuyo.coffee
58 lines (43 loc) · 1.41 KB
/
rokuyo.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
###
* はてなブログの記事の日付に六曜を表示する
** 使い方
以下をコピーして デザイン編集 → カスタマイズ → フッタHTML に貼り付け
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://hitode909.github.io/hatenablog-unofficial-modules/rokuyo.js"></script>
旧暦を取得するWeb APIを利用しています.
- http://api.sekido.info/qreki?output=usage
日付が途中で改行して崩れる場合はいかのようなCSSを指定すれば直るかもしれない
.date {
display: inline-block;
width: auto;
}
###
$ ->
handle_article = ($article) ->
return if $article.prop 'rokuyou-loaded'
$article.prop 'rokuyou-loaded', true
year = + $article.find('.date-year').text()
month = +$article.find('.date-month').text()
day = +$article.find('.date-day').text()
load = $.ajax
url: 'http://api.sekido.info/qreki'
dataType: 'jsonp'
data:
year: year
month: month
day: day
output: 'jsonp'
load.done (res) ->
rokuyou = res.rokuyou_text
$rokuyou = $ '<span>'
$rokuyou.addClass 'rokuyou'
$rokuyou.addClass "rokuyou-#{ rokuyou }"
$rokuyou.text rokuyou
$article.find('.date a').append $rokuyou
main = ->
($ 'article').each ->
handle_article ($ this)
do main
setInterval ->
do main
, 1000