Permalink
Browse files

Extension converted to Tumblr APIv2

All the XHR of the concerned extensions have been rewritten to use the
APIv2.

Fix #161, except for the Timezone
fetching of the Profiler extension, which does not exist anymore in the
APIv2.
  • Loading branch information...
1 parent 816577c commit b308886205754bcb833ea44b4ceceeca738ea2bf @WyohKnott WyohKnott committed Oct 11, 2014
View
@@ -1,10 +1,10 @@
/*
Bridge2 for XKit
- Version 2.1
-
+ Version 2.2
+
(c) 2011 - 2013 STUDIOXENIX
-
+
*/
var bridge_error = false;
@@ -23,7 +23,7 @@ try {
console.log("[XKIT] Caught bridge error: " + e.message);
bridge_error_object = e;
bridge_error = true;
- try {
+ try {
call_xkit();
} catch(em) {
alert("Fatal XKit Error:\n" + em.message + "\n\nPlease go to xkit-extension.tumblr.com for support.");
@@ -38,14 +38,14 @@ function getBridgeError() {
return m_object;
}
-function getVersion() {
- var version = 'NaN';
- var xhr = new XMLHttpRequest();
- xhr.open('GET', chrome.extension.getURL('manifest.json'), false);
- xhr.send(null);
- var manifest = JSON.parse(xhr.responseText);
- return manifest.version;
-}
+function getVersion() {
+ var version = 'NaN';
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', chrome.extension.getURL('manifest.json'), false);
+ xhr.send(null);
+ var manifest = JSON.parse(xhr.responseText);
+ return manifest.version;
+}
function call_xkit() {
if(typeof XKit !== "undefined") {
@@ -56,23 +56,23 @@ function call_xkit() {
}
function init_bridge() {
-
+
console.log("[XKit Bridge] Hello from Bridge " + bridge_ver);
console.log("[XKit Bridge] Retrieving storage..");
-
+
try {
-
+
storage.get(function(items) {
-
+
last_error = "";
-
+
if (typeof chrome.runtime.lastError !== "undefined") {
last_error = chrome.runtime.lastError.message;
console.log("storage.get error: " + last_error);
}
-
+
if (last_error !== "") {
-
+
XKit.window.show("Corrupt storage","XKit noticed that your browser's storage area allocated for XKit is corrupt and will now reset itself and clear the storage area so it can save it data and function properly.<br/><br/><b>Your browser returned the following error message:</b><br/>\"" + last_error + "\"<br/><br/>If you keep seeing this message, it means your Chrome's profile file is corrupt, please click on the button below for more information and learn how to fix it.", "error","<div class=\"xkit-button default\" id=\"xkit-bridge-reset-and-continue\">OK</div><a href=\"http://xkit-extension.tumblr.com/post/52742121604/chrome-system-restores-corrupt-profile-settings-and\" class=\"xkit-button\">Didn't fix your problem?</a>");
$("#xkit-bridge-reset-and-continue").click(function() {
GM_flushStorage(function() {
@@ -83,30 +83,30 @@ function init_bridge() {
}
for (key in items) {
xkit_storage[key] = items[key];
- }
+ }
storage_loaded = true;
console.log("[XKit Bridge] Storage loaded, calling XKit.. bye!");
-
+
storage.getBytesInUse(function(bytes) {
storage_used = bytes;
storage_max = -1;
call_xkit();
});
-
-
-
+
+
+
});
-
+
} catch(e) {
-
+
XKit.window.show("Corrupt storage","XKit noticed that your browser's storage area allocated for XKit is corrupt and will now reset itself and clear the storage area so it can save it data and function properly.<br/><br/><b>Your browser returned the following error message:</b><br/>\"" + last_error + "\"<br/><br/>If you keep seeing this message, it means your Chrome's profile file is corrupt, please click on the button below for more information and learn how to fix it.", "error","<div class=\"xkit-button default\" id=\"xkit-bridge-reset-and-continue\">OK</div><a href=\"http://xkit-extension.tumblr.com/post/52742121604/chrome-system-restores-corrupt-profile-settings-and\" class=\"xkit-button\">Didn't fix your problem?</a>");
$("#xkit-bridge-reset-and-continue").click(function() {
GM_flushStorage(function() {
init_bridge();
});
});
return;
-
+
}
}
@@ -127,7 +127,7 @@ function GM_deleteAllValues(callback) {
storage.get(function(items) {
for (key in items) {
storage.remove(key);
- }
+ }
storage.clear();
callback();
});
@@ -161,21 +161,21 @@ function GM_setValue(name, value) {
var m_name = name;
m_object[ m_name ] = value;
xkit_storage[name] = value;
- storage.set(m_object);
+ storage.set(m_object);
return true;
}
-
+
function GM_log(message) {
-
+
console.log(message);
}
function GM_openInTab(url) {
-
+
return window.open(url, "_blank");
-
+
}
function GM_listValues() {
@@ -201,84 +201,58 @@ function GM_listValues() {
function GM_xmlhttpRequest(settings) {
try {
-
+
var request = new XMLHttpRequest();
var timeout = 1;
-
-// if (settings['url'].indexOf("http://") != -1 && settings['url'].indexOf(".tumblr.com/api/") != -1) {
-//
-// try {
-// console.log(" -- Bridge forwarding to Bridge! (API v1)");
-// settings['url'] = XKit.servers.next() + "/seven/bridge.php?url=" + settings['url'];
-// timeout = 1500;
-// } catch(e) {
-// console.log(" -- Bridge forwarding to Bridge FAIL..!");
-// }
-//
-// }
-//
-// if (settings['url'].indexOf("http://") != -1 && settings['url'].indexOf("tumblr.com/archive") != -1) {
-//
-// try {
-// console.log(" -- Bridge forwarding to Bridge! (Archive)");
-// settings['url'] = XKit.servers.next() + "/seven/bridge.php?url=" + settings['url'];
-// timeout = 700;
-// } catch(e) {
-// console.log(" -- Bridge forwarding to Bridge FAIL..!");
-// }
-//
-// }
-
-
-
+
if (settings['url'].indexOf("http://") != -1 && settings['url'].indexOf("tumblr.com/svc/") != -1) {
-
+
try {
console.log(" -- Bridge forwarding to HTTPS!");
settings['url'] = settings['url'].replace("http://","https://");
timeout = 1;
} catch(e) {
console.log(" -- Bridge forwarding to HTTPS FAIL..!");
}
-
- }
-
+
+ }
+
settings['url'] = settings['url'].replace("http://api.tumblr.com","https://api.tumblr.com");
-
- if (settings['url'] == "http://www.tumblr.com/dashboard" || settings['url'] == "http://www.tumblr.com/dashboard/") {
-
+
+ if (settings['url'].indexOf("http://www.tumblr.com/") == 0) {
+
try {
console.log(" -- Bridge forwarding to HTTPS! (Dashboard)");
settings['url'] = settings['url'].replace("http://","https://");
timeout = 1;
} catch(e) {
console.log(" -- Bridge forwarding to HTTPS FAIL..!");
}
-
- }
-
+
+ }
+
setTimeout(function() {
-
+
if (settings['method'] === "POST") {
request.open('POST', settings['url'], true);
} else {
request.open('GET', settings['url'], true);
}
- request.onreadystatechange = function (oEvent) {
- if (request.readyState === 4) {
- if (request.status === 200) {
+ request.onreadystatechange = function (oEvent) {
+ if (request.readyState === 4) {
+ if (request.status === 200) {
if (typeof settings['onload'] !== "undefined") {
settings['onload'].call(request, request);
}
- } else {
+ } else {
if (typeof settings['onerror'] !== "undefined") {
settings['onerror'].call(request, request);
}
- }
- }
- };
-
+ }
+ }
+ };
+
if (typeof settings['headers'] !== "undefined") {
for (var obj in settings['headers']) {
request.setRequestHeader(obj, settings['headers'][obj]);
@@ -297,7 +271,7 @@ function GM_xmlhttpRequest(settings) {
} else {
request.send(null);
}
-
+
}, timeout);
} catch(e) {
@@ -1,5 +1,5 @@
//* TITLE Audio Downloader **//
-//* VERSION 2.0 REV D **//
+//* VERSION 2.0 REV F **//
//* DESCRIPTION Lets you download audio posts hosted on Tumblr **//
//* DEVELOPER STUDIOXENIX **//
//* FRAME false **//
@@ -11,6 +11,7 @@ XKit.extensions.audio_downloader = new Object({
slow: true,
running: false,
+ apiKey: "fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4",
button_icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6QkY1MzdFN0ExNTU3MTFFMzlCNjJGNTNDQTgzRjc3M0UiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6QkY1MzdFN0IxNTU3MTFFMzlCNjJGNTNDQTgzRjc3M0UiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpCRjUzN0U3ODE1NTcxMUUzOUI2MkY1M0NBODNGNzczRSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpCRjUzN0U3OTE1NTcxMUUzOUI2MkY1M0NBODNGNzczRSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PuxbowMAAACcSURBVHja7NTBDYAgDABA6gKMQpzEURiFERyFERiFEZCamlTToqIvY5O+aO/RlEIpxUgBAOJDrQejxGBejB/7EobhcX0epl/3lZY2PoAiGhyzNXMHhD12hxHoOjC39e8wAv3dOakYgfMFaD72aRjOLzWgxOfUxNj8sjJwJ/WoGIGTgE1afRMjMDAotGoxQbu07OImurDj2VdaBBgAbglVZHbAZ/wAAAAASUVORK5CYII=",
@@ -52,43 +53,33 @@ XKit.extensions.audio_downloader = new Object({
download: function(post_id, username) {
- var json_page = "http://" + username + ".tumblr.com/api/read/json?id=" + post_id;
+ var api_url = "https://api.tumblr.com/v2/blog/" + username + ".tumblr.com/posts" + "?api_key=" + XKit.extensions.audio_downloader.apiKey + "&id=" + post_id;
GM_xmlhttpRequest({
method: "GET",
- url: json_page,
+ url: api_url,
+ json: true,
onload: function(response) {
-
- var m_data = response.responseText.replace("var tumblr_api_read = {", "{");
- m_data = m_data.substring(0, m_data.length - 2);
-
- console.log(m_data);
-
try {
- var obj = JSON.parse(m_data);
+ var data = JSON.parse(response.responseText);
+ var obj = data.response;
if (typeof obj.posts[0] === "undefined") {
return XKit.extensions.audio_downloader.show_error("13");
}
- if (typeof obj.posts[0]["audio-player"] === "undefined" ||obj.posts[0]["audio-player"] === "") {
- return XKit.extensions.audio_downloader.show_error("14");
- }
-
- var m_text = obj.posts[0]["audio-player"];
-
- var m_start = m_text.indexOf("?audio_file=") + 12;
- var m_end = m_text.indexOf("\"", m_start);
- var m_url = decodeURIComponent(m_text.substring(m_start, m_end));
- if (m_url.indexOf('&color=') !== -1) {
- m_url = m_url.substring(0, m_url.indexOf('&color='));
+ if (obj.posts[0].audio_type == "tumblr") {
+ m_url = obj.posts[0]['audio_url'];
+ if (m_url.indexOf('https://www.tumblr.com/audio_file/') == 0) {
+ m_url = 'http://a.tumblr.com/' + m_url.substr(m_url.lastIndexOf('/') + 1) + 'o1.mp3';
+ }
}
var m_id = "audio_" + XKit.extensions.audio_downloader.make_id();
- var audio_name = $("#post_" + post_id).find(".id3_tags").find(".track_name").html();
- var audio_author = $("#post_" + post_id).find(".id3_tags").find(".artist_name").html();
+ var audio_name = obj.posts[0]['track_name'];
+ var audio_author = obj.posts[0].artist;
if (typeof audio_author == "undefined" || audio_author == "") {
audio_author = "unknown";
@@ -1,5 +1,5 @@
//* TITLE Find Inactives **//
-//* VERSION 0.1 REV C **//
+//* VERSION 0.1 REV D **//
//* DESCRIPTION Find the inactive blogs you follow **//
//* DEVELOPER STUDIOXENIX **//
//* DETAILS This extension lets you find the blog that haven't been updated for over 30 days. Just go to list of blogs you follow, then click on &quot;Find Inactive Blogs&quot; button below your Crushes to get started. **//
@@ -9,6 +9,7 @@
XKit.extensions.find_inactives = new Object({
running: false,
+ apiKey: "fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4",
timeout_time: 300,
@@ -161,10 +162,12 @@ XKit.extensions.find_inactives = new Object({
}
+ var api_url = "https://api.tumblr.com/v2/blog/" + XKit.extensions.find_inactives.people_list[XKit.extensions.find_inactives.people_index] + ".tumblr.com/info" + "?api_key=" + XKit.extensions.find_inactives.apiKey;
+
GM_xmlhttpRequest({
- method: "GET",
- url: "http://" + XKit.extensions.find_inactives.people_list[XKit.extensions.find_inactives.people_index] + ".tumblr.com/api/read/json?rd=" + XKit.tools.random_string(),
- json: false,
+ method: "GET",
+ url: api_url,
+ json: true,
onerror: function(response) {
// Probably a bug in the list.
setTimeout(function() { XKit.extensions.find_inactives.next_person(); }, 800);
@@ -180,9 +183,8 @@ XKit.extensions.find_inactives = new Object({
XKit.progress.value("find-inactives", perc);
- var data = JSON.parse(response.responseText.substring(22, response.responseText.length - 2));
- console.log(data);
- var post_date = new Date(data.posts[0]["unix-timestamp"] * 1000);
+ var data = JSON.parse(response.responseText).response;
+ var post_date = new Date(data.blog.updated * 1000);
var days = Math.round(Math.abs((post_date.getTime() - new Date().getTime())/(24*60*60*1000)));
Oops, something went wrong.

0 comments on commit b308886

Please sign in to comment.