「サブウインドウ表示」から元に戻れない

「サブウインドウ表示」は、最初にこの機能を実装した時から比べると、大変に調子よく機能する様になりました。 ただ、動画プレーヤーは色々な状態で動作するので、普通は見ないコンテンツなども総当たりで実際に動画表示をして、問題が生じないかチェックをしている所です。

 

今回判ったのは、「ABEMAプレミアム」の「無料体験の案内画面」が表示された場合に、「サブウインドウ表示」にしていると、そこから抜け出せなくなる問題です。

 

下は、問題を生じる「案内画面」です。

 

 

シリーズになった動画を表示していると、ひとつの動画が終了すると、自動的に次に続く動画を表示する仕組みになっていますが、それまで「無料動画」で、その続きの動画が「プレミアム」(有料)の場合に、上の様な「案内画面」が表示されます。

 

この画面は動画ではなく、リンクボタンを埋め込んだパネルです。 動画プレーヤーは動画表示の状態ではないので、コントロールボタンは有りません。

 

上の様な「デフォルト表示」や「ワイド表示」の場合は、周囲にいくらでもボタンがあり、この画面から離れる事が出来ます。 しかし、「サブウインドウ表示」でこの「案内画面」が表示されると、下の様に画面を離れる方法がありません。

 

 

ブラウザのリロード「 」で抜け出せますが、これは余り良い事ではないでしょう。 しばらくユーザーを惑わす事になりますから。「ワイド表示」が左列を残した中途半端なデザインなのは、抜け出せなくなるのを避けたからかも知れません。

 

 

対策 

この「案内画面」を表示する最上流の「親要素」は、下の太字の要素です。「案内画面」の表示のために、この要素が動画プレーヤーに呼び込まれます。

 

下のコードは、この親要素の存在を判定し、「サブウインドウ表示」のデザインを適用する「.atv_style」(styleタグ)を無効にして「デフォルト表示」に戻します。

 

let ec_thumbnail=document.querySelector(
             '.c-vod-EpisodePlayerContainer-thumbnail');

if(ec_thumbnail){ //プレミアム表示で「サブウインドウ表示」をリセット
    let atv_style=document.querySelector('.atv_style');
    if(atv_style){
        if(atv_style.disabled==false){
            atv_style.disabled=true; }}}

 

このコードを、動画コンテンツが切換るごとに実行する様にしました。「案内画面」は、新しい動画コンテンツの最初に表示されるので、その時に「案内画面」が表示されていれば、「サブウインドウ表示」を「デフォルト表示」に戻すわけです。

 

新しい動画プレーヤーのロード後に、「案内表示」の呼込みが僅かに遅れる様です。 このため、プレーヤーロード後に更に「200msec」を待ってから、この処理を実行しています。(ver. 0.5 の 89行)

 

 

 

「AmbTV Comfy」を利用するには

このツールは Chrome / Edge / Firefox版の拡張機能「Tampermonkey」上で動作します。 以下に、このツールの導入手順を簡単に説明します。

 

❶「Tampermonkey」を導入します

◎ 使用しているブラウザに拡張機能「Tampermonkey」を導入する事が必要です。

既に「Tampermonkey」を導入している場合は、この手順 ❶ は不要です。 

拡張機能の導入については、以下のページに簡単な説明があるので参照ください。

 

 

❷「Tampermonkey」にスクリプトを登録します

◎「Tampermonkey」の「」マークの「新規スクリプト」タブを開きます。

 

 

 

◎「新規スクリプト」には、最初からテンプレートが記入されています。 これは全て削除して、完全に空白の編集枠に 下のコードをコピー&ペーストします。

 

〔コピー方法〕 軽量シンプルなツール「PreBox Button   」を使うと

  コード枠内を「Ctrl+左Click」➔「Copy code 」を「左Click」

  の操作で、掲載コードのコピーが可能になります。

 

◎ 最後に「ファイル」メニューの「保存」を押すと、ツールが使用可能になります。

 

 

〔 AmbTV Comfy 〕 ver. 0.5

 

// ==UserScript==
// @name         AmbTV Comfy
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  AbemaTV ユーティリティ
// @author       Ameba User
// @match        https://abema.tv/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=abema.tv
// @grant        none
// ==/UserScript==



main();

let target=document.querySelector('head > title');
let monitor=new MutationObserver(main);
monitor.observe(target, { childList: true });

function main(){

    let style=
        '<style class="atv_style">'+
        '.c-common-HeaderContainer-header, '+
        '.c-application-SideNavigation, '+
        '.c-application-SideNavigation--collapsed, '+
        '.com-vod-VODRecommendedContentsContainerView__player-aside-recommended '+
        '{ display: none; } '+
        '.c-video-EpisodeContainerView-breadcrumb, '+
        '.com-vod-VODRecommendedContentsContainerView__details, '+
        '.com-vod-VODRecommendedContentsContainerView__episode-list, '+
        '.com-feature-area-FeatureRecommendedArea__section, '+
        '.c-video-EpisodeContainerView__page-bottom, '+
        '.c-application-FooterContainer '+
        '{ display: none; } '+
        '.c-application-DesktopAppContainer__content-container '+
        '{ align-items: center; height: 100vh; } '+
        '.com-vod-VODResponsiveMainContent '+
        '{ margin: 0 !important; padding: 0 !important; } '+
        '.com-vod-VODRecommendedContentsContainerView__player-and-details '+
        '{ margin-right: 0 !important; } '+
        '.com-vod-VODRecommendedContentsContainerView__player '+
        '{ margin: 0 6px !important; } '+
        '.c-application-DesktopAppContainer__content '+
        '{ min-width: 400px !important; } '+
        '.com-vod-VODResponsiveMainContent '+
        '{ --com-vod-VODResponsiveMainContent--content-min-width: 400 !important; } '+
        '.com-vod-VODResponsiveMainContent__container { overflow: hidden; } '+
        '</style>'+
        '<style class="atv_style_basic">'+
        '.com-vod-VODScreen-container { background: #000 !important; }'+
        '</style>';

    if(!document.querySelector('.atv_style')){
        document.body.insertAdjacentHTML('beforeend', style);

        let atv_style=document.querySelector('.atv_style');
        if(atv_style){
            atv_style.disabled=true; }}



    let retry=0;
    let interval=setInterval(wait_target, 20);
    function wait_target(){
        retry++;
        if(retry>100){ // リトライ制限 100回 2secまで
            clearInterval(interval); }
        let player=document.querySelector(
            '.com-vod-VODRecommendedContentsContainerView__player');
        if(player){
            clearInterval(interval);
            set_player(player); }}


    function set_player(player){
        let wrap=player.querySelector('.c-vod-EpisodePlayerContainer-wrapper');
        if(wrap){
            let monitor1=new MutationObserver(play);
            monitor1.observe(wrap, { childList: true }); }

        setTimeout(()=>{
            let wrap_tv=player.querySelector('.c-tv-TimeshiftPlayerContainerView');
            if(wrap_tv){
                let monitor2=new MutationObserver(play);
                monitor2.observe(wrap_tv, { childList: true }); }
        }, 1000);

        setTimeout(()=>{
            let ec_thumbnail=
                document.querySelector('.c-vod-EpisodePlayerContainer-thumbnail');
            if(ec_thumbnail){
                reset_subw(); } //「サブウインドウ表示」をプレミアムAD表示時にリセット
        }, 200); }



    function play(){
        let nav_b=document.querySelector(
            '.com-vod-VideoControlBar__playback-rate');
        if(nav_b){
            let sw=
                '<button type="button" class="atv_sw com-vod-FullscreenButton">'+
                '<div class="com-vod-FullscreenButton__tooltip">'+
                '<div class="atv_tp com-a-Tooltip com-a-Tooltip--arrow-position-center">'+
                '</div></div>'+
                '<span class="atv_icon">🔳</span></button>'+
                '<style>.atv_icon { padding: 0 0 2px; '+
                'filter: drop-shadow(2px 2px 0 #fff); } '+
                ':fullscreen .atv_sw { display: none; }</style>';

            if(!document.querySelector('.atv_sw')){
                nav_b.insertAdjacentHTML('afterend', sw); }

            let atv_sw=document.querySelector('.atv_sw');
            let atv_style=document.querySelector('.atv_style');
            let atv_tp=document.querySelector('.atv_tp');
            if(atv_sw && atv_style && atv_tp){
                if(atv_style.disabled==false){
                    atv_tp.textContent='デフォルト表示'; }
                else{
                    atv_tp.textContent='サブウインドウ表示'; }

                atv_sw.onclick=function(e){
                    e.preventDefault();
                    if(atv_style.disabled==false){
                        atv_style.disabled=true;
                        atv_tp.textContent='サブウインドウ表示'; }
                    else{
                        atv_style.disabled=false;
                        atv_tp.textContent='デフォルト表示'; }
                }}}} // play()



    function reset_subw(){
        let atv_style=document.querySelector('.atv_style');
        if(atv_style){
            if(atv_style.disabled==false){
                atv_style.disabled=true; }}}

} // main()



catch_click();

function catch_click(){ // 動画のサムネイルの暗転拡大表示
    let html_=document.querySelector('html');

    box_env();

    document.addEventListener('contextmenu', function(event){
        if(!event.shiftKey && !event.ctrlKey){
            event.preventDefault();
            let elem=document.elementFromPoint(event.clientX, event.clientY);
            let link_elem=elem.closest('a');

            if(link_elem){
                set_link(link_elem);
                set_img(link_elem);
                close(); }}});


    function box_env(){
        let lightbox=
            '<div id="lightbox">'+
            '<div id="photo_sw"><a id="photo_link">🎦 Movie Page</a></div>'+
            '<img id="box_img">'+
            '<style>'+
            '@keyframes fadeIn { 0% {opacity: 0} 100% {opacity: 1}} '+
            '.fin { animation: fadeIn .5s ease 0s 1 normal; animation-fill-mode: both; } '+
            '@keyframes fadeOut { 0% {opacity: 1} 100% {opacity: 0}} '+
            '.fout { animation: fadeOut .2s ease 0s 1 normal; animation-fill-mode: both; } '+
            '#lightbox { position: fixed; top: 0; left: 0; z-index: 3000; visibility: hidden; '+
            'background: black; width: 100vw; height: 100vh; text-align: center; } '+
            '#photo_sw { position: absolute; width: 100%; height: 15%; } '+
            '#photo_sw:hover #photo_link { opacity: 1; } '+
            '#photo_link { font: bold 21px Meiryo; position: absolute; top: 20px; left: 30px; '+
            'padding: 4px 12px 2px 10px; color: #000; background: #fff; cursor: pointer; '+
            'border: 2px solid #000; border-radius: 6px; text-decoration: none; opacity: 0; } '+
            '#box_img { width: 100vw; height: 100vh; padding: 2vh 2vw; '+
            'object-fit: contain; } '+
            '</style></div>';

        if(!document.querySelector('#lightbox')){
            document.body.insertAdjacentHTML('beforeend', lightbox); }}


    function set_link(target){
        let photo_link=document.querySelector('#photo_link');
        if(photo_link){
            let url=target.getAttribute('href');
            if(url){
                photo_link.setAttribute('href', url); }

            photo_link.onclick=function(event){
                event.stopImmediatePropagation(); }}}


    function set_img(target){
        let lightbox=document.querySelector('#lightbox');
        let box_img=lightbox.querySelector('#box_img');
        let img=target.querySelector('img');
        if(lightbox && box_img && img){
            let img_url=img.getAttribute('src').replace(/%3Fversion%.*$/,"");
            if(img_url){
                box_img.src=img_url;
                html_.style.overflow='hidden';
                lightbox.style.visibility='visible';
                lightbox.classList.remove('fout');
                lightbox.classList.add('fin'); }}}


    function close(){
        let html_=document.querySelector('html');
        let lightbox=document.querySelector('#lightbox');
        let box_img=lightbox.querySelector('#box_img');
        if(lightbox){
            lightbox.onclick=function(event){
                event.preventDefault();
                html_.style.overflow='inherit';
                lightbox.classList.remove('fin');
                lightbox.classList.add('fout');
                setTimeout(()=>{
                    lightbox.style.visibility='hidden';
                    box_img.src='';
                }, 200); }}}

} // catch_click()


 

 

 

「AmbTV Comfy」最新版について 

旧いバージョンの JavaScriptツールは、Abemaサイトのページ構成の変更で動作しない場合があり、導入する場合は最新バージョンをお勧めします。

 

●「AmbTV Comfy」の最新バージョンへのリンクは、以下のページのリンクリストから探せます。