Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
tombfix, tombloo, InoReader, Firefox, userscript
// ==UserScript==
// @name InoReaderTombloo
// @namespace http://d.hatena.ne.jp/serian
// @description derived from GoogleReader + Tombloo
// @include https://inoreader.com/*
// @version 0.0.1
// ==/UserScript==
(function(){
GM_addStyle(" \
.TMBL_posted, \
.TMBL_posted a{ \
color : silver !important; \
} \
.TMBL_posted .item_body a{ \
color : dimgray !important; \
} \
.TMBL_posted img{ \
opacity: 0.5; \
} \
");
var win = unsafeWindow;
var doc = win.document;
var tombloo = Tombloo;
win.addEventListener('keydown', function(e){
// shift-t
if(e.keyCode == 84 && e.shiftKey) { // T
// if(e.keyCode == 82 && e.shiftKey) { // R
share(); //http://www.programming-magic.com/file/20080205232140/keycode_table.html
}
}, true);
function share(){
var item = get_current_item();
if(!item) return;
// for Tombloo
var ctx = update({
document : doc,
window : win,
selection : '' + win.getSelection(),
target : item.target,
event : {},
title : item.title,
mouse : null,
menu : null,
}, win.location);
var ext = tombloo.check(ctx)[0];
tombloo.share(ctx,ext, true);
addClass(item.parent, 'TMBL_posted');
}
// Utility
function update(t, s){
for(var p in s)
t[p] = s[p];
return t;
}
function $x(exp, context){
context = context || document;
return document.evaluate(exp, context, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function addClass(e, cl){
if(!e || !cl) return false;
e.className
? (!~e.className.toLowerCase().split(/\s+/).indexOf(cl.toLowerCase())) && (e.className +=' '+cl)
: (e.className = cl);
}
function get_current_item(){
var item = {
parent: null,
body: null,
target: null,
feed: {
channel: {
link: null
}
}
}, link;
try {
item.parent = $x('//div[contains(@class,"article_current")]');
item.title = $x('//div[contains(@class,"article_current")]/*/div[@class="article_title"]/a').textContent;
item.target = $x('//div[contains(@class,"article_current")]/*/div[@class="article_title"]/a');
item.link = $x('//div[contains(@class,"article_current")]/*/div[@class="article_title"]/a/@href');
if(item.target.href.startsWith("http://www.jiji.com"))
{
var jiji = item.target.href;
// item.target.href = jiji.split("?")[0] + "?" + jiji.match(/&g=\w+/)[0].substring(1) + jiji.match(/&k=\d+/)[0];
// item.target.href = item.target.href.replace("&m=rss",""); // for jiji.com
item.target.href = jiji.split("&").slice(0,2).join("&");
}
if(!item.parent || !item.target){
throw 'get_current_item error';
} else {
return item;
}
} catch (e) {
return null;
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment