Skip to content

Commit

Permalink
Update gitlab-wiki-play.js
Browse files Browse the repository at this point in the history
  • Loading branch information
flyhope authored Jul 3, 2020
1 parent 98356aa commit d75eb8c
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions wiki-play/gitlab-wiki-play.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// @name Gitlab Wiki Player
// @name:zh-cn Gitlab WIKI 播放器
// @namespace http://chengxuan.li
// @version 12.9.0
// @version 12.9.1
// @description Play Gitlab wiki like PPT!
// @description:zh-cn 像PPT一样播放Gitlab WIKI
// @author Leelmes <[email protected]>
// @match http*://*/*/wikis/*
// @match http*://*/*/merge_requests/*
// @match http*://*/*/snippets/*
// @match http*://*/*/issues/*
// @contributionURL https://www.paypal.me/flyhope
// @grant none
// @supportURL https://github.com/flyhope/gitlab-script/issues
Expand All @@ -33,9 +34,10 @@

// 主入口
function main() {
// 插入播放按钮
// 插入WIKI播放按钮
$(".nav-controls").prepend('<a id="wiki-ppt-play" class="btn" href="javascript:void(0)"><span class="fa fa-play"></span></a>');
$(".issue-btn-group,.detail-page-header-actions > .hidden-xs").prepend('<a id="wiki-ppt-play" class="btn pull-left" href="javascript:void(0)"><span class="fa fa-play"></span></a>');
// 插入MergeRequest、ISSUE播放按钮
$(".detail-page-header-actions a.btn:first").before('<a id="wiki-ppt-play" class="btn pull-left" href="javascript:void(0)"><span class="fa fa-play"></span></a>');

// 绑定PPT按钮播放事件
$("#wiki-ppt-play").click(function() {
Expand Down Expand Up @@ -63,8 +65,31 @@
$(".content-wrapper").removeClass("content-wrapper");
$(".layout-page").removeClass("page-with-contextual-sidebar right-sidebar-expanded").css("padding-left", 0);

// 删除mergeRequest除主体外全部元素
$(".alert-wrapper,.detail-page-header,.detail-page-description,.mr-state-widget,.content-block,.merge-request-tabs-holder,.mr-version-controls").remove();
// 删除mergeRequest除主体外全部元素,调整吸顶
let mergeRequestTimer;
let mergeRequestShow = () => {
if ($(".file-title").length) {
$(".alert-wrapper,.detail-page-header,.mr-state-widget,.merge-request-tabs-holder,.mr-version-controls").remove();
$(".file-title").css("top", 0);
clearInterval(mergeRequestTimer)
}
}

// MergeRequest调整
if (location.href.search("/merge_requests/") > 0) {
if ($("#diffs-tab.active").length) {
mergeRequestShow()
} else {
$("#diffs-tab a").trigger("click")
mergeRequestTimer = setInterval(mergeRequestShow, 200)
}
}

// 删除ISSUE讨论区,并全屏
if (location.href.search("/issues/") > 0) {
$(".emoji-block,.issuable-discussion").remove();
fullScreen()
}

if ($wiki.length) {
// 整理数据,并清空现有WIKI数据结构
Expand Down Expand Up @@ -93,8 +118,8 @@

// 开始播放
$wiki.empty();
$("body").css("zoom", "2");
show(show_index)
fullScreen()
}

// 绑定按键
Expand Down Expand Up @@ -142,4 +167,18 @@
});
}

// 全屏
function fullScreen() {
let element = document.documentElement;
if(element.requestFullscreen) {
element.requestFullscreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
$("body").css("zoom", "2");
};
})()

0 comments on commit d75eb8c

Please sign in to comment.