Gitlab Wiki Player

Play Gitlab wiki like PPT!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name              Gitlab Wiki Player
// @name:zh-cn        Gitlab WIKI 播放器
// @namespace         http://chengxuan.li
// @version           0.1
// @description       Play Gitlab wiki like PPT!
// @description:zh-cn 像PPT一样播放Gitlab WIKI
// @author            Leelmes <[email protected]>
// @match             http*://*/*/wikis/*
// @contributionURL   https://www.paypal.me/flyhope
// @supportURL        https://github.com/flyhope/gitlab-script/issues
// @license           GNU General Public License v3.0 or later
// ==/UserScript==
(function() {
    'use strict';

    // WIKI每页数据
    let wikis = [];

    // 当前看的是第几页(从0开始计算)
    let current = -1;

    // 检测是否可以执行
    if (typeof jQuery !== "undefined" && $("header.navbar-gitlab").length) {
        main();
    }

    // 主入口
    function main() {
        // 插入播放按钮
        $(".nav-controls").prepend('<a id="wiki-ppt-play" class="btn" href="javascript:void(0)"><span class="fa fa-play"></span></a>');

        // 绑定PPT按钮播放事件
        $("#wiki-ppt-play").click(play);
    }

    // 执行播放操作
    function play() {
        // 删除除主体外全部元素
        $("#feedly-mini,aside,header,.nav-sidebar,.wiki-page-header,.alert-wrapper").remove();
        $(".content-wrapper").removeClass("content-wrapper");
        $(".layout-page").removeClass("page-with-contextual-sidebar right-sidebar-expanded");

        // 整理数据,并清空现有WIKI数据结构
        if (!wikis.length) {
            $(".wiki").children().each(function(k, v){
                let index = wikis.length - 1;
                let newIndex = false;
                if (index < 0) {
                    index = 0;
                    newIndex = true;
                }
                if (v.tagName === "H2") {
                    index++;
                    newIndex = true;
                }

                if (newIndex) {
                    wikis[index] = [];
                }

                wikis[index].push(v)
            })
        }

        // 开始播放
        current = -1;
        $(".wiki").html("");
        next();
        $("body").css("zoom", "2.5")

        // 绑定按键
        $("body").keydown(function(e){
            switch (e.which) {
                case 37 :
                    prev();
                    break;
                case 39 :
                    next();
                    break;
            }
        });

    }

    // 下一页
    function next() {
        if (wikis.length >= current + 2) {
            current++;
            show(current);
        }
    }

    // 上一页
    function prev() {
        if (current > 0) {
            current--;
            show(current);
        }
    }

    // 展示内容
    function show(index) {
        $(".wiki").html("").hide().append(wikis[index]).fadeIn();
        $("body,html").scrollTop(0);
    }

})()