MoonWalk Assistant

Расширяет функционал плеера MoonWalk.

目前為 2018-08-08 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            MoonWalk Assistant
// @name:en         MoonWalk Assistant
// @namespace       ANT0x1
// @version         2.1.2
// @date            2018-08-08
// @description     Расширяет функционал плеера MoonWalk.
// @description:en  Extends Moonwalk player functionality.
// @author          ANT0x1
// @match           http://*.abbanole.com/*/iframe*
// @icon            http://hdrezka.me/templates/hdrezka/images/favicon.ico
// @run-at          document-end
// @homepage        https://openuserjs.org/scripts/ANT0x1/
// @grant           none
// @copyright       2018, ANT0x1
// @license         CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
// @license         GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @namespace       ANT0x1
// ==/UserScript==

// ==OpenUserJS==
// @author          ANT0x1
// ==/OpenUserJS==

(function() {
    'use strict';
    removeAds();
})();

var currentVideo = {
	position: 0,
	isFinished: false,
	volume: 100
}

function removeAds(){
    setTimeout(function(){
        if (typeof player === 'undefined') {
            removeAds();
        }
        else {
            if (typeof player.vast === 'undefined' || typeof player.vast.remove === 'undefined'){
                removeAds();
            }
            else{
                player.vast.remove();
                console.log("[Assistant] Ads disabled.");
                playVideo();
            }
        }
    }, 2000);
}

function playVideo(){
    setTimeout(function(){
        if (typeof player === 'undefined' || typeof player.api === 'undefined'){
            playVideo();
            return;
        }
		
		player.api.play();
		
		console.log("[Assistant] Playing.");
		
		restoreFromStorage(); 

		api.fullscreen();
		console.log("[Assistant] Set to fullscreen.");

		player.api.setVolume(currentVideo.volume);		
		
		autoSave();
		        
    }, 2000);
}

function autoSave(){
	var timeout = api.paused ? 20000 : 5000;
		
	setTimeout(function(){
			savePosition();
			
			if (!api.paused)
				saveToStorage();
						
			if (!currentVideo.isFinished)
				autoSave();
			
		}, timeout);
}

function savePosition(){
	currentVideo.position = _mw_current_time;
	currentVideo.volume = api.volumeLevel;
	currentVideo.isFinished = api.finished;
}

function restorePosition(){
	
	if (currentVideo.position > 0){
		player.api.seek(currentVideo.position);
		console.log("[Assistant] Position restored to "+currentVideo.position+' sec.');
	}
}

function saveToStorage(){
	var videos = JSON.parse(localStorage.getItem('videos'));
	
	if (!videos)
		videos = {};
	
	videos[video_balancer.options.video_token] = currentVideo;
	localStorage.setItem('videos', JSON.stringify(videos));
	
	console.log('[Assistant] Saved to storage');
}

function restoreFromStorage(){
	var videos = JSON.parse(localStorage.getItem('videos'));
	
	if (!videos)
	{
		videos = {};
	}
	
	currentVideo = videos[video_balancer.options.video_token];
	
	if (!currentVideo){
		currentVideo = {
			position: 0,
			isFinished: false,
			volume: api.volumeLevel
		}
	}
	
	console.log('[Assistant] Restored from storage');
	
	if (!currentVideo.isFinished)
		restorePosition();
	else
		currentVideo.isFinished = false;
}