From 0e14982fa3af1292b4ca20806b03397ed76d2c48 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sun, 30 May 2021 14:35:15 +0300 Subject: [PATCH] [userscripts] add some useless scripts --- .../github-set-theme-without-login.user.js | 17 +++++++++ .../gitlab-set-theme-without-login.user.js | 35 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 web/userscripts/github-set-theme-without-login.user.js create mode 100644 web/userscripts/gitlab-set-theme-without-login.user.js diff --git a/web/userscripts/github-set-theme-without-login.user.js b/web/userscripts/github-set-theme-without-login.user.js new file mode 100644 index 0000000..5dc9ad2 --- /dev/null +++ b/web/userscripts/github-set-theme-without-login.user.js @@ -0,0 +1,17 @@ +// ==UserScript== +// @name GitHub set theme without login +// @version 1 +// @grant none +// @match https://github.com/* +// @match https://gist.github.com/* +// @run-at document-start +// ==/UserScript== + +(() => { + 'use strict'; + + let $html = document.documentElement; + $html.dataset.colorMode = 'dark'; + $html.dataset.darkTheme = 'dark_dimmed'; + $html.dataset.lightTheme = 'light'; +})(); diff --git a/web/userscripts/gitlab-set-theme-without-login.user.js b/web/userscripts/gitlab-set-theme-without-login.user.js new file mode 100644 index 0000000..38f54af --- /dev/null +++ b/web/userscripts/gitlab-set-theme-without-login.user.js @@ -0,0 +1,35 @@ +// ==UserScript== +// @name GitLab set theme without login +// @description DOES NOT WORK +// @version 1 +// @grant none +// @match https://gitlab.com/* +// @match https://salsa.debian.org/* +// @run-at document-start +// ==/UserScript== + +(() => { + 'use strict'; + + for (let $link of document.getElementsByTagName('link')) { + if (!($link.as === 'style' || $link.rel === 'stylesheet')) continue; + + let pattern = /^(https:\/\/assets\.gitlab-static\.net\/assets\/)(.+)(-[0-9a-fA-F]{64}\.css)$/; + let matches = $link.href.match(pattern); + if (matches == null) continue; + let [hrefBefore, assetPath, hrefAfter] = matches.slice(1); + let newAssetPath = null; + + if (assetPath === 'application' || assetPath === 'application_utilities') { + newAssetPath = `${assetPath}_dark`; + } else if (assetPath === 'highlight/themes/white') { + newAssetPath = 'highlight/themes/dark'; + } + + if (newAssetPath == null) continue; + $link.href = `${hrefBefore}${newAssetPath}${hrefAfter}`; + } + + document.body.classList.remove('ui-indigo'); + document.body.classList.add('gl-dark'); +})();