🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Reddit Sticky Sidebar with Toggle

Keep sidebar visible while scrolling, add a toggle button.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         Reddit Sticky Sidebar with Toggle
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Keep sidebar visible while scrolling, add a toggle button.
// @author       IDW
// @license MIT
// @match        https://old.reddit.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=reddit.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var sidebar = document.querySelector('.side');

    if (sidebar) {
        var stickyContainer = document.createElement('div');
        stickyContainer.id = 'sticky-sidebar-container';
        stickyContainer.style.position = 'fixed';
        stickyContainer.style.top = '100px';
        stickyContainer.style.right = '0';
        stickyContainer.style.width = sidebar.offsetWidth + 'px';
        stickyContainer.style.zIndex = '1000';

        stickyContainer.style.transition = 'transform 0.05s ease-in-out';
        stickyContainer.style.transform = 'translateX(0)';

        sidebar.parentNode.insertBefore(stickyContainer, sidebar);
        stickyContainer.appendChild(sidebar);

        var header = document.querySelector('.tabmenu');

        if (header) {
            var toggleButton = document.createElement('li');
            toggleButton.className = 'toggle-sidebar-button';

            var toggleLink = document.createElement('a');
            toggleLink.href = '#';
            toggleLink.textContent = 'I≡I';

            var sidebarVisible = true;

            toggleLink.addEventListener('click', function(e) {
                e.preventDefault();
                if (sidebarVisible) {
                    var sidebarWidth = stickyContainer.offsetWidth;
                    stickyContainer.style.transform = 'translateX(' + (sidebarWidth + 20) + 'px)';
                } else {
                    // Afficher la sidebar
                    stickyContainer.style.transform = 'translateX(0)';
                }
                sidebarVisible = !sidebarVisible;
            });

            toggleButton.appendChild(toggleLink);
            header.appendChild(toggleButton);
        }
    }
})();