Toggle Sidebar in Fextralife

Adds a toggle button at the top left of fextralife pages that will show/hide the side menu.

当前为 2022-03-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Toggle Sidebar in Fextralife
// @namespace   Zharay Scripting
// @match       https://*.fextralife.com/*
// @grant       none
// @version     1.1
// @author      Zharay
// @description Adds a toggle button at the top left of fextralife pages that will show/hide the side menu.
// @license     MIT
// ==/UserScript==

var bIsToggled = false;
var sidewrapper = document.getElementById("sidebar-wrapper");
var wrapper = document.getElementById("wrapper");
var displayType = sidewrapper.style.display;
var paddingLeft = wrapper.style.paddingLeft;
var tglNode = document.createElement ('div');

tglNode.innerHTML = '<button id="sideTgl" type="button" class="btn btn-default">Toggle Sidebar</button>';
tglNode.setAttribute ('id', 'myContainer');
tglNode.setAttribute ('style', 'position:fixed;z-index=999;top:0;left:0');

function SideToggleAction (zEvent) {
    bIsToggled = !bIsToggled;
    sidewrapper = document.getElementById("sidebar-wrapper");
    sidewrapper.style.display = (bIsToggled ? displayType : "none");
    wrapper.style.paddingLeft = (bIsToggled ? paddingLeft : "0px");
}

function hideSidebar () {
    try {
        wrapper.style.paddingLeft = "0px";
    } catch (e) {}

    try {
        sidewrapper.style.display = "none";
    } catch (e) {}
}

(function() {
    if (sidewrapper) {
        hideSidebar();
        window.addEventListener('resize', function() { setTimeout(hideSidebar, 100); });
        document.body.appendChild (tglNode);
        document.getElementById ("sideTgl").addEventListener ( "click", SideToggleAction, false );
    }
}) ();