Skip to content

Instantly share code, notes, and snippets.

@YungSang
Last active February 6, 2021 05:33
Show Gist options
  • Save YungSang/7920406 to your computer and use it in GitHub Desktop.
Save YungSang/7920406 to your computer and use it in GitHub Desktop.
[Deprecated] Taberareloo 用パッチ: Tumblr のポストの仕様変更に対応させる。 *Taberareloo v3.0.7 で対応されました。と思ったら、完全版では無かったので、再度有効化。v3.0.9 で対応。
// ==Taberareloo==
// {
// "name" : "Fix Post to Tumblr"
// , "description" : "Follow the latest change to post to Tumblr"
// , "include" : ["background"]
// , "version" : "0.2.6"
// , "downloadURL" : "https://gist.github.com/YungSang/7920406/raw/patch.model.tumblr.post.tbrl.js"
// }
// ==/Taberareloo==
(function() {
var version = chrome.runtime.getManifest().version;
if (semver.gte(version, '3.0.9')) {
alert("This patch has been merged into Taberareloo 3.0.9. Going to uninstall it.");
Patches.uninstall(Patches['patch.model.tumblr.post.tbrl.js']);
return;
}
update(Models['Tumblr'], {
_post : function (form) {
return request(Tumblr.TUMBLR_URL + 'svc/secure_form_key', {
method : 'POST',
headers : {
'X-tumblr-form-key' : form.form_key
}
}).addCallback(function (res) {
var secure_form_key = res.getResponseHeader('X-tumblr-secure-form-key');
return request(Tumblr.TUMBLR_URL + 'svc/post/update', {
headers : {
'Content-Type' : 'application/json',
'X-tumblr-puppies' : secure_form_key
},
sendContent : JSON.stringify(form)
});
});
},
post : function (ps) {
var self = this;
if(TBRL.Config.post['tumblr_default_quote']){
ps = update({}, ps);
ps.flavors = update({}, ps.flavors);
delete ps['flavors']['html'];
}
var endpoint = Tumblr.TUMBLR_URL + 'new/' + ps.type;
return this.postForm(function(){
return self.getForm(endpoint).addCallback(function postUpdate(form){
var type;
type = ps.type.capitalize();
return Tumblr[type].convertToForm(ps).addCallback(function(form2){
// merging forms
update(form, form2);
self.appendTags(form, ps);
if (TBRL.Config.post.multi_tumblelogs && !Tumblr.blogs.some(function(id){ return id === form.channel_id; })) {
throw new Error(chrome.i18n.getMessage('error_notLoggedin', form.channel_id));
}
return (function () {
if (type === 'Photo') {
if (form['photo[]']) {
return request(Tumblr.TUMBLR_URL + 'svc/post/upload_photo', {
sendContent: form
}).addCallback(function(res){
var response = JSON.parse(res.response);
if (response.meta && response.meta.msg === 'OK' && response.meta.status === 200) {
delete form['photo[]'];
form['images[o1]'] = response.response[0].url;
form['post[photoset_layout]'] = '1';
form['post[photoset_order]'] = 'o1';
return self._post(form);
}
return res;
});
} else {
form['images[o1]'] = form['photo_src[]'];
form['post[photoset_layout]'] = '1';
form['post[photoset_order]'] = 'o1';
}
}
return self._post(form);
}()).addErrback(function(err){
if (self.retry) {
throw err;
}
Tumblr.form_key = Tumblr.channel_id = null;
self.retry = true;
return self.getForm(endpoint).addCallback(postUpdate);
});
});
});
});
},
favor : function (ps) {
// メモをreblogフォームの適切なフィールドの末尾に追加する
var form = ps.favorite.form;
var that = this;
this.trimReblogInfo(form);
return Tumblr[ps.type.capitalize()].convertToForm({
description : ps.description
}).addCallback(function(res) {
items(res).forEach(function(item) {
var name = item[0], value = item[1];
if (!value) {
return;
}
if (form[name]) {
form[name] += '\n\n' + value;
}
else {
form[name] = value;
}
});
that.appendTags(form, ps);
return that.postForm(function(){
return that._post(form);
});
});
}
});
var jobs = [];
var posting = false;
addAround(Models['Tumblr'], '_post', function(proceed, args, target, methodName) {
var deferred = new Deferred();
jobs.push({
deferred : deferred,
proceed : proceed,
args : args,
target : target
});
return deferred;
});
setInterval(function () {
if (posting || (jobs.length === 0)) {
return;
}
posting = true;
var job = jobs.shift();
job.proceed(job.args).addCallback(function (res) {
job.deferred.callback(res);
posting = false;
}).addErrback(function (e) {
job.deferred.errback(e);
posting = false;
});
}, 500);
})();
@Constellation
Copy link

https://gist.github.com/Constellation/7932734 こんなもんでどうでしょ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment