Created
March 22, 2010 05:44
-
-
Save a2ikm/339827 to your computer and use it in GitHub Desktop.
2ch hatena star
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name 2ch Star | |
// @namespace http://aerial.st/ | |
// @include http://*.2ch.net/test/read.cgi/* | |
// @include http://p2.2ch.net/p2/read.php?* | |
// @version 0.2 | |
// ==/UserScript== | |
// | |
// add Hatena Star on messages of 2ch (*.2ch.net, p2.2ch.net) | |
// | |
(function(){ | |
var $w = typeof unsafeWindow != "undefined" ? unsafeWindow : window; | |
var s = document.createElement('script'); | |
s.src = 'http://s.hatena.ne.jp/js/HatenaStar.js'; | |
s.charset = 'utf-8'; | |
s.type = 'text/javascript'; | |
document.body.appendChild(s); | |
var t = setInterval(function(){ | |
if($w.Hatena){ | |
init(); | |
clearInterval(t); | |
} | |
}, 100); | |
function init() { | |
if (window.location.href.match(/^http:\/\/p2\./)) { | |
initP2ch(); | |
} else { | |
initNormal2ch(); | |
} | |
} | |
function initNormal2ch() { | |
$w.Hatena.Star.EntryLoader.loadEntries = function(node){ | |
var threadTitle = (document.title); | |
// generate Permalink with http://pl2ch.kiseki.info | |
(window.location.href).match(/\/read\.cgi\/(\w+)\/(\d+)/); | |
var threadBaseUrl = 'http://pl2ch.kiseki.info/' + RegExp.$1 + '/' + RegExp.$2 + '/'; | |
var dts = document.getElementsByTagName('dt'); | |
var entries = []; | |
for (var i = 0, len = dts.length; i < len; i++) { | |
var dt = dts[i]; | |
var resNum = dt.textContent.match(/^\d{1,4}/); | |
var resUrl = threadBaseUrl + resNum; | |
var title = resNum + ' - ' + threadTitle; | |
var star_container = $w.Hatena.Star.EntryLoader.createStarContainer(); | |
var comment_container = $w.Hatena.Star.EntryLoader.createCommentContainer(); | |
dt.appendChild(star_container); | |
dt.appendChild(comment_container); | |
entries.push({ | |
'uri' : resUrl | |
, 'title' : title | |
, 'star_container' : star_container | |
, 'comment_container': comment_container | |
}); | |
} | |
return entries; | |
}; | |
if(!!window.opera) new $w.Hatena.Star.EntryLoader(); | |
} | |
function initP2ch() { | |
$w.Hatena.Star.EntryLoader.loadEntries = function(node){ | |
var threadTitle = (document.title); | |
// generate Permalink with http://pl2ch.kiseki.info | |
// location is like like : http://p2.2ch.net/p2/read.php?host=love6.2ch.net&bbs=magazin&key=1210781514&rc=697#r696 | |
var params = parseURLSearch(window.location.search); | |
var threadBaseUrl = 'http://pl2ch.kiseki.info/' + params['bbs'] + '/' + params['key'] + '/'; | |
var dts = document.getElementsByTagName('dt'); | |
var entries = []; | |
for (var i = 0, len = dts.length; i < len; i++) { | |
var dt = dts[i]; | |
var resNum = dt.textContent.match(/^\d{1,4}/); | |
var resUrl = threadBaseUrl + resNum; | |
var title = resNum + ' - ' + threadTitle; | |
var star_container = $w.Hatena.Star.EntryLoader.createStarContainer(); | |
var comment_container = $w.Hatena.Star.EntryLoader.createCommentContainer(); | |
dt.appendChild(star_container); | |
dt.appendChild(comment_container); | |
entries.push({ | |
'uri' : resUrl | |
, 'title' : title | |
, 'star_container' : star_container | |
, 'comment_container': comment_container | |
}); | |
} | |
return entries; | |
}; | |
if(!!window.opera) new $w.Hatena.Star.EntryLoader(); | |
} | |
function parseURLSearch(aSearch) { | |
var result = new Array(); | |
var array = aSearch.split('&'); | |
for (var i = 0, len = array.length; i < len; i++) { | |
var strs = array[i].split('='); | |
result[strs[0]] = strs[1]; | |
} | |
return result; | |
} | |
if (typeof(GM_addStyle) != 'function') { | |
function GM_addStyle(css) { | |
var head = document.getElementsByTagName('head'); | |
if (!!head) { | |
var style = document.createElement('style'); | |
style.type = 'text/css'; | |
style.innerHTML = css; | |
head[0].appendChild(style); | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment