Video Celebs Search And UI Tweaks

Video filters and UI manipulations

Verzia zo dňa 09.12.2020. Pozri najnovšiu verziu.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name         Video Celebs Search And UI Tweaks
// @namespace    brazenvoid
// @version      1.2.3
// @author       brazenvoid
// @license      GPL-3.0-only
// @description  Video filters and UI manipulations
// @include      https://videocelebs.net/*
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @require      https://greasyfork.org/scripts/375557-base-resource/code/Base%20Resource.js?version=878636
// @require      https://greasyfork.org/scripts/416104-brazen-ui-generator/code/Brazen%20UI%20Generator.js?version=877816
// @require      https://greasyfork.org/scripts/416105-brazen-base-search-enhancer/code/Brazen%20Base%20Search%20Enhancer.js?version=878637
// @grant        GM_addStyle
// @run-at       document-end
// ==/UserScript==

GM_addStyle(`#settings-wrapper{background-color:#ffa31a;top:15vh;width:250px}input.form-input.check-radio-input{width:auto;margin:0 5px 1px 0}label.title{margin: 0}`)

const PAGE_PATH_NAME = window.location.pathname

const IS_VIDEO_PAGE = PAGE_PATH_NAME.endsWith('.html')

const FILTER_VIDEOS_RATING = 'Rating'
const FILTER_VIDEOS_YEAR = 'Year'

const OPTION_MOVE_VIDEO_ATTRIBUTES_SECTION = 'Reposition Attributes Section'
const OPTION_REMOVE_COMMENTS_SECTION = 'Remove Comments Section'
const OPTION_REMOVE_IFRAME_SECTION = 'Remove Iframe Share Section'
const OPTION_REMOVE_RELATED_VIDEOS_SECTION = 'Remove Related Videos Section'

class VideoCelebsSearchAndUITweaks extends BrazenBaseSearchEnhancer
{
    static getLastPageUrl ()
    {
        let lastPaginationElement = $('.wp-pagenavi a:last')
        return lastPaginationElement.length ? lastPaginationElement.attr('href') : window.location.href
    }

    constructor ()
    {
        super({
            scriptPrefix: 'vc-sui-',
            itemClasses: 'item',
            paginator: {
                enable: !IS_VIDEO_PAGE,
                listSelector: '.midle_div',
                lastPageUrl: VideoCelebsSearchAndUITweaks.getLastPageUrl(),
                getPageNo: (url) => url.includes('/page/') ? parseInt(url.split('/').pop()) : 1,
                getPageUrl: (newPageNo) => {
                    let currentUrl = window.location.href
                    if (currentUrl.includes('/page/')) {
                        let currentUrlFragments = currentUrl.split('/')
                        currentUrlFragments.pop()
                        currentUrl = currentUrlFragments.join('/')
                    } else {
                        currentUrl += '/page'
                    }
                    return currentUrl + '/' + newPageNo
                },
                afterPagination: (paginator) => {

                    let currentPaginationElement = $('.wp-pagenavi span.current')
                    currentPaginationElement.text(paginator.currentPageNo + '-' + paginator.paginatedPageNo)

                    let paginatorLinksAfterCurrent = $('.wp-pagenavi span.current ~ a')
                    if (paginator.paginatedPageNo === paginator.lastPageNo) {
                        paginatorLinksAfterCurrent.remove()
                    } else {
                        paginatorLinksAfterCurrent.each((index, element) => {
                            let paginationLink = $(element)
                            if (paginator.getPageNo($(element).attr('href')) <= paginator.paginatedPageNo) {
                                paginationLink.remove()
                            }
                        })
                        let nextPageUrl = paginator.getPageUrl(paginator.paginatedPageNo + 1)
                        let nextPageLink = $('.wp-pagenavi a[href="'+ nextPageUrl +'"]')
                        if (nextPageLink.length === 0) {
                            let lastPageLink = $('.wp-pagenavi a:last')
                            lastPageLink.clone().insertAfter(currentPaginationElement).
                                text(paginator.paginatedPageNo + 1).removeClass('last').attr('href', nextPageUrl)
                        }
                    }
                }
            }
        })

        this._configurationManager.
            addFlagField(OPTION_MOVE_VIDEO_ATTRIBUTES_SECTION, 'Move the video attributes section from below the screenshot area to under the description.').
            addFlagField(OPTION_REMOVE_COMMENTS_SECTION, 'Remove comments area on video pages.').
            addFlagField(OPTION_REMOVE_IFRAME_SECTION, 'Remove iframe share section under video player.').
            addFlagField(OPTION_REMOVE_RELATED_VIDEOS_SECTION, 'Remove related videos section on video pages.').
            addRangeField(FILTER_VIDEOS_RATING, 0, 100, 'Filter videos by ratings.').
            addRangeField(FILTER_VIDEOS_YEAR, 0, new Date().getFullYear(), 'Filter videos by content release year.')

        // UI Events

        this._onBeforeUIBuild = () => {
            if (IS_VIDEO_PAGE) {
                this._moveVideoAttributesBelowDescription()
                this._removeCommentsSection()
                this._removeIFrameSection()
                this._removeRelatedVideosSection()
            }
        }

        this._onUIBuild = () =>
            this._uiGen.createSettingsSection().append([
                this._uiGen.createTabsSection(['Filters', 'UI', 'Stats'], [
                    this._uiGen.createTabPanel('Filters', true).append([
                        this._configurationManager.createElement(FILTER_VIDEOS_RATING),
                        this._configurationManager.createElement(FILTER_VIDEOS_YEAR),
                        this._uiGen.createSeparator(),
                        this._configurationManager.createElement(OPTION_DISABLE_COMPLIANCE_VALIDATION),
                    ]),
                    this._uiGen.createTabPanel('UI').append([
                        this._configurationManager.createElement(OPTION_MOVE_VIDEO_ATTRIBUTES_SECTION),
                        this._configurationManager.createElement(OPTION_REMOVE_COMMENTS_SECTION),
                        this._configurationManager.createElement(OPTION_REMOVE_IFRAME_SECTION),
                        this._configurationManager.createElement(OPTION_REMOVE_RELATED_VIDEOS_SECTION),
                        this._uiGen.createSeparator(),
                        this._configurationManager.createElement(CONFIG_PAGINATOR_THRESHOLD),
                        this._configurationManager.createElement(CONFIG_PAGINATOR_LIMIT),
                        this._configurationManager.createElement(OPTION_ALWAYS_SHOW_SETTINGS_PANE),
                    ]),
                    this._uiGen.createTabPanel('Stats').append([
                        this._uiGen.createStatisticsFormGroup(FILTER_VIDEOS_RATING),
                        this._uiGen.createStatisticsFormGroup(FILTER_VIDEOS_YEAR),
                        this._uiGen.createSeparator(),
                        this._uiGen.createStatisticsTotalsGroup(),
                    ]),
                ]),
                this._createSettingsFormActions(),
                this._uiGen.createSeparator(),
                this._uiGen.createStatusSection(),
            ])

        this._onAfterUIBuild = () => {
            this._uiGen.getSelectedSection()[0].userScript = this
        }

        // Compliance Events

        this._onGetItemLists = () => $('.midle_div,.list_videos')

        this._complianceFilters = [
            (videoItem) => this._validateRating(videoItem),
            (videoItem) => this._validateYear(videoItem),
        ]
    }

    _moveVideoAttributesBelowDescription ()
    {
        if (this._configurationManager.getValue(OPTION_MOVE_VIDEO_ATTRIBUTES_SECTION)) {
            let videoInfoBlock = $('.entry-utility')
            videoInfoBlock.insertBefore(videoInfoBlock.prev().prev())
        }
    }

    _removeCommentsSection ()
    {
        if (this._configurationManager.getValue(OPTION_REMOVE_COMMENTS_SECTION)) {
            $('.comments-area').remove()
        }
    }

    _removeIFrameSection ()
    {
        if (this._configurationManager.getValue(OPTION_REMOVE_IFRAME_SECTION)) {
            $('#tab_share').remove()
        }
    }

    _removeRelatedVideosSection ()
    {
        if (this._configurationManager.getValue(OPTION_REMOVE_RELATED_VIDEOS_SECTION)) {
            $('.related').remove()
        }
    }

    /**
     * Validate video source release year
     * @param {JQuery} videoItem
     * @return {boolean}
     * @private
     */
    _validateRating (videoItem)
    {
        let range = this._configurationManager.getValue(FILTER_VIDEOS_RATING)
        if (range.minimum > 0 || range.maximum > 0) {
            let rating = parseInt(videoItem.find('.rating').text().trim().replace('%', ''))
            return this._validator.validateRange(FILTER_VIDEOS_RATING, rating, [range.minimum, range.maximum])
        }
        return true
    }

    /**
     * Validate video view count
     * @param {JQuery} videoItem
     * @return {boolean}
     * @private
     */
    _validateYear (videoItem)
    {
        let range = this._configurationManager.getValue(FILTER_VIDEOS_YEAR)
        if (range.minimum > 0 || range.maximum > 0) {
            let yearFragments = videoItem.find('.title a').text().trim().split('(')
            let year = parseInt(yearFragments[yearFragments.length - 1].replace(')', ''))
            return this._validator.validateRange(FILTER_VIDEOS_YEAR, year, [range.minimum, range.maximum])
        }
        return true
    }
}

(new VideoCelebsSearchAndUITweaks).init()