Skip to content

Instantly share code, notes, and snippets.

@benok
Last active November 30, 2022 03:41
Show Gist options
  • Save benok/69b98fc38aa5884234fe50326ef014ae to your computer and use it in GitHub Desktop.
Save benok/69b98fc38aa5884234fe50326ef014ae to your computer and use it in GitHub Desktop.
GitHub Gist apply dark theme on secret Gists
// ==UserScript==
// @name GitHub Gist apply dark theme on secret Gists
// @namespace https://github.com/benok/
// @description Apply dark theme to your secret Gists on GitHub Gist
// @include https://gist.github.com/*
// @version 2022.11.30.1
// @homepage https://gist.github.com/benok/69b98fc38aa5884234fe50326ef014ae
// @downloadURL https://gist.github.com/benok/69b98fc38aa5884234fe50326ef014ae/raw/github-gist-apply-dark-theme-on-secret-gists.user.js
// @author benok
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
if ( (document.querySelector('span.Label.v-align-middle')||
document.querySelector('span.Label.Label--secondary')/* Editing page */).textContent.includes('Secret')) {
console.log('secret gist. set data-color-mode to dark');
document.querySelector('html').setAttribute('data-color-mode', 'dark');
} else {
console.log('public gist. set data-color-mode to light');
document.querySelector('html').setAttribute('data-color-mode', 'light');
}
})();
@benok
Copy link
Author

benok commented Jan 31, 2022

I'm not that good with JavaScript, so I'd be happy if you could fork this and implement support for the "All gists" tab!
(Please see also private repo version.)

@benok
Copy link
Author

benok commented Nov 30, 2022

Having trouble now.
Setting html's data-color-mode doesn't update the actual page theme. :-(
(Setting the default theme to dark, it works partially, but unstable. May be needed to change apply timing.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment