DRY
This commit is contained in:
parent
20e3d8f697
commit
3dbe03300e
128
4chan_x.user.js
128
4chan_x.user.js
@ -1950,26 +1950,10 @@
|
|||||||
foo: function() {
|
foo: function() {
|
||||||
var code;
|
var code;
|
||||||
code = conf['time'].replace(/%([A-Za-z])/g, function(s, c) {
|
code = conf['time'].replace(/%([A-Za-z])/g, function(s, c) {
|
||||||
switch (c) {
|
if (c in Time.formatters) {
|
||||||
case 'a':
|
return "' + Time.formatters." + c + "() + '";
|
||||||
case 'A':
|
} else {
|
||||||
case 'b':
|
return s;
|
||||||
case 'B':
|
|
||||||
case 'd':
|
|
||||||
case 'e':
|
|
||||||
case 'H':
|
|
||||||
case 'I':
|
|
||||||
case 'k':
|
|
||||||
case 'l':
|
|
||||||
case 'm':
|
|
||||||
case 'M':
|
|
||||||
case 'p':
|
|
||||||
case 'P':
|
|
||||||
case 'y':
|
|
||||||
return "' + Time." + c + "() + '";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return Time.funk = Function('Time', "return '" + code + "'");
|
return Time.funk = Function('Time', "return '" + code + "'");
|
||||||
@ -1983,58 +1967,60 @@
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
a: function() {
|
formatters: {
|
||||||
return this.day[this.date.getDay()].slice(0, 3);
|
a: function() {
|
||||||
},
|
return Time.day[Time.date.getDay()].slice(0, 3);
|
||||||
A: function() {
|
},
|
||||||
return this.day[this.date.getDay()];
|
A: function() {
|
||||||
},
|
return Time.day[Time.date.getDay()];
|
||||||
b: function() {
|
},
|
||||||
return this.month[this.date.getMonth()].slice(0, 3);
|
b: function() {
|
||||||
},
|
return Time.month[Time.date.getMonth()].slice(0, 3);
|
||||||
B: function() {
|
},
|
||||||
return this.month[this.date.getMonth()];
|
B: function() {
|
||||||
},
|
return Time.month[Time.date.getMonth()];
|
||||||
d: function() {
|
},
|
||||||
return this.zeroPad(this.date.getDate());
|
d: function() {
|
||||||
},
|
return Time.zeroPad(Time.date.getDate());
|
||||||
e: function() {
|
},
|
||||||
return this.date.getDate();
|
e: function() {
|
||||||
},
|
return Time.date.getDate();
|
||||||
H: function() {
|
},
|
||||||
return this.zeroPad(this.date.getHours());
|
H: function() {
|
||||||
},
|
return Time.zeroPad(Time.date.getHours());
|
||||||
I: function() {
|
},
|
||||||
return this.zeroPad(this.date.getHours() % 12 || 12);
|
I: function() {
|
||||||
},
|
return Time.zeroPad(Time.date.getHours() % 12 || 12);
|
||||||
k: function() {
|
},
|
||||||
return this.date.getHours();
|
k: function() {
|
||||||
},
|
return Time.date.getHours();
|
||||||
l: function() {
|
},
|
||||||
return this.date.getHours() % 12 || 12;
|
l: function() {
|
||||||
},
|
return Time.date.getHours() % 12 || 12;
|
||||||
m: function() {
|
},
|
||||||
return this.zeroPad(this.date.getMonth() + 1);
|
m: function() {
|
||||||
},
|
return Time.zeroPad(Time.date.getMonth() + 1);
|
||||||
M: function() {
|
},
|
||||||
return this.zeroPad(this.date.getMinutes());
|
M: function() {
|
||||||
},
|
return Time.zeroPad(Time.date.getMinutes());
|
||||||
p: function() {
|
},
|
||||||
if (this.date.getHours() < 12) {
|
p: function() {
|
||||||
return 'AM';
|
if (Time.date.getHours() < 12) {
|
||||||
} else {
|
return 'AM';
|
||||||
return 'PM';
|
} else {
|
||||||
|
return 'PM';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
P: function() {
|
||||||
|
if (Time.date.getHours() < 12) {
|
||||||
|
return 'am';
|
||||||
|
} else {
|
||||||
|
return 'pm';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
y: function() {
|
||||||
|
return Time.date.getFullYear() - 2000;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
P: function() {
|
|
||||||
if (this.date.getHours() < 12) {
|
|
||||||
return 'am';
|
|
||||||
} else {
|
|
||||||
return 'pm';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
y: function() {
|
|
||||||
return this.date.getFullYear() - 2000;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
titlePost = {
|
titlePost = {
|
||||||
|
|||||||
@ -1557,9 +1557,10 @@ Time =
|
|||||||
$.replace s, time
|
$.replace s, time
|
||||||
foo: ->
|
foo: ->
|
||||||
code = conf['time'].replace /%([A-Za-z])/g, (s, c) ->
|
code = conf['time'].replace /%([A-Za-z])/g, (s, c) ->
|
||||||
switch c
|
if c of Time.formatters
|
||||||
when 'a', 'A', 'b', 'B', 'd', 'e', 'H', 'I', 'k', 'l', 'm', 'M', 'p', 'P', 'y' then "' + Time.#{c}() + '"
|
"' + Time.formatters.#{c}() + '"
|
||||||
else s
|
else
|
||||||
|
s
|
||||||
Time.funk = Function 'Time', "return '#{code}'"
|
Time.funk = Function 'Time', "return '#{code}'"
|
||||||
day: [
|
day: [
|
||||||
'Sunday'
|
'Sunday'
|
||||||
@ -1585,21 +1586,22 @@ Time =
|
|||||||
'December'
|
'December'
|
||||||
]
|
]
|
||||||
zeroPad: (n) -> if n < 10 then '0' + n else n
|
zeroPad: (n) -> if n < 10 then '0' + n else n
|
||||||
a: -> @day[@date.getDay()][...3]
|
formatters:
|
||||||
A: -> @day[@date.getDay()]
|
a: -> Time.day[Time.date.getDay()][...3]
|
||||||
b: -> @month[@date.getMonth()][...3]
|
A: -> Time.day[Time.date.getDay()]
|
||||||
B: -> @month[@date.getMonth()]
|
b: -> Time.month[Time.date.getMonth()][...3]
|
||||||
d: -> @zeroPad @date.getDate()
|
B: -> Time.month[Time.date.getMonth()]
|
||||||
e: -> @date.getDate()
|
d: -> Time.zeroPad Time.date.getDate()
|
||||||
H: -> @zeroPad @date.getHours()
|
e: -> Time.date.getDate()
|
||||||
I: -> @zeroPad @date.getHours() % 12 or 12
|
H: -> Time.zeroPad Time.date.getHours()
|
||||||
k: -> @date.getHours()
|
I: -> Time.zeroPad Time.date.getHours() % 12 or 12
|
||||||
l: -> @date.getHours() % 12 or 12
|
k: -> Time.date.getHours()
|
||||||
m: -> @zeroPad @date.getMonth() + 1
|
l: -> Time.date.getHours() % 12 or 12
|
||||||
M: -> @zeroPad @date.getMinutes()
|
m: -> Time.zeroPad Time.date.getMonth() + 1
|
||||||
p: -> if @date.getHours() < 12 then 'AM' else 'PM'
|
M: -> Time.zeroPad Time.date.getMinutes()
|
||||||
P: -> if @date.getHours() < 12 then 'am' else 'pm'
|
p: -> if Time.date.getHours() < 12 then 'AM' else 'PM'
|
||||||
y: -> @date.getFullYear() - 2000
|
P: -> if Time.date.getHours() < 12 then 'am' else 'pm'
|
||||||
|
y: -> Time.date.getFullYear() - 2000
|
||||||
|
|
||||||
titlePost =
|
titlePost =
|
||||||
init: ->
|
init: ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user