Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
2ch hatena star
// ==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
You can’t perform that action at this time.