Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saitamanodoruji/4124810 to your computer and use it in GitHub Desktop.
Save saitamanodoruji/4124810 to your computer and use it in GitHub Desktop.
Twitter の会話を Tumblr に Chat でポストする Tombloo パッチ
Tombloo.Service.extractors.register(
{
name: 'Conversation - Twitter',
RE: /^https?:\/\/twitter\.com\/[^\/]+(?:\/status)?/,
RE_STATUS: /^https?:\/\/twitter\.com\/[^\/]+\/status/,
ICON: 'http://twitter.com/favicon.ico',
check: function(ctx){
return this.RE.test(ctx.href);
},
extract : function (ctx) {
var tweets, id, text, permalink, body = [];
if (this.RE_STATUS.test(ctx.href)) {
tweets = ctx.document.querySelectorAll('.tweet:not(.original-tweet), .tweet-embed');
} else {
tweets = ctx.document.querySelectorAll('.tweet, .tweet-embed');
}
for (var i = 0; i < tweets.length; i++) {
id = tweets[i].querySelector('.username b, .nickname b, .p-nickname b');
text = tweets[i].querySelector('.js-tweet-text, .entry-content, .e-content');
permalink = tweets[i].querySelector('.tweet-timestamp, .view-details');
if (id && text && permalink) {
body.push(id.textContent + ":" + text.textContent.replace(/[\r\n]/g, '') + " [" + permalink.href + "]");
}
}
// alert(body.join('\n'));
return {
type: 'conversation',
body: body.join('\n'),
};
}
}
);
Tombloo.Service.extractors.register(
{
name: 'Conversation - Twitter (reverse)',
RE: /^https?:\/\/twitter\.com\/[^\/]+(?:\/status)?/,
RE_STATUS: /^https?:\/\/twitter\.com\/[^\/]+\/status/,
ICON: 'http://twitter.com/favicon.ico',
check: function(ctx){
return this.RE.test(ctx.href);
},
extract : function (ctx) {
var tweets, id, text, permalink, body = [];
if (this.RE_STATUS.test(ctx.href)) {
tweets = ctx.document.querySelectorAll('.tweet:not(.original-tweet), .tweet-embed');
} else {
tweets = ctx.document.querySelectorAll('.tweet, .tweet-embed');
}
for (var i = 0; i < tweets.length; i++) {
id = tweets[i].querySelector('.username b, .nickname b, .p-nickname b');
text = tweets[i].querySelector('.js-tweet-text, .entry-content, .e-content');
permalink = tweets[i].querySelector('.tweet-timestamp, .view-details');
if (id && text && permalink) {
body.push(id.textContent + ":" + text.textContent.replace(/[\r\n]/g, '') + " [" + permalink.href + "]");
}
}
// alert(body.reverse().join('\n'));
return {
type: 'conversation',
// body: body.join('\n'),
body: body.reverse().join('\n'),
};
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment