ニコニコ漫画
by
asannou
2013-09-03 [2013/09/03 18:45:41]
Flash Player がない環境でニコニコ漫画を見る
@@ -3,7 +3,6 @@
* @description Flash Player がない環境でニコニコ漫画を見る
* @include http://seiga.nicovideo.jp/watch/*
* @license MIT License
- * @require
*/
jQuery(function($){
@@ -12,37 +11,50 @@
var url = [];
var bgm = [];
var i = 0;
-var img = $("<img></img>").css({border: "solid 1px #000"});
-var audio = $("<audio autoplay loop></audio>").appendTo("body");
+var img = $("<img></img>").css({ border: "solid 1px #000", width: "670px", height: "380px" });
+var div = $("<div></div>").css({ border: "solid 1px #000", position: "absolute", "z-index": "100", "background-color": "#000", opacity: "0.5" }).appendTo("body");
+var audio = $("<audio></audio>").appendTo("body");
-var next = function() {
- $.ajax({
- url: '/api/theme/next?id=' + id[1],
- type: 'get',
- dataType: 'xml',
- success: function(xml, status) {
+var next = function () {
+ $.get(
+ '/api/theme/next?id=' + id[1],
+ function (xml, status) {
if (status != 'success') return;
var next = $(xml).find("next");
- if (next && window.confirm(next.find("title").text())) {
+ var title = next.find("title").text();
+ if (title && window.confirm(title)) {
location.href = "http://seiga.nicovideo.jp/watch/mg" + next.find("id").text();
}
}
- });
+ );
};
-$.ajax({
- url: '/api/theme/data?theme_id=' + id[1],
- type: 'get',
- dataType: 'xml',
- success: function(xml, status) {
+var play = function (url) {
+ if (url) {
+ if (url != audio.attr("src")) audio.attr("src", url);
+ audio[0].play();
+ } else {
+ audio[0].pause();
+ audio[0].currentTime = 0;
+ }
+};
+
+$.get(
+ '/api/theme/data?theme_id=' + id[1],
+ function (xml, status) {
if (status != 'success') return;
- $(xml).find("image").each(function(){
+ $(xml).find("image").each(function () {
url.push($(this).find("source_url").text());
- bgm.push("http://lohas.nicoseiga.jp" + $(this).find("bgm_path").text());
+ if ($(this).find("bgm_id").text() == "-1") {
+ bgm.push("");
+ } else {
+ var bgm_path = $(this).find("bgm_path").text();
+ bgm.push((bgm_path && "http://lohas.nicoseiga.jp" + bgm_path) || bgm[bgm.length - 1]);
+ }
});
$("#playerBody").empty().append(img);
img.attr("src", url[i]);
- img.click(function(e) {
+ img.click(function (e) {
var w = $(this).width();
var x = e.pageX - $(this).offset().left;
if (x < w / 2) {
@@ -55,9 +67,16 @@
}
}
$(this).attr("src", url[i]);
+ play(bgm[i]);
+ });
+ div.offset(img.offset());
+ div.width(img.width());
+ div.height(img.height());
+ div.click(function () {
+ $(this).hide();
+ play(bgm[i]);
});
- audio.attr("src", bgm[0]);
}
-});
+);
});
/*
* @title ニコニコ漫画
* @description Flash Player がない環境でニコニコ漫画を見る
* @include http://seiga.nicovideo.jp/watch/*
* @license MIT License
*/
jQuery(function($){
var id = location.href.match(/http:\/\/seiga\.nicovideo\.jp\/watch\/mg([0-9]+)/);
var url = [];
var bgm = [];
var i = 0;
var img = $("<img></img>").css({ border: "solid 1px #000", width: "670px", height: "380px" });
var div = $("<div></div>").css({ border: "solid 1px #000", position: "absolute", "z-index": "100", "background-color": "#000", opacity: "0.5" }).appendTo("body");
var audio = $("<audio></audio>").appendTo("body");
var next = function () {
$.get(
'/api/theme/next?id=' + id[1],
function (xml, status) {
if (status != 'success') return;
var next = $(xml).find("next");
var title = next.find("title").text();
if (title && window.confirm(title)) {
location.href = "http://seiga.nicovideo.jp/watch/mg" + next.find("id").text();
}
}
);
};
var play = function (url) {
if (url) {
if (url != audio.attr("src")) audio.attr("src", url);
audio[0].play();
} else {
audio[0].pause();
audio[0].currentTime = 0;
}
};
$.get(
'/api/theme/data?theme_id=' + id[1],
function (xml, status) {
if (status != 'success') return;
$(xml).find("image").each(function () {
url.push($(this).find("source_url").text());
if ($(this).find("bgm_id").text() == "-1") {
bgm.push("");
} else {
var bgm_path = $(this).find("bgm_path").text();
bgm.push((bgm_path && "http://lohas.nicoseiga.jp" + bgm_path) || bgm[bgm.length - 1]);
}
});
$("#playerBody").empty().append(img);
img.attr("src", url[i]);
img.click(function (e) {
var w = $(this).width();
var x = e.pageX - $(this).offset().left;
if (x < w / 2) {
if (url[i - 1]) i--;
} else {
if (url[i + 1]) {
i++;
} else {
next();
}
}
$(this).attr("src", url[i]);
play(bgm[i]);
});
div.offset(img.offset());
div.width(img.width());
div.height(img.height());
div.click(function () {
$(this).hide();
play(bgm[i]);
});
}
);
});
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。