MoonWalk Assistant

Убирает рекламу из онлайн плееров.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            MoonWalk Assistant
// @name:en         MoonWalk Assistant
// @namespace       ANT0x1
// @version         2.5.2
// @date            2018-12-02
// @description     Убирает рекламу из онлайн плееров.
// @description:en  Removes ads from online players.
// @author          ANT0x1
// @match           http://*.abbanole.com/*/iframe*
// @match           http://*.mastarti.com/*/iframe*
// @icon            http://hdrezka.me/templates/hdrezka/images/favicon.ico
// @supportURL      http://clc.am/RemoveAds
// @run-at          document-end
// @homepage        http://clc.am/zWStKw
// @grant           none
// @copyright       2018, ANT0x1
// @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';
    setTimeout(removeAds, 2000);
})();

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

function removeAds() {
    if (typeof video_balancer !== 'undefined') {
        console.log('[Assistant] Removin Ads');

        video_balancer.adv_loader.options.adb_vast.urls = [];
        video_balancer.adv_loader.options.vast.urls = [];
        video_balancer.adv_loader.options.reserve_vast.urls = [];
    }

    console.log("[Assistant] Ads disabled.");
    playVideo();
}

function playVideo() {
    setTimeout(function () {
        if (typeof player === 'undefined' || typeof player.api === 'undefined') {
            playVideo();
            return;
        }

        console.log("[Assistant] Playing.");

        setTimeout(function () {
            setTimeout(restoreFromStorage, 2000);
            player.api.setVolume(currentVideo.volume);
            autoSave();
        }, 2000);
    }, 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;
}