Created
November 3, 2009 07:12
-
-
Save nobodyplace/224859 to your computer and use it in GitHub Desktop.
ニコニコ動画のブログ貼り付け用コードを動画画面に表示するGreasemonkey
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 Nico Blogparts | |
// @version 0.1.0 | |
// @namespace https://gist.github.com/224859 | |
// @description ニコニコ動画のブログ貼り付け用コードを動画画面に表示するGreasemonkey | |
// @include http://www.nicovideo.jp/watch/* | |
// @updated 2011/10/01 15:34:00 | |
// ==/UserScript== | |
// 0.0.1 - 2009/11/01 リリース | |
// 0.0.2 - 2009/11/08 チャンネル動画のvideoId(ex. http://www.nicovideo.jp/watch/1255083605)に対応 | |
// 0.0.3 - 2010/05/31 videoId取得を変更 | |
// 0.0.4 - 2010/05/31 canonicalを通常の動画URLに置き換えるようにした | |
// 0.0.5 - 2010/06/02 全角スペースがundefineになる問題を修正 | |
// 0.0.6 - 2010/10/14 動画視聴ページのリニューアルに対応 | |
// 0.0.7 - 2010/10/25 チャンネル動画対応のため動画IDを変更 | |
// 0.0.8 - 2010/11/07 二重表示対策 / 誕生日おめでとう>妹 | |
// 0.0.9 - 2011/10/01 表示位置変更 | |
// 0.1.0 - 2011/10/02 canonical置き換えを削除他 | |
(function(doc){ | |
'use strict'; | |
var w = unsafeWindow; //ページ内要素にアクセスするためunsafeWindowを使用する | |
var id = w.Video['v']; //動画ID | |
var title = w.Video['title']; //動画タイトルを取得 | |
if(!id || !title) return; | |
//外部プレイヤー | |
var extPlayer = '<script type="text/javascript" src="http://ext.nicovideo.jp/thumb_watch/'+id+'"></script>' + '<noscript><a href="http://www.nicovideo.jp/watch/'+id+'">'+title+'</a></noscript>'; | |
//動画情報 | |
var movieInfo = '<iframe width="312" height="176" src="http://ext.nicovideo.jp/thumb/'+id+'" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"><a href="http://www.nicovideo.jp/watch/'+id+'">'+title+'</a></iframe>'; | |
//HTMLエスケープ | |
var htmlEscape = function(str){ | |
var map = {"<":"<", ">":">", "&":"&", "'":"'", "\"":""", " ":" ", " ":" "}; | |
var replaceStr = function(s){ return map[s]; }; | |
return str.replace(/<|>|&|'|"|\s| /g, replaceStr); | |
} | |
//表示するテキストを作成 | |
var str = | |
'<table cellspacing="0">'+ | |
'<tr><th class="font10">外部プレイヤー</th></tr>'+ | |
'<tr><td><form name="form_script"><input type="text" style="width: 250px;" readonly="true" name="script_code" onclick="javascript:document.form_script.script_code.focus(); document.form_script.script_code.select();" value="'+htmlEscape(extPlayer)+'"></form></td></tr>'+ | |
'<tr><th class="font10">動画情報</th></tr>'+ | |
'<tr><td><form name="form_iframe"><input type="text" style="width: 250px;" readonly="true" name="iframe_code" onclick="javascript:document.form_iframe.iframe_code.focus(); document.form_iframe.iframe_code.select();" value="'+htmlEscape(movieInfo)+'"></form></td></tr>'+ | |
'</table>' | |
; | |
//表示 | |
var e = doc.getElementsByClassName('owner_prof')[0].parentNode; | |
var d = doc.createElement('div'); | |
d.id = 'blog_parts_area'; //二重表示防止のため | |
d.innerHTML = str; | |
if(!doc.getElementById('blog_parts_area')) | |
e.insertBefore(d, e.lastChild); | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment