Skip to content

Instantly share code, notes, and snippets.

@ailispaw
Last active December 28, 2021 04:33
Show Gist options
  • Save ailispaw/3aef8857c274e22f2b41 to your computer and use it in GitHub Desktop.
Save ailispaw/3aef8857c274e22f2b41 to your computer and use it in GitHub Desktop.
Fix Tumblr.getTumblelogs 2021.10
// ==Taberareloo==
// {
// "name" : "Fix Tumblr.getTumblelogs 2021.12"
// , "description" : "Fix Tumblr.getTumblelogs 2021.12"
// , "include" : ["background"]
// , "version" : "0.5.2"
// , "downloadURL" : "https://gist.githubusercontent.com/ailispaw/3aef8857c274e22f2b41/raw/patch.fix.tumblr.getTumblelogs.tbrl.js"
// }
// ==/Taberareloo==
(function() {
addAround(Tumblr, 'getTumblelogs', function (proceed, args, target, methodName) {
var self = target;
return request(Tumblr.LINK + 'dashboard').then(function (res) {
var html = res.responseText;
if (/{"isLoggedIn":false}/.test(html)) {
throw new Error(chrome.i18n.getMessage('error_notLoggedin', self.name));
}
var validJSON = html.match(/window\['___INITIAL_STATE___'\] ?= ?(.*?);\n/)[1];
validJSON = validJSON.replace(/:undefined,/g, ':null,');
validJSON = validJSON.replace(/:undefined]/g, ':null]');
validJSON = validJSON.replace(/:undefined}/g, ':null}');
self.STATE = JSON.parse(validJSON);
console.log(self.STATE);
return request(self.LINK + 'settings/account', {responseType : 'document'}).then(function (res) {
return request(Tumblr.LINK + 'api/v2/user/info', {
responseType : 'json',
queryString : {
fields : 'name,title,url'
},
headers : {
Authorization : 'Bearer ' + self.STATE.apiFetchStore.API_TOKEN
}
}).then(function (res) {
var json = res.response;
self.USER = json.response.user;
console.log(self.USER);
return self.USER.blogs.filter(function (blog) {
if (blog.primary) {
self.channel_id = blog.name;
self.blogs = [self.channel_id];
}
return !blog.primary
}).reverse().map(function (blog) {
Tumblr.blogs.push(blog.name);
return {
id : blog.name,
name : blog.title
};
});
});
});
});
});
setTimeout(function() {
Models.getMultiTumblelogs();
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment