GitHub Distractionless

Userscript that makes sure that GitHub stays a work tool and doesn't turn into a social media website

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        GitHub Distractionless
// @namespace   Violentmonkey Scripts
// @match       https://github.com/*
// @grant       none
// @version     0.1.1
// @author      turtlebasket
// @website     https://github.com/turtlebasket/userscripts/tree/master/github-distractionless
// @license     MIT
// @description Userscript that makes sure that GitHub stays a work tool and doesn't turn into a social media website
// @run-at      document-end
// ==/UserScript==

let hideEls = [];
let focusing = false;

// title bar links - custom behavior for now
const titleBarExclude = ["Explore", "Marketplace", "Codespaces"];
let titleBarEls = document.getElementsByClassName("js-selected-navigation-item")
for (let i = 0; i < titleBarEls.length; i++) {
    let el = titleBarEls[i];
    if (titleBarExclude.includes(el.innerHTML.trim())) {
        hideEls.push(el);
    }
}

// general exclusion list

[
    ["mail-status unread", [0], /.*/],
    ["UnderlineNav-item", [1], /^\/$/],
]
.forEach(([className, hideIndices, pageRegex]) => {
    hideIndices.forEach(i => {
        let el = document.getElementsByClassName(className)[i];
        if (typeof el === 'undefined') {
            console.log(`focus mode: unable to find element ${className} [ ${i} ]`)
        }
        else {
            hideEls.push(el);
        }
    });
})

// hide all els in els
function toggleFocus() {
    focusing = !focusing;
    for (let el of hideEls) {
        el.setAttribute(
            "style", 
            focusing ? "display: none;" : "display: auto;");
    }
}

// initial state
toggleFocus();

// toggle switch coming later, currently bugged due to github content policy