TaberarelooがTwitterが動画GIF対応したことに伴い動画GIFも投稿できるように対応。
YungSang NaNさんが早速、パッチを作成してくれました!!
GIF animation のアップロードに対応させました。
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
// ==Taberareloo== | |
// { | |
// "name" : "Patch for Twitter Model" | |
// , "description" : "Patch for Twitter model" | |
// , "include" : ["background"] | |
// , "version" : "0.2.2" | |
// , "downloadURL" : "https://gist.github.com/YungSang/9205023/raw/patch.model.twitter.tbrl.js" | |
// } | |
// ==/Taberareloo== | |
(function () { | |
var version = chrome.runtime.getManifest().version; | |
version = version.split('.'); | |
if (version.length > 3) { | |
version.pop(); | |
} | |
version = version.join('.'); | |
if (semver.gte(version, '3.0.12')) { | |
setTimeout(function () { | |
Patches.uninstall(Patches['patch.model.twitter.tbrl.js'], true); | |
}, 500); | |
Patches.install('https://raw.githubusercontent.com/YungSang/patches-for-taberareloo/ready-for-v4.0.0/patches/patch.model.twitter.createstatus.tbrl.js', true); | |
return; | |
} | |
setTimeout(function () { | |
if (Patches['patch.model.twitter.upload.tbrl.js']) { | |
Patches.uninstall(Patches['patch.model.twitter.upload.tbrl.js'], true); | |
} | |
if (Patches['patch.model.twitter.createstatus.tbrl.js']) { | |
Patches.uninstall(Patches['patch.model.twitter.createstatus.tbrl.js'], true); | |
} | |
}, 500); | |
addAround(Models['Twitter'], 'createStatus', function (proceed, args, target, methodName) { | |
var ps = update({}, args[0]); | |
if (ps.body) { | |
ps.body = ps.body.trimTag().replace(/\s+/g, ' '); | |
} | |
return proceed([ps]).addCallback(function (status) { | |
return status; | |
}).addErrback(function(e) { | |
console.log(e.message); | |
var over = ''; | |
if (typeof e.message === 'string') { | |
over = e.message.extract(/post \((\d+) over\)/); | |
} | |
if (!over) { | |
throw e; | |
} | |
var len; | |
if (ps.body) { | |
len = ps.body.length; | |
ps.body = ps.body.slice(0, -1 * over); | |
over -= len; | |
} | |
if ((over > 0) && ps.item) { | |
len = ps.item.length; | |
ps.item = ps.item.slice(0, -1 * over); | |
over -= len; | |
} | |
if ((over > 0) && ps.description) { | |
len = ps.description.length; | |
ps.description = ps.description.slice(0, -1 * over); | |
over -= len; | |
} | |
if (over > 0) { | |
throw e; | |
} | |
return target[methodName](ps).addCallback(function (status) { | |
return status; | |
}); | |
}); | |
}); | |
update(Models['Twitter'], { | |
update : function (status, media_ids) { | |
var self = this; | |
return this.getToken().addCallback(function (token) { | |
var sendContent = { | |
authenticity_token : token.authenticity_token, | |
place_id : '', | |
status : status, | |
tagged_users : '' | |
}; | |
if (media_ids) { | |
sendContent.media_ids = media_ids; | |
} | |
return request(self.URL + '/i/tweet/create', { | |
sendContent : sendContent | |
}).addErrback(function (e) { | |
var res = e.message; | |
var json = res.responseText; | |
try { | |
json = JSON.parse(json); | |
throw new Error(json.message); | |
} catch (e2) { | |
throw e2; | |
} | |
}); | |
}); | |
}, | |
upload : function (ps, status, file) { | |
var self = this; | |
var UPLOAD_URL = 'https://upload.twitter.com/i/media/upload.iframe'; | |
var SIZE_LIMIT = 3145728; | |
return this.getToken().addCallback(function (token) { | |
return fileToBinaryString(file).addCallback(function (binary) { | |
return request(UPLOAD_URL, { | |
queryString : { | |
origin : self.URL | |
}, | |
sendContent : { | |
authenticity_token : token.authenticity_token, | |
iframe_callback : '', | |
media : window.btoa(binary), | |
upload_id : (new Date()).getTime(), | |
origin : self.URL | |
} | |
}).addCallback(function (res) { | |
var html = res.responseText; | |
var json = html.extract(/parent\.postMessage\(JSON\.stringify\((\{.+\})\), ".+"\);/); | |
json = JSON.parse(json); | |
return self.update(status, json.media_id_string); | |
}); | |
}); | |
}); | |
}, | |
getActualLength : function (status) { | |
var ret = status.split('\n').map(function (s) { | |
s = s.replace(/(https:\/\/[^ ]+)/g, '12345678901234567890123'); | |
s = s.replace(/(http:\/\/[^ ]+)/g, '1234567890123456789012'); | |
return s; | |
}).join('\n'); | |
return ret.length; | |
} | |
}); | |
})(); |
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
// ==Taberareloo== | |
// { | |
// "name" : "Upload an image to Twitter" | |
// , "description" : "Upload an image to Twitter" | |
// , "include" : ["background"] | |
// , "version" : "0.3.1" | |
// , "downloadURL" : "https://gist.github.com/YungSang/9205023/raw/patch.model.twitter.upload.tbrl.js" | |
// } | |
// ==/Taberareloo== | |
(function() { | |
setTimeout(function () { | |
if (Patches['patch.model.twitter.upload.tbrl.js']) { | |
Patches.uninstall(Patches['patch.model.twitter.upload.tbrl.js'], true); | |
} | |
}, 500); | |
})(); |
attripからひとこと!
早速パッチを入れました!ありがとうございます!
https://plus.google.com/109448778834120388056/posts/YP4P1t72UUh