-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
138 additions
and
40 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
export const EXTENSION_LABEL = '[非公式] PinP'; | ||
|
||
/* | ||
* video タグのセレクタ | ||
*/ | ||
// ニコニコ動画 | ||
export const NICO_VIDEO_VIDEO_TAG_SELECTOR = '#MainVideoPlayer video'; | ||
// ニコニコ動画(Re:仮) | ||
export const NICO_VIDEO_TMP_VIDEO_TAG_SELECTOR = 'main [data-name="content"] video'; | ||
// ニコニコ生放送 | ||
export const NICO_LIVE_VIDEO_TAG_SELECTOR = '[class^=___video-layer___] video'; | ||
|
||
export const VIDEO_TAG_SELECTOR = [ | ||
NICO_VIDEO_VIDEO_TAG_SELECTOR, | ||
NICO_VIDEO_TMP_VIDEO_TAG_SELECTOR, | ||
NICO_LIVE_VIDEO_TAG_SELECTOR, | ||
].join(','); | ||
|
||
/* | ||
* コメント用 canvas のセレクタ | ||
*/ | ||
// ニコニコ動画 | ||
export const NICO_VIDEO_COMMENT_CANVAS_TAG_SELECTOR = '.CommentRenderer canvas'; | ||
// ニコニコ動画(Re:仮) | ||
export const NICO_VIDEO_TMP_COMMENT_CANVAS_TAG_SELECTOR = 'main [data-name="comment"] > canvas'; | ||
// ニコニコ生放送 | ||
export const NICO_LIVE_COMMENT_CANVAS_TAG_SELECTOR = '[class^=___comment-layer___] canvas'; | ||
|
||
export const COMMENT_CANVAS_TAG_SELECTOR = [ | ||
NICO_VIDEO_COMMENT_CANVAS_TAG_SELECTOR, | ||
NICO_VIDEO_TMP_COMMENT_CANVAS_TAG_SELECTOR, | ||
NICO_LIVE_COMMENT_CANVAS_TAG_SELECTOR, | ||
].join(','); | ||
|
||
/* | ||
* コピー元とするボタンのセレクタ | ||
*/ | ||
// ニコニコ動画 | ||
export const NICO_VIDEO_TARGET_BUTTON_SELECTOR = '.ControllerContainer .EnableFullScreenButton'; | ||
// ニコニコ動画(Re:仮) | ||
export const NICO_VIDEO_TMP_TARGET_BUTTON_SELECTOR = 'main .w_24px:not(.p_2px)'; | ||
// ニコニコ生放送 | ||
export const NICO_LIVE_TARGET_BUTTON_SELECTOR = '[class^=___addon-controller___] [class^=___fullscreen-button___]'; | ||
|
||
export const TARGET_BUTTON_SELECTOR = [ | ||
NICO_VIDEO_TARGET_BUTTON_SELECTOR, | ||
NICO_VIDEO_TMP_TARGET_BUTTON_SELECTOR, | ||
NICO_LIVE_TARGET_BUTTON_SELECTOR, | ||
].join(','); | ||
|
||
/** | ||
* 提供画面の HTML のセレクタ(ニコニコ動画のみ) | ||
*/ | ||
export const NICO_VIDEO_SUPPORTER_VIEW_SELECTOR = '#UadPlayer .SupporterView'; | ||
export const NICO_VIDEO_TMP_SUPPORTER_VIEW_SELECTOR = 'main [data-name="supporter-content"]'; | ||
|
||
export const SUPPORTER_VIEW_SELECTOR = [ | ||
NICO_VIDEO_SUPPORTER_VIEW_SELECTOR, | ||
NICO_VIDEO_TMP_SUPPORTER_VIEW_SELECTOR, | ||
].join(','); | ||
|
||
/** | ||
* 提供画面の Canvas のセレクタ(ニコニコ動画のみ) | ||
*/ | ||
export const NICO_VIDEO_SUPPORTER_VIEW_CANVAS_SELECTOR = '#SupporterView-canvas'; | ||
export const NICO_VIDEO_TMP_SUPPORTER_VIEW_CANVAS_SELECTOR = 'main [data-name="supporter-content"] canvas'; | ||
|
||
export const SUPPORTER_VIEW_CANVAS_SELECTOR = [ | ||
NICO_VIDEO_SUPPORTER_VIEW_CANVAS_SELECTOR, | ||
NICO_VIDEO_TMP_SUPPORTER_VIEW_CANVAS_SELECTOR, | ||
].join(','); | ||
|
||
/** | ||
* Akashic のゲーム画面の canvas のセレクタ(ニコニコ生放送のみ) | ||
*/ | ||
export const NICO_LIVE_AKASHIC_CANVAS_SELECTOR = '#akashic-gameview canvas'; | ||
|
||
export const AKASHIC_CANVAS_SELECTOR = [NICO_LIVE_AKASHIC_CANVAS_SELECTOR].join(','); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,48 @@ | ||
import { EXTENSION_LABEL, TARGET_BUTTON_SELECTOR, VIDEO_TAG_SELECTOR } from './constants'; | ||
import { copyButton } from './functions/copyButton'; | ||
import { initPinP, startPinP } from './functions/pinp'; | ||
import PictureInPictureIcon from './svg/pinpIcon'; | ||
|
||
const TITLE = '[非公式] PinP'; | ||
|
||
const checkPinPButton = setInterval(function () { | ||
const fullScreenButton = document.querySelector<HTMLElement>( | ||
'.ControllerContainer .EnableFullScreenButton, [class^=___addon-controller___] [class^=___fullscreen-button___]' | ||
); | ||
if (!fullScreenButton) return; | ||
(() => { | ||
// ページにスクリプトを挿入 | ||
// ※主にギフト画像の読み込み問題用。解消したら削除したい。 | ||
const path = chrome.runtime.getURL('js/inject.js'); | ||
const script = document.createElement('script'); | ||
script.src = path; | ||
document.head.append(script); | ||
|
||
initPinP(); | ||
let count = 0; | ||
const checkPinPButton = setInterval(function () { | ||
const targetButtons = document.querySelectorAll<HTMLElement>(TARGET_BUTTON_SELECTOR); | ||
if (targetButtons.length === 0) { | ||
// 一定回数チェックして見つからなかったらページ構造が変わったと判断して終了 | ||
++count; | ||
if (count > 15) clearInterval(checkPinPButton); | ||
return; | ||
} | ||
|
||
// フルスクボタンをコピーしPinPボタンにする | ||
copyButton({ | ||
srcButton: fullScreenButton, | ||
title: TITLE, | ||
icon: PictureInPictureIcon, | ||
onClick: startPinP, | ||
}); | ||
// PinPの初期化 | ||
initPinP(); | ||
|
||
// videoのPinP操作からstartPinPを呼び出すようにする | ||
const video = document.querySelector<HTMLVideoElement>('#MainVideoPlayer video, [class^=___video-layer___] video'); | ||
if (video) { | ||
video.disablePictureInPicture = false; | ||
video.addEventListener('enterpictureinpicture', (e) => { | ||
e.preventDefault(); | ||
startPinP(); | ||
// ボタンをコピーしPinPボタンにする | ||
const targetButton = targetButtons[targetButtons.length - 1]; | ||
copyButton({ | ||
srcButton: targetButton, | ||
title: EXTENSION_LABEL, | ||
icon: PictureInPictureIcon, | ||
onClick: startPinP, | ||
}); | ||
} | ||
|
||
clearInterval(checkPinPButton); | ||
}, 500); | ||
// videoのPinP操作からstartPinPを呼び出すようにする | ||
const video = document.querySelector<HTMLVideoElement>(VIDEO_TAG_SELECTOR); | ||
if (video) { | ||
video.disablePictureInPicture = false; | ||
video.addEventListener('enterpictureinpicture', (e) => { | ||
e.preventDefault(); | ||
startPinP(); | ||
}); | ||
} | ||
|
||
(() => { | ||
const path = chrome.runtime.getURL('js/inject.js'); | ||
const script = document.createElement('script'); | ||
script.src = path; | ||
document.head.append(script); | ||
clearInterval(checkPinPButton); | ||
}, 500); | ||
})(); |
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
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