forked from sciooga/v2ex-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv2ex_date.js
34 lines (28 loc) · 1.24 KB
/
v2ex_date.js
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
//————————————————显示主题发布日期————————————————
var gray = $(".header .gray");
var grayText = gray.text();
chrome.storage.sync.get(function(response) {
if(response.displayPostDate && grayText.indexOf("天前") > -1){
var distance = parseInt(grayText.match(/[0-9]* 天前/g)[0]);
var date=new Date();
date.setDate(date.getDate()-distance);
var month = date.getMonth() + 1;
// 获取当前是几号
var strDate = date.getDate();
// 添加分隔符“-”
var seperator = "-";
// 对月份进行处理,1-9月在前面添加一个“0”
if (month >= 1 && month <= 9) {
month = "0" + month;
}
// 对月份进行处理,1-9号在前面添加一个“0”
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
// 最后拼接字符串,得到一个格式为(yyyy-MM-dd)的日期
var postDate = date.getFullYear() + seperator + month + seperator + strDate;
//插入postDate
grayText = grayText.replace(/ 天前 ·/," 天前(" + postDate + ") ·");
gray.text(grayText);
}
});