Skip to content

Instantly share code, notes, and snippets.

@poochin
Created January 16, 2012 04:49
Show Gist options
  • Save poochin/1619121 to your computer and use it in GitHub Desktop.
Save poochin/1619121 to your computer and use it in GitHub Desktop.
tumblr life 1.0.0pre8 に標準以外のチャンネルに reblog する機能を追加するパッチ
diff -Naru 1.0_0/script.js 1.0_0p/script.js
--- 1.0_0/script.js 2012-01-16 13:42:39.771423716 +0900
+++ 1.0_0p/script.js 2012-01-16 13:47:48.915422946 +0900
@@ -12,6 +12,14 @@
(function(w, content_window, d) { 'use strict';
+var channels = (function(objs) {
+ var names = [];
+ for (var i = 1; i < objs.length; ++i) {
+ names.push(objs[i].querySelector('a').href.match(/[^/]+$/)[0]);
+ }
+ return names;
+})(document.querySelectorAll('#user_channels > li'));
+
var GM_addStyle = w.GM_addStyle || function(css) {
var style = d.createElement('style');
@@ -654,14 +662,25 @@
else if (e.target.className) {
var action = (/^tumblrlife-reblog-(.+)$/.exec(e.target.className) || [])[1];
e.preventDefault();
- this.reblog(action);
+ if (action == 'add-to-channel') {
+ this.reblog(action + ':' + e.target.innerText);
+ }
+ else {
+ this.reblog(action);
+ }
}
break;
}
}
+var menu_channels = [];
+for (var i = 0; i < channels.length; ++i) {
+ menu_channels.push('<li class="tumblrlife-reblog-add-to-channel">' + channels[i] + '</li>');
+}
+
var menu_template_menu = [
'<ul>',
+ menu_channels.join(''),
'<li class="tumblrlife-reblog-add-to-queue">add to queue</li>',
'<li class="tumblrlife-reblog-private">private</li>',
'<li class="tumblrlife-reblog-manually"><a href="${href}" target="_blank">reblog manually</a></li>',
@@ -707,19 +726,23 @@
return;
}
+ var chid = (!state || state.indexOf(':') == -1 ? 0 : state.split(':')[1]);
+ state = (chid == 0 ? state : state.split(':')[0]);
+
this.reblogging = true;
container.className += ' tumblrlife-reblogging';
this.reblogContainer.innerHTML = 'reblogging...';
get(this.postURL,
function() {
- post(self.postURL, self.query(this.responseText, state),
+ post(self.postURL, self.query(this.responseText, state, chid),
function(data) {
var id = self.id;
self.reblogging = false;
container.className = container.className.replace('tumblrlife-reblogging', 'tumblrlife-reblogged');
menu_container.removeEventListener('click', self, false);
menu_container.innerHTML = 'reblogged' + (state ? {
+ 'add-to-channel': ' (ch: ' + chid + ')',
'add-to-queue': ' (queue)',
'private' : ' (private)'
}[state] : '');
@@ -752,7 +775,7 @@
}
}
-function menuQuery(html, state) {
+function menuQuery(html, state, chid) {
var options, queries = {}, i, o;
options = createDocumentFromString(html).querySelectorAll('#edit_post input, #edit_post textarea, #edit_post select');
@@ -774,6 +797,10 @@
'private' : 'private'
}[state] || '0';
+ if (chid) {
+ queries['channel_id'] = chid;
+ }
+
queries['post[tags]'] = this.menuContainer.querySelector('input.tumblrlife-tags').value;
delete queries['preview_post'];
@s-aska
Copy link

s-aska commented Jan 16, 2012

pull req するといいんじゃないかな 。
https://github.com/yoko/userscripts/blob/master/tumblr_life.user.js

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