WIP localstorage + add search > marketplace
parent
cc92d897b7
commit
e1584b3a9f
|
@ -8,13 +8,35 @@
|
||||||
// @website https://github.com/turtlebasket/userscripts/tree/master/github-distractionless
|
// @website https://github.com/turtlebasket/userscripts/tree/master/github-distractionless
|
||||||
// @license MIT
|
// @license MIT
|
||||||
// @description Userscript that makes sure that GitHub stays a work tool and doesn't turn into a social media website
|
// @description Userscript that makes sure that GitHub stays a work tool and doesn't turn into a social media website
|
||||||
// @run-at document-end
|
// @run-at document-idle
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
let hideEls = [];
|
let hideEls = [];
|
||||||
let focusing = false;
|
|
||||||
let urlPath = new URL(window.location.href).pathname;
|
let urlPath = new URL(window.location.href).pathname;
|
||||||
|
|
||||||
|
function runHideEls() {
|
||||||
|
for (let el of hideEls) {
|
||||||
|
el.setAttribute(
|
||||||
|
"style",
|
||||||
|
getFocusing() ? "display: none;" : "display: auto;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFocusing() {
|
||||||
|
let focusStatus = Boolean(localStorage.getItem("focusOn"));
|
||||||
|
if (focusStatus == null) {
|
||||||
|
localStorage.setItem(String(true))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleFocusing() {
|
||||||
|
localStorage.setItem(String(!getFocusing()));
|
||||||
|
if (getFocusing()) {
|
||||||
|
runHideEls();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// title bar links - custom behavior for now
|
// title bar links - custom behavior for now
|
||||||
const titleBarExclude = ["Explore", "Marketplace", "Codespaces"];
|
const titleBarExclude = ["Explore", "Marketplace", "Codespaces"];
|
||||||
let titleBarEls = document.getElementsByClassName("js-selected-navigation-item")
|
let titleBarEls = document.getElementsByClassName("js-selected-navigation-item")
|
||||||
|
@ -26,13 +48,15 @@ for (let i = 0; i < titleBarEls.length; i++) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// general exclusion list
|
// general exclusion list
|
||||||
|
// [<class>, <instances of occurrence>, <page filter>]
|
||||||
|
|
||||||
[
|
[
|
||||||
["mail-status unread", [0], /^.*$/],
|
["mail-status unread", [0], /^.*$/],
|
||||||
["UnderlineNav-item", [1], /^\/$/],
|
["UnderlineNav-item", [1], /^\/$/],
|
||||||
|
["menu-item", [6], /^\/search[.*]$/],
|
||||||
]
|
]
|
||||||
.forEach(([className, hideIndices, pathRegex]) => {
|
.forEach(([className, hideInstances, pathRegex]) => {
|
||||||
hideIndices.forEach(i => {
|
hideInstances.forEach(i => {
|
||||||
if (urlPath.search(pathRegex) > -1) {
|
if (urlPath.search(pathRegex) > -1) {
|
||||||
let el = document.getElementsByClassName(className)[i];
|
let el = document.getElementsByClassName(className)[i];
|
||||||
if (typeof el === 'undefined') {
|
if (typeof el === 'undefined') {
|
||||||
|
@ -45,18 +69,8 @@ for (let i = 0; i < titleBarEls.length; i++) {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// hide all els in els
|
|
||||||
function toggleFocus() {
|
|
||||||
focusing = !focusing;
|
|
||||||
for (let el of hideEls) {
|
|
||||||
el.setAttribute(
|
|
||||||
"style",
|
|
||||||
focusing ? "display: none;" : "display: auto;");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// initial state
|
// initial state
|
||||||
toggleFocus();
|
runHideEls();
|
||||||
|
|
||||||
// toggle switch
|
// toggle switch
|
||||||
// NOTE: WIP, currently bugged due to github content policy. add later
|
// NOTE: WIP, currently bugged due to github content policy. add later
|
||||||
|
@ -70,7 +84,7 @@ toggleFocus();
|
||||||
// padding: 2px 4px;
|
// padding: 2px 4px;
|
||||||
// font-size: 12pt;`;
|
// font-size: 12pt;`;
|
||||||
// const focusModeSwitch = document.createElement("button");
|
// const focusModeSwitch = document.createElement("button");
|
||||||
// focusModeSwitch.setAttribute("innerText", `Focus: ${focusing ? "on" : "off"}`);
|
// focusModeSwitch.setAttribute("innerText", `Focus: ${getFocusing() ? "on" : "off"}`);
|
||||||
// focusModeSwitch.setAttribute("style", btnStyle);
|
// focusModeSwitch.setAttribute("style", btnStyle);
|
||||||
// focusModeSwitch.setAttribute("onclick", toggleFocus)
|
// focusModeSwitch.setAttribute("onclick", toggleFocus)
|
||||||
// document.getElementsByClassName("Header js-details-container Details")[0]
|
// document.getElementsByClassName("Header js-details-container Details")[0]
|
||||||
|
|
Loading…
Reference in New Issue