Skip to content

Instantly share code, notes, and snippets.

@hazisarashi
Forked from rawegg/nicoLiveTweet.user.js
Created July 7, 2009 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hazisarashi/141962 to your computer and use it in GitHub Desktop.
Save hazisarashi/141962 to your computer and use it in GitHub Desktop.
ニコニコ生放送を視聴中、放送中にTwitterに見てる、放送してるをお知らせするボタンを加えるユーザースクリプトです。 元のソースは 生卵さんの制作された物を使用しています。 Greasemonkey, GreaseKitなどでご利用頂けます。http://hazisarashi.wordpress.com/tag/nicolivetweet/
// ==UserScript==
// @name            nicoLiveTweet
// @namespace       http://nicolivemac.wordpress.com/
// @description     ニコ生お知らせTwitterボタン
// @include         http://live.nicovideo.jp/watch/lv*
// ==/UserScript==
(function(){
// 設定
var ownerTitle = new Array("放送開始をTweet!","Now On Air!: ") ; // 放送開始ボタン(ボタン表示テキスト,挿入テキスト)
var guestTitle = new Array("ゲスト出演をTweet!","ゲスト出演中: ") ; // ゲスト通知ボタン(ボタン表示テキスト,挿入テキスト)
var watchTitle = new Array("視聴をTweet!","Watching: ") ; // 視聴通知ボタン(ボタン表示テキスト,挿入テキスト)
var hashTagText = "#nicolive"; // タグ(英字のみ)
// 放送情報取得
var liveTitle = document.getElementsByTagName("h1")[1].childNodes[0].innerHTML; // 放送タイトルの取得
var liveURL = location.href; // 放送URLの取得
// 主コメを縮小
var masterComment = document.getElementsByTagName("h1")[1].parentNode.getElementsByTagName("p")[2];
masterComment.style.height = "80px";
masterComment.style.overflow = "auto";
masterComment.style.border = "#CCC 1px solid";
masterComment.style.padding = "2px";
// GM_setValue, GM_getValueが使えない場合Cookieに書き込む
if ( typeof ( GM_setValue ) != 'function' && typeof ( GM_getValue ) != 'function') {
function GM_setValue(name, value) {
document.cookie = [
name, '=', escape(value),
';expires=', (new Date(new Date().getTime() + 365 * 1000 * 60 * 60 * 24)).toGMTString()
].join('');
}
function GM_getValue(name, value) {
var r = new RegExp(name + '=([^;]*)'), m;
if (m = document.cookie.match(r)) {
return unescape(m[1]);
}
return value;
}
function GM_delValue(name, value) {
if (GM_getValue(name, false))
document.cookie = name + '=;expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
} else {
var GM_delValue = GM_setValue;
}
// 初期設定
if( GM_getValue( 'trashboxActivityCheck', '' ) == '' ){
GM_setValue( 'trashboxActivityCheck', 0);
}
// Main Div Element 生成
var mainFrame = document.createElement("div");
mainFrame.id = "nicoLiveTweetBox";
mainFrame.style.zIndex = '0';
mainFrame.style.border = "#FFF 3px solid";
mainFrame.style.background = '#94e4e8';
mainFrame.style.padding = '3px 20px 3px 3px';
// ボタンをmainFrameに埋め込む
var pushElement = document.getElementById("console_container");
if( pushElement ){
pushElement = document.getElementById("WATCHHEADER");
mainFrame.appendChild( createButton( ownerTitle ) );
pushElement.style.position = 'relative';
mainFrame.style.position = 'absolute';
mainFrame.style.right = '7px';
mainFrame.style.width = '235px';
}else{
pushElement = document.getElementById("WATCHHEADER");
mainFrame.appendChild( createButton( guestTitle ) );
mainFrame.appendChild( createButton( watchTitle ) );
mainFrame.style.position = 'relative';
mainFrame.style.float = 'left';
mainFrame.style.margin = '-38px 0 0 290px';
}
mainFrame.appendChild( createCheckBox ( 'tagActivityCheck', ' tag ' ) );
mainFrame.appendChild( createCheckBox ( 'trashboxActivityCheck', ' Auto close ' ) );
// 削除ボタンを設置
var trashboxImg = document.createElement("span");
trashboxImg.innerHTML = '×'
trashboxImg.id = "trashbox";
trashboxImg.title = 'お知らせボックスを消す';
trashboxImg.style.display = 'block';
trashboxImg.style.textAlign = 'center';
trashboxImg.style.lineHeight = '15px';
trashboxImg.style.width = '13px';
trashboxImg.style.height = '15px';
trashboxImg.style.color = '#FFF';
trashboxImg.style.backgroundColor = '#94e4e8';
trashboxImg.style.border = '#FFF 2px solid';
trashboxImg.style.position = 'absolute';
trashboxImg.style.top = '-5px';
trashboxImg.style.right = '-5px';
trashboxImg.style.cursor = "pointer";
trashboxImg.addEventListener ( "click", function(){ displaynone(); }, false );
mainFrame.appendChild( trashboxImg );
// Twitter送信ボタン挿入
pushElement.appendChild( mainFrame );
// ボタン生成
function createButton ( data ){
var buttonName = data[0];
var twitterText = data[1];
var tweetBtn = document.createElement("button");
var tweetBtnTxt = document.createTextNode( buttonName );
var postText = setText( twitterText , liveTitle, liveURL );
tweetBtn.addEventListener ( "click", function(){tweetPostWindowOpen( postText, hashTagText )}, true );
tweetBtn.appendChild( tweetBtnTxt );
return tweetBtn;
}
// チェックボックス生成
function createCheckBox ( id, text ) {
var checkboxLabel = document.createElement("label");
var checkboxLabelText = document.createTextNode(text);
var ActivityCheckBox = document.createElement("input");
ActivityCheckBox.id = id;
ActivityCheckBox.type = 'checkbox';
ActivityCheckBox.style.margin = '0 0 0 4px';
if( GM_getValue( id, 1) != '0' ){
ActivityCheckBox.checked = true
}
checkboxLabel.appendChild(ActivityCheckBox);
checkboxLabel.appendChild(checkboxLabelText);
return checkboxLabel;
}
// Twitterのページを直接開いてstatusを渡すウィンドウを開く関数
function tweetPostWindowOpen ( postText, hashTagText ) {
console.log( typeof(GM_setValue) );
var hashTag;
if ( document.getElementById('tagActivityCheck').checked == true ) {
hashTag = ' ' + hashTagText;
GM_setValue( 'tagActivityCheck', 1);
} else {
hashTag = '';
GM_setValue( 'tagActivityCheck', 0);
}
if ( document.getElementById('trashboxActivityCheck').checked == true ) {
GM_setValue( 'trashboxActivityCheck', 1);
displaynone();
}else{
GM_setValue( 'trashboxActivityCheck', 0);
}
//statusを含むURL
var twitterPageURL = "http://twitter.com?status=" + encodeURIComponent( postText + hashTag );
var tweetPostWindow = window.open( twitterPageURL, "postWindow", "width=760,height=400,menubar=no,toolbar=no,status=no,resize=no,scrollbars=no");
}
// statusテキスト生成
function setText( text, liveTitle, liveURL ){
   var url = liveURL.match(/^(.*lv\d+)/);
   var tweetBody = "[ニコ生] " + text + liveTitle + " " + url[1];
return tweetBody;
}
// お知らせボックスを消す関数
function displaynone(){
document.getElementById("nicoLiveTweetBox").style.display = "none";
return false;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment