Last active
December 10, 2017 18:12
-
-
Save AprilSylph/3def1e7a93d061228859e46d98a09c00 to your computer and use it in GitHub Desktop.
XKit Extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//* TITLE Follower Details **// | |
//* VERSION 1.0.0 **// | |
//* DESCRIPTION See when each of your followers last updated **// | |
//* DEVELOPER AprilSylph **// | |
//* FRAME false **// | |
//* BETA false **// | |
XKit.extensions.follower_details = new Object({ | |
running: false, | |
run: function() { | |
this.running = true; | |
console.log("Follower Details booted up!"); | |
if (!XKit.interface.where().followers) { return; } | |
$(".follower").each(function() { | |
var username = $(this).find(".name").find("a").html(); | |
var target = $(this); | |
var api_url = "https://api.tumblr.com/v2/blog/" + username + ".tumblr.com/info" + "?api_key=" + XKit.api_key; | |
var last_updated = 0; | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: api_url, | |
json: true, | |
onerror: function(response) { | |
return; | |
}, | |
onload: function(response) { | |
var data = JSON.parse(response.responseText).response; | |
var dtx = new Date(data.blog.updated * 1000); | |
// defined in moment.js | |
/* globals moment */ | |
var dt = moment(dtx); | |
last_updated = dt.from(new Date()); | |
XKit.extensions.follower_details.add_stat(target, last_updated); | |
} | |
}); | |
}); | |
}, | |
add_stat: function(target, text) { | |
f_text = "<div class='description'>Last updated <span style='font-weight: bold;'>" + text + "</span></div>"; | |
$(target).find(".info").append(f_text); | |
}, | |
destroy: function() { | |
this.running = false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment