Iwara Video Sticky

Iwara.tvの動画プレイヤーをスクロールに追従させる

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Iwara Video Sticky
// @namespace    http://iwara.video.sticky/
// @version      0.2
// @description  Iwara.tvの動画プレイヤーをスクロールに追従させる
// @match        *://*.iwara.tv/videos/*
// @run-at       document-end
// ==/UserScript==

function addStyle (cssStr) {
    var D               = document;
    var newNode         = D.createElement ('style');
    newNode.textContent = cssStr;

    var targ    = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
    targ.appendChild (newNode);
}

(function() {
    'use strict';
    addStyle ( `
    .fixed {
        position : fixed;
        top : 0px;
        left:auto;
        z-index : 999;
    }
    ` );
})();

window.onscroll = function() {
	var videoPlayer = document.getElementById( "video-player" );
	var header = document.getElementsByTagName('header')[0];
	var nodeInfo = document.getElementsByClassName( "node-info" )[0];

    var style = videoPlayer.getAttribute('style');
    videoPlayer.setAttribute('style', style + 'width: '+ nodeInfo.offsetWidth +'px !important;');

	var screen_Y = document.documentElement.scrollTop || document.body.scrollTop;

	var headerRect = header.getBoundingClientRect();
	var header_Y = headerRect.top + headerRect.height + screen_Y;

    if(screen_Y >= header_Y) {
		videoPlayer.classList.add('fixed');
	}else{
        videoPlayer.classList.remove('fixed');
    }
};