Skip to content

Instantly share code, notes, and snippets.

@YungSang
Last active December 29, 2015 02:59
Show Gist options
  • Save YungSang/7604503 to your computer and use it in GitHub Desktop.
Save YungSang/7604503 to your computer and use it in GitHub Desktop.
[Deprecated] Taberareloo パッチ: reblog advent calend*e*r mach 33 イベント専用、高速リブログ用パッチ
// ==Taberareloo==
// {
// "name" : "Post to RAC33"
// , "description" : "Post to reblogadventcalendermach33.tumblr.com"
// , "include" : ["background", "content"]
// , "match" : ["*://*/*"]
// , "version" : "0.1.1"
// , "downloadURL" : "https://gist.github.com/YungSang/7604503/raw/patch.post.to.rac33.tbrl.js"
// }
// ==/Taberareloo==
(function() {
var RAC33 = 'Tumblr - reblog advent calend*e*r...';
var EVENT = 'Taberareloo.RAC33';
if (inContext('background')) {
/***********
* Create Dynamic Context Menu
*/
var name = 'RAC33 - Taberareloo';
Menus._register({
title : name,
contexts : ['all'],
onclick: function(info, tab) {
chrome.tabs.sendMessage(tab.id, {
request: 'contextMenusForRAC33',
content: info
});
}
}, null, 'Taberareloo');
Menus._register({
type : 'separator',
contexts : ['all']
}, null, 'Taberareloo');
Menus.create();
TBRL.setRequestHandler('updateContextMenusForRAC33', function (req, sender, func) {
chrome.contextMenus.update(Menus[name].id, {
title : 'RAC33 - ' + req.extractor
}, function() {});
});
/*
* Create Dynamic Context Menu
***********/
/***********
* Post To RAC33
*/
TBRL.setRequestHandler('postToRAC33', function (req, sender, func) {
var ps = req.content;
var posters = [Models[RAC33]];
posters = posters.filter(function (m) {
return (ps.favorite && ps.favorite.name === (m.typeName || m.name)) || (m.check && m.check(ps));
});
if (!posters.length) {
alert(chrome.i18n.getMessage('error_noPoster', ps.type.capitalize()));
} else {
TBRL.Service.post(ps, posters);
}
});
var CHROME_GESTURES = 'jpkfjicglakibpenojifdiepckckakgk';
var CHROME_KEYCONFIG = 'okneonigbfnolfkmfgjmaeniipdjkgkl';
var action = {
group : 'Taberareloo',
actions : [{
name : EVENT
}]
};
chrome.runtime.sendMessage(CHROME_GESTURES, action, function(res) {});
chrome.runtime.sendMessage(CHROME_KEYCONFIG, action, function(res) {});
/*
* Post To RAC33
***********/
return;
}
/***********
* Post To RAC33
*/
TBRL.setRequestHandler('contextMenusForRAC33', function (req, sender, func) {
var content = req.content;
var ctx = {};
var query = null;
switch (content.mediaType) {
case 'video':
ctx.onVideo = true;
ctx.target = $N('video', {
src: content.srcUrl
});
query = 'video[src="'+content.srcUrl+'"]';
break;
case 'audio':
ctx.onVideo = true;
ctx.target = $N('audio', {
src: content.srcUrl
});
query = 'audio[src="'+content.srcUrl+'"]';
break;
case 'image':
ctx.onImage = true;
ctx.target = $N('img', {
src: content.srcUrl
});
query = 'img[src="'+content.srcUrl+'"]';
break;
default:
if (content.linkUrl) {
// case link
ctx.onLink = true;
ctx.link = ctx.target = $N('a', {
href: content.linkUrl
});
ctx.title = content.linkUrl;
query = 'a[href="'+content.linkUrl+'"]';
}
break;
}
update(ctx, TBRL.createContext((query && document.querySelector(query)) || TBRL.getContextMenuTarget()));
TBRL.extract(ctx, Extractors.check(ctx)[0]).addCallback(function(ps) {
chrome.runtime.sendMessage(TBRL.id, {
request : "postToRAC33",
content : checkHttps(update({
page : ctx.title,
pageUrl : ctx.href
}, ps))
});
});
});
var isDashboard = /^https?:\/\/www\.tumblr\.com\/(?:(?:dashboard|likes)|(?:liked\/by|show|tagged|blog)\/)/.test(location.href);
function postToRAC33(ev) {
var ctx = TBRL.createContext();
var ext = Extractors.check(ctx)[0];
if (isDashboard) {
var current;
if (!('selectionStart' in ev.target && ev.target.disabled !== true)) {
current = UserScripts['Dashboard + Taberareloo'].getCurrentItem();
if (!current) {
return;
}
stop(ev);
}
else {
return;
}
var post = current.classList.contains('post') ? current : current.querySelector('.post');
var sel = createFlavoredString(window.getSelection());
ctx = update({
document : document,
window : window,
selection : (sel.raw) ? sel : null,
target : post,
event : {},
title : null,
mouse : null,
menu : null
}, window.location);
ext = Extractors['ReBlog - Dashboard'];
if (!ext.check(ctx)) {
return;
}
}
TBRL.extract(ctx, ext).addCallback(function(ps) {
chrome.runtime.sendMessage(TBRL.id, {
request : "postToRAC33",
content : checkHttps(update({
page : ctx.title,
pageUrl : ctx.href
}, ps))
});
});
}
window.addEventListener(EVENT, postToRAC33, false);
document.addEventListener('unload', function() {
window.removeEventListener(EVENT, postToRAC33, false);
}, false);
/*
* Post To RAC33
***********/
/*
* Create Dynamic Context Menu
*/
function updateContextMenu(event) {
var ctx = {};
switch (event.target.nodeName) {
case 'IMG':
ctx.onImage = true;
ctx.target = event.target;
break;
case 'A':
ctx.onLink = true;
ctx.link = event.target;
ctx.title = event.target.title || event.target.text.trim() || event.target.href;
break;
}
update(ctx, TBRL.createContext(event.target));
var extractor = Extractors.check(ctx)[0];
chrome.runtime.sendMessage(TBRL.id, {
request : "updateContextMenusForRAC33",
extractor : extractor.name
}, function(res) {});
}
window.addEventListener("contextmenu", function(event) {
updateContextMenu(event);
}, true);
window.addEventListener("contextmenu", function(event) {
busyWait(50);
}, false);
function busyWait(waitMilliSeconds) {
var now = new Date().getTime();
var end = now + waitMilliSeconds;
while (now < end) {
now = new Date().getTime();
}
}
})();