Skip to content

Instantly share code, notes, and snippets.

@hazisarashi
Created July 5, 2009 10:20
Show Gist options
  • Save hazisarashi/140917 to your computer and use it in GitHub Desktop.
Save hazisarashi/140917 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("放送開始をお知らせ","放送開始!: ") ;
var guestTitle = new Array("ゲスト出演をお知らせ","ゲスト出演中!: ") ;
var watchTitle = new Array("視聴をお知らせ","Watching: ") ;
// 放送情報取得
var liveTitle = document.getElementsByTagName("h1")[1].childNodes[0].innerHTML; // 放送タイトルの取得
var liveURL = location.href; // 放送URLの取得
// Main Div Element 生成
var mainFrame = document.createElement("div");
mainFrame.id = "nicoLiveTweetBox";
mainFrame.style.border = "#FFF 3px solid";
mainFrame.style.background = 'url(http://assets0.twitter.com/images/twitter_logo_header.png) no-repeat 10px center #94e4e8';
mainFrame.style.padding = '17px 0 13px 180px';
// ボタンをmainFrameに埋め込む
var pushElement = document.getElementById("console_container");
if( pushElement ){
pushElement = document.getElementById("WATCHHEADER");
mainFrame.appendChild( createButton( ownerTitle ) );
}else{
pushElement = document.getElementById("WATCHHEADER");
mainFrame.appendChild( createButton( guestTitle ) );
mainFrame.appendChild( createButton( watchTitle ) );
}
// 削除ボタンを設置
var trashboxImg = document.createElement("img");
trashboxImg.id = "trashbox";
trashboxImg.style.display = "block";
trashboxImg.style.float = "right";
trashboxImg.style.cssFloat = "right"
trashboxImg.style.width = "16px"
trashboxImg.style.height = "16px"
trashboxImg.style.margin = "10px 3px 0 0";
trashboxImg.style.cursor = "pointer";
trashboxImg.addEventListener ( "click", function(){ displaynone(); }, false );
trashboxImg.src = "http://static.twitter.com/images/icon_trash.gif";
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 )}, true );
tweetBtn.appendChild( tweetBtnTxt );
tweetBtn.style.margin = '0 15px 0 0';
return tweetBtn;
}
// Twitterのページを直接開いてstatusを渡すウィンドウを開く関数
function tweetPostWindowOpen ( postText ) {
//statusを含むURL
var twitterPageURL = "http://twitter.com?status=" + encodeURIComponent( postText );
var tweetPostWindow = window.open( twitterPageURL, "postWindow", "width=760,height=400,menubar=no,toolbar=no,status=no,resize=no,scrollbars=no");
}
function setText( text, liveTitle, liveURL ){
var tweetBody = text + liveTitle + " " + liveURL;
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