Skip to content

Commit

Permalink
Merge pull request #1276 from GrosPoulet/master
Browse files Browse the repository at this point in the history
Improvement for plug-in: niconico_a (#1275)
  • Loading branch information
GrosPoulet authored Jan 1, 2024
2 parents 31d8226 + 0c424c2 commit 180a0ba
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions plugins/niconico_a.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push({
name:'niconico_a',
version:'0.2',
version:'0.3',
prepareImgLinks:function (callback) {
var res = [];

Expand All @@ -21,10 +21,13 @@ hoverZoomPlugins.push({
// page hosting thumbnail img: https://seiga.nicovideo.jp/
// thumbnail img: https://lohas.nicoseiga.jp/thumb/10804753q?1630337080
// fullsize img: https://lohas.nicoseiga.jp/priv/6fe923d8cddbce9d42ecd163db4c8dad622db3ea/1660470301/10804753
$('img[src*="nicoseiga.jp/thumb/"]:not(.hoverZoomMouseover), a[href*="/seiga/im"]:not(.hoverZoomMouseover)').filter(function() { if(/nico.*\.jp/.test($(this).prop('src'))) return true; if(/nico.*\.jp/.test($(this).prop('href'))) return true; return false; }).addClass('hoverZoomMouseover').one('mouseover', function() {
var thumb = this.src || this.href;
$('img[src*="nicoseiga.jp/thumb/"], a[href*="/seiga/im"]').filter(function() { if(/nico.*\.jp/.test($(this).prop('src'))) return true; if(/nico.*\.jp/.test($(this).prop('href'))) return true; return false; }).one('mouseover', function() {

var link = $(this);
if (link.data().hoverZoomMouseOver) return;
link.data().hoverZoomMouseOver = true;

var thumb = this.src || this.href;
var re = /\/thumb\/(\d+)/; // image id (e.g. 10804753)
var m = thumb.match(re);
if (m == undefined) {
Expand All @@ -42,17 +45,27 @@ hoverZoomPlugins.push({
let fullsize = doc.querySelector('div[data-src]');
if (fullsize) {
callback(fullsize.dataset.src);
hoverZoom.displayPicFromElement(link);
// Image is displayed if the cursor is still over the link
if (link.data().hoverZoomMouseOver)
hoverZoom.displayPicFromElement(link);
}
}, true); // get source async
}).one('mouseleave', function () {
const link = $(this);
link.data().hoverZoomMouseOver = false;
});

// comics (some comics are protected: displayed as canvas instead of regular imgs)
// overview: https://seiga.nicovideo.jp/comic/52735?track=verticalwatch_recommend
// episode: https://seiga.nicovideo.jp/watch/mg553196?track=ct_episode
$('a[href*="/watch/mg"]').filter(function() { return (/nicovideo\.jp\/watch\/mg\d+/.test($(this).prop('href'))) }).one('mouseover', function() {
var episodeLink = this.href;

var link = $(this);
if (link.data().hoverZoomMouseOver) return;
link.data().hoverZoomMouseOver = true;

var episodeLink = this.href;
console.log(`niconico episode: ${episodeLink}`);

// clean previous result
link.data().hoverZoomSrc = [];
Expand All @@ -65,16 +78,26 @@ hoverZoomPlugins.push({
gallery.push([this.dataset.original]);
});
callback(gallery);
hoverZoom.displayPicFromElement(link);
// Image is displayed if the cursor is still over the link
if (link.data().hoverZoomMouseOver)
hoverZoom.displayPicFromElement(link);
}
}, true); // get source async
}).one('mouseleave', function () {
const link = $(this);
link.data().hoverZoomMouseOver = false;
});

// videos
// sample: https://www.nicovideo.jp/watch/sm38456939
$('a[href*="/watch/sm"]:not(.hoverZoomMouseover), a[href*="/watch/so"]:not(.hoverZoomMouseover), a[href*="/watch/nm"]:not(.hoverZoomMouseover)').filter(function() { return (/nicovideo\.jp\/\/?watch\/(sm|so|nm)\d+/.test($(this).prop('href'))) }).addClass('hoverZoomMouseover').one('mouseover', function() {
var videoLink = this.href;
$('a[href*="/watch/sm"], a[href*="/watch/so"], a[href*="/watch/nm"]').filter(function() { return (/nicovideo\.jp\/\/?watch\/(sm|so|nm)\d+/.test($(this).prop('href'))) }).one('mouseover', function() {

var link = $(this);
if (link.data().hoverZoomMouseOver) return;
link.data().hoverZoomMouseOver = true;

var videoLink = this.href;
console.log(`niconico video: ${videoLink}`);

const re = /\/watch\/(sm|so|nm)(\d+)/; // video id (e.g. 38456939)
const m = videoLink.match(re);
Expand Down Expand Up @@ -117,7 +140,9 @@ hoverZoomPlugins.push({
response = JSON.parse(response);
let m3u8 = response.data.session.content_uri;
callback(m3u8);
hoverZoom.displayPicFromElement(link);
// Image is displayed if the cursor is still over the link
if (link.data().hoverZoomMouseOver)
hoverZoom.displayPicFromElement(link);
} catch {
return;
}
Expand All @@ -129,6 +154,10 @@ hoverZoomPlugins.push({
return;
}
}, true); // get source async

}).one('mouseleave', function () {
const link = $(this);
link.data().hoverZoomMouseOver = false;
});

callback($(res), this.name);
Expand Down

0 comments on commit 180a0ba

Please sign in to comment.