leminoViwerSizeTuner

Place a slider bar to adjust lemino viwer size.

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==UserScript==
// @name            leminoViwerSizeTuner
// @namespace       https://greatest.deepsurf.us/ja/users/1328592-naoqv
// @description     Place a slider bar to adjust lemino viwer size.
// @description:ja  lemino ビューワーサイズ調整スライダーバー設置
// @version         0.1
// @match           https://lemino.docomo.ne.jp/*
// @grant           none
// @license         MIT
// ==/UserScript==


(() => {
  'use strict';

  // modalパーツのidは '*_madal'
  const REGEX_MODAL = /_modal/;

  const styleText = `
  #slider-container {
    margin-top: 20px;
    width: 200px;
    height: 40px;
    position: absolute;
    right: 0;
    top: 0;
  }

  #size-display {
    margin-top: 10px;
    font-family: monospace;
  }`;

  const styleElem = document.createElement("style");
  styleElem.setAttribute("rel", "stylesheet");
  styleElem.textContent = styleText;
  document.head.appendChild(styleElem);

  const minScale = 0.5;
  const maxScale = 2.0;
  let baseWidth = Math.floor(window.screen.width/2.58);

  const htmltext = `
    <div id="slider-container">
      <label for="scale-slider">サイズ調整:</label>
      <input type="range" id="scale-slider" min="0.5" max="2" step="0.01" value="1">
      <div id="size-display">現在のサイズ: 200 × 150</div>
    </div>`;

  
  /**
   * ビューワーサイズを更新する
   * @param {number} scale 
   */
  function updateSize(scale) {
    // 制限内に収める
    scale = Math.min(Math.max(scale, minScale), maxScale);

    const newWidth = Math.round(baseWidth * scale);

    const box = document.querySelector('.vQB');
    box.style.width = `${newWidth}px`;

    const currentWidth = box.clientWidth;
    const currentHeight = box.clientHeight;

    const sizeDisplay = document.getElementById('size-display');
    sizeDisplay.textContent = `現在のサイズ: ${currentWidth} × ${currentHeight}`;
  }

  /**
   * 指定したidのタグ内にビューワーサイズ調整するスライダーを配置する
   * 
   * @param {string} スライダーを配置するタグのid属性
   */
  const placeSlider = (id) => {

    const vod = document.getElementById(id);
    vod.insertAdjacentHTML('beforeend', htmltext);

    const slider = document.getElementById('scale-slider');

    // 初期表示
    updateSize(parseFloat(slider.value));

    slider.addEventListener('input', (e) => {

      updateSize(parseFloat(slider.value));
    });

    document.getElementById('slider-container').addEventListener('mousedown', (e) => {
      e.stopPropagation();
    });

    document.getElementById('slider-container').addEventListener('click', (e) => {
      e.stopPropagation();
    });
  };

	// DOM監視 
  const observer = new MutationObserver((mutationsList) => {
    for (const mutation of mutationsList) {
      for (const node of mutation.addedNodes) {
        
        if (node.tagName === "DIV" && node.hasChildNodes()) {

          const modal = Array.prototype.find.call(node.children, (n) => n.id.match(REGEX_MODAL));
 
					if (modal) {

            placeSlider(modal.id);
           	return;
          }
        }
      }
    }
  });

  // DOM監視スタート
  observer.observe(document.getElementById('__next'), {
    childList: true,
    subtree: true
  });

})();