Skip to content

Instantly share code, notes, and snippets.

@uu59
Created August 8, 2012 21:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uu59/3299085 to your computer and use it in GitHub Desktop.
Save uu59/3299085 to your computer and use it in GitHub Desktop.
techcrunch ja
{
"manifest_version": 2,
"name": "techcrunch",
"version": "1.1.1",
"description": "説明",
"icons":
{
},
"content_scripts": [
{
"js": [
"techcrunch.user.js"
],
"matches": [
"http://jp.techcrunch.com/archives/*"
]
}
]
}
// ==UserScript==
// @name techcrunch
// @namespace http://uu59.org/
// @version 1.1.0
// @include http://jp.techcrunch.com/archives/*
// ==/UserScript==
var url = document.evaluate('//a[text() = "原文へ"]/@href|//div[@class="post_subheader"]//a[contains(@href, "http://techcrunch.com/")]/@href', document, null, 2, null).stringValue;
var proxy = "http://xhr2-proxy.herokuapp.com";
var targets = [
'//h1[@class="headline"]',
'//div[@class="meta-info"]/h4',
'//div[@class="body-copy"]',
//'//div[@id="module-post-detail"]',
];
var query = targets.reduce(function(r, c){
r += "&xpathes[]=" + encodeURIComponent(c);
return r;
}, "");
var xhr = new XMLHttpRequest();
xhr.open('GET', proxy + "/proxy?url=" + encodeURIComponent(url) + query, true);
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
var result = JSON.parse(xhr.responseText);
var html = '<a href="'+url+'">'+result[targets[0]]+'</a>' + result[targets[1]] + result[targets[2]];
document.querySelector('#container').style.width = "auto";
var entry = document.querySelector('#col1');
entry.style.width = "50%";
var div = document.createElement('div');
var rects = entry.getClientRects()[0];
div.innerHTML = html;
div.style.textAlign = "left";
div.style.position = "absolute";
div.style.background = "#fff";
div.style.top = rects.top + "px";
div.style.left = (rects.right + 5) + "px";
div.style.width = (document.body.clientWidth - entry.clientWidth - 15) + "px";
document.body.appendChild(div);
}
};
xhr.send(null);
// 翻訳者情報を上に持ってくる
var translator = document.evaluate('//p[contains(string(self::node()), "翻訳")]', document, null, 9, null).singleNodeValue;
document.querySelector('.post_subheader').appendChild(translator);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment