2023-02-10 11:04:30 -08:00
|
|
|
// ==UserScript==
|
|
|
|
// @name GitHub Distractionless
|
|
|
|
// @namespace Violentmonkey Scripts
|
2023-02-10 11:16:49 -08:00
|
|
|
// @match https://github.com/*
|
2023-02-10 11:04:30 -08:00
|
|
|
// @grant none
|
2023-02-10 11:31:35 -08:00
|
|
|
// @version 0.1.2
|
2023-02-10 11:04:30 -08:00
|
|
|
// @author turtlebasket
|
|
|
|
// @website https://github.com/turtlebasket/userscripts/tree/master/github-distractionless
|
2023-02-10 11:16:49 -08:00
|
|
|
// @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
|
2023-02-10 11:04:30 -08:00
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
let hideEls = [];
|
|
|
|
let focusing = false;
|
2023-02-10 11:31:21 -08:00
|
|
|
let urlPath = new URL(window.location.href).pathname;
|
2023-02-10 11:04:30 -08:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
[
|
2023-02-10 11:31:21 -08:00
|
|
|
["mail-status unread", [0], /^.*$/],
|
2023-02-10 11:04:30 -08:00
|
|
|
["UnderlineNav-item", [1], /^\/$/],
|
|
|
|
]
|
2023-02-10 11:31:21 -08:00
|
|
|
.forEach(([className, hideIndices, pathRegex]) => {
|
2023-02-10 11:04:30 -08:00
|
|
|
hideIndices.forEach(i => {
|
2023-02-10 11:31:21 -08:00
|
|
|
if (urlPath.search(pathRegex) > -1) {
|
|
|
|
let el = document.getElementsByClassName(className)[i];
|
|
|
|
if (typeof el === 'undefined') {
|
|
|
|
console.log(`focus mode: unable to find element ${className} [ ${i} ]`)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hideEls.push(el);
|
|
|
|
}
|
2023-02-10 11:04:30 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// NOTE: WIP, currently bugged due to github content policy. add later
|
|
|
|
|
|
|
|
// const btnStyle = `
|
|
|
|
// background-color: black;
|
|
|
|
// foreground-color: white;
|
|
|
|
// borde-color: white;
|
|
|
|
// border-width: 1px;
|
|
|
|
// margin-left: 4px;
|
|
|
|
// padding: 2px 4px;
|
|
|
|
// font-size: 12pt;`;
|
|
|
|
// const focusModeSwitch = document.createElement("button");
|
|
|
|
// focusModeSwitch.setAttribute("innerText", `Focus: ${focusing ? "on" : "off"}`);
|
|
|
|
// focusModeSwitch.setAttribute("style", btnStyle);
|
|
|
|
// focusModeSwitch.setAttribute("onclick", toggleFocus)
|
|
|
|
// document.getElementsByClassName("Header js-details-container Details")[0]
|
|
|
|
// .appendChild(focusModeSwitch);
|