// ==UserScript== // @name nicoLiveTweet // @namespace http://nicolivemac.wordpress.com/ // @description ニコ生お知らせTwitterボタン // @include http://live.nicovideo.jp/watch/lv* // ==/UserScript== (function(){ // 設定 var ownerTitle = new Array("放送開始をお知らせ","Now On Air!: ") ; // 放送開始ボタン(ボタン表示テキスト,挿入テキスト) var guestTitle = new Array("ゲスト出演をお知らせ","ゲスト出演中: ") ; // ゲスト通知ボタン(ボタン表示テキスト,挿入テキスト) var watchTitle = new Array("視聴をお知らせ","Watching: ") ; // 視聴通知ボタン(ボタン表示テキスト,挿入テキスト) var hashTagText = "#nicolive"; // タグ(英字のみ) // 放送情報取得 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.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 ) ); mainFrame.appendChild( createCheckBox() ); pushElement.style.position = 'relative'; mainFrame.style.position = 'absolute'; mainFrame.style.right = '7px'; mainFrame.style.width = '155px'; }else{ pushElement = document.getElementById("WATCHHEADER"); mainFrame.appendChild( createButton( guestTitle ) ); mainFrame.appendChild( createButton( watchTitle ) ); mainFrame.appendChild( createCheckBox() ); mainFrame.style.position = 'relative'; mainFrame.style.float = 'left'; mainFrame.style.margin = '-38px 0 0 300px'; } // 削除ボタンを設置 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 () { var checkboxLabel = document.createElement("label"); var checkboxLabelText = document.createTextNode("タグ"); var tagActivityCheckBox = document.createElement("input"); tagActivityCheckBox.id = 'tagActivityCheck'; tagActivityCheckBox.checked = true; tagActivityCheckBox.type = 'checkbox'; checkboxLabel.appendChild(tagActivityCheckBox); checkboxLabel.appendChild(checkboxLabelText); return checkboxLabel; } // Twitterのページを直接開いてstatusを渡すウィンドウを開く関数 function tweetPostWindowOpen ( postText, hashTagText ) { var hashTag; if ( document.getElementById('tagActivityCheck').checked == true ) { hashTag = ' ' + hashTagText; } else { hashTag = ''; } //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 tweetBody = text + liveTitle + " " + liveURL; return tweetBody; } // お知らせボックスを消す関数 function displaynone(){ document.getElementById("nicoLiveTweetBox").style.display = "none"; return false; } })();