Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamps Age Update #1694

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update timestamps.js
motackt authored Apr 27, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit a40fdd8cc3243528022e117cb8a0a35d8cf7fbb8
39 changes: 36 additions & 3 deletions Extensions/timestamps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//* TITLE Timestamps **//
//* VERSION 2.10.1 **//
//* VERSION 2.11.0 **//
//* DESCRIPTION See when a post has been made. **//
//* DETAILS This extension lets you see when a post was made, in full date or relative time (eg: 5 minutes ago). It also works on asks, and you can format your timestamps. **//
//* DEVELOPER New-XKit **//
@@ -26,6 +26,16 @@ XKit.extensions.timestamps = new Object({
default: true,
value: true
},
beside_header: {
text: "Show timestamps beside header",
default: false,
value: false
},
show_age: {
text: "Show timestamps age",
default: true,
value: true
},
reblogs: {
text: "Reblog timestamps",
type: "combo",
@@ -124,6 +134,9 @@ XKit.extensions.timestamps = new Object({
this.check_quota();
try {
if (this.is_compatible()) {
if (this.preferences.beside_header.value) {
XKit.tools.add_css('.xtimestamp { display: inline-block; top: 0; margin: 0; }', "timestamps");
}
XKit.tools.add_css('#posts .post .post_content { padding-top: 0px; }', "timestamps");
if (this.preferences.posts.value || (this.preferences.inbox.value && XKit.interface.where().inbox)) {
XKit.post_listener.add("timestamps", this.add_timestamps);
@@ -184,7 +197,11 @@ XKit.extensions.timestamps = new Object({
post.find(".post-info-tumblelogs").prepend(in_search_html);
} else {
var normal_html = '<div class="xkit_timestamp_' + post_id + ' xtimestamp xtimestamp_loading">&nbsp;</div>';
post.find(".post_content").prepend(normal_html);
if (XKit.extensions.timestamps.preferences.beside_header.value) {
post.find(".post_wrapper .post_header").append(normal_html);
} else {
post.find(".post_content").prepend(normal_html);
}
}

var note = $(".xkit_timestamp_" + post_id);
@@ -234,6 +251,9 @@ XKit.extensions.timestamps = new Object({
throw 404;
}

var date = moment(new Date(responseData.posts[0].timestamp * 1000));
XKit.extensions.timestamps.add_age(date, date_element);

var timestamp = responseData.posts[0].timestamp;
date_element.html(this.format_date(moment(new Date(timestamp * 1000))));
date_element.removeClass("xtimestamp_loading");
@@ -242,6 +262,18 @@ XKit.extensions.timestamps = new Object({
.catch(() => this.show_failed(date_element));
},

add_age: function(date, date_element) {
var this_year = moment().year();

if (date.year() == this_year) {
date_element.addClass("xtimestamp-this-year");
} else if (date.year() <= this_year - 5) {
date_element.addClass("xtimestamp-5plus-year");
} else {
date_element.addClass("xtimestamp-" + (this_year - date.year()) + "-year");
}
},

fetch_from_cache: function(post_id, date_element) {
var cached = XKit.storage.get("timestamps", "xkit_timestamp_cache_" + post_id, "");
if (cached === "") {
@@ -257,6 +289,7 @@ XKit.extensions.timestamps = new Object({
if (!cached_date.isValid()) {
return false;
}
this.add_age(moment(new Date(cached * 1000)), date_element);
date_element.html(this.format_date(cached_date));
date_element.removeClass("xtimestamp_loading");
return true;
@@ -278,7 +311,7 @@ XKit.extensions.timestamps = new Object({
if (this.preferences.only_relative.value) {
return `<span title="${absolute}">${relative}</span>`;
} else {
return `${absolute} &middot; ${relative}`;
return `${absolute}`;
}
},