Last active
May 14, 2018 18:18
-
-
Save AprilSylph/bdf77c74388d24ce7d358530df0d6495 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 URL Checker **// | |
//* VERSION 1.1.0 **// | |
//* DESCRIPTION Be notified of when URLs are deleted **// | |
//* DEVELOPER AprilSylph **// | |
//* FRAME false **// | |
//* BETA false **// | |
XKit.extensions.url_checker = new Object({ | |
running: false, | |
preferences: { | |
users: { | |
text: "URLs to check (comma separated)", | |
type: "text", | |
default: "", | |
value: "" | |
}, | |
no_info: { | |
text: "Only notify me when URLs are freed", | |
default: true, | |
value: true | |
} | |
}, | |
run: function() { | |
this.running = true; | |
var usernames = this.preferences.users.value.split(","); | |
usernames.forEach(function(username) { | |
username = username.trim(); | |
if (!username.length) { return; } | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: "https://api.tumblr.com/v2/blog/" + username + ".tumblr.com/info" + "?api_key=" + XKit.api_key, | |
json: true, | |
onerror: function(response) { | |
XKit.notifications.add(username + " does not exist!", "ok", true); | |
}, | |
onload: function(response) { | |
var data = JSON.parse(response.responseText).response; | |
var dtx = new Date(data.blog.updated * 1000); | |
var dt = moment(dtx); | |
var last_updated = dt.from(new Date()); | |
var ask_info = "Error loading ask data"; | |
if (data.blog.ask) { | |
ask_info = "Asks: enabled"; | |
} else { | |
ask_info = "Asks: disabled"; | |
} | |
if (!XKit.extensions.url_checker.preferences.no_info.value) { | |
XKit.notifications.add(username + " last updated " + last_updated + "<br/>" + ask_info, "info"); | |
} | |
} | |
}); | |
}); | |
}, | |
destroy: function() { | |
this.running = false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment