Skip to content

Commit

Permalink
Initial Implementation of light theming
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Mar 10, 2016
1 parent 4ff8387 commit 09aaf2c
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 38 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ included will not be changed from the defaults. `enabled` is set to false by de

### States

#### `enableAll`
Enables the current custom theme for ALL custom colors. Everything becomes themed

### `enableHighlight`
Enables the current custom theme but ONLY uses the custom highlight color. Everything else remains standard Google Play Music styles.

#### `enable()`
Enables the current custom theme
Is a mirror of `enableAll`, present for backwards compatibility

#### `disable()`
Disables the current custom theme
Expand Down
70 changes: 55 additions & 15 deletions dist/gmusic-theme.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/gmusic-theme.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/gmusic-theme.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/_constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
CLASS_NAMESPACE: 'gmusic-theme',
CLASS_NAMESPACE_LIGHT: 'gmusic-theme-light',
};
2 changes: 1 addition & 1 deletion lib/generate-stylesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const reworkCSS = rework(styles)
// DEV: Adds a .custom selector to the beginning of all CSS selectors
.use(rework.namespace({
selector: '.' + CONSTANTS.CLASS_NAMESPACE,
root: 'body',
root: 'html',
namespaceBody: false,
}))
// DEV: Adds !important flag to all CSS rules
Expand Down
25 changes: 24 additions & 1 deletion lib/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ body {
background-color: <<BACK_HIGHLIGHT>>;
}

body.material,
body,
.material-detail-view .material-container-details .info .description,
.song-table th {
color: #efefef;
Expand Down Expand Up @@ -460,3 +460,26 @@ button.goog-buttonset-default:hover {
.material-detail-view .top-tracks {
background-color: <<BACK_PRIMARY>>;
}

/*
* Light theme specific things
*/

.gmusic-theme-light #material-app-bar {
background-color: <<FORE_SECONDARY>>;
}

.gmusic-theme-light .nav-item-container.selected {
color: <<FORE_SECONDARY>>;
}

body.gmusic-theme-light,
.gmusic-theme-light .material-detail-view .material-container-details .info .description,
.gmusic-theme-light .song-table th {
color: #212121;
}

.gmusic-theme-light .song-row .song-indicator {
background-image: url('ani_equalizer_black.gif');
background-size: 40px 40px;
}
74 changes: 57 additions & 17 deletions src/gmusic-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ const BASE_CSS = fs.readFileSync(__dirname + '/../build/rework.css', 'utf8');
const BASE_SVG = fs.readFileSync(__dirname + '/../lib/logo.svg', 'utf8');
const CONSTANTS = require('../lib/_constants');

const DEFAULTS = {
BACK_PRIMARY: '#222326',
BACK_SECONDARY: '#121314',
BACK_HIGHLIGHT: '#615F59',
FORE_PRIMARY: '#FFFFFF',
FORE_SECONDARY: '#1ED760',
};

window.GMusicTheme = class GMusicTheme {
/**
* Constructor for a new Google Music Theme API.
Expand All @@ -16,11 +24,11 @@ window.GMusicTheme = class GMusicTheme {
*/
constructor(options = {}) {
// DEV: Use the colors specified in the options or the default if it isn't set
this.BACK_PRIMARY = '#222326';
this.BACK_SECONDARY = '#121314';
this.BACK_HIGHLIGHT = '#615F59';
this.FORE_PRIMARY = '#FFFFFF';
this.FORE_SECONDARY = '#1ED760';
this.BACK_PRIMARY = DEFAULTS.BACK_PRIMARY;
this.BACK_SECONDARY = DEFAULTS.BACK_SECONDARY;
this.BACK_HIGHLIGHT = DEFAULTS.BACK_HIGHLIGHT;
this.FORE_PRIMARY = DEFAULTS.FORE_PRIMARY;
this.FORE_SECONDARY = DEFAULTS.FORE_SECONDARY;

this.enabled = false;
if (options.enabled) {
Expand All @@ -44,20 +52,40 @@ window.GMusicTheme = class GMusicTheme {
}

/**
* Enables the custom theme
*/
* Enabled the dark theme, this allows for backwards compatibility
*/
enable() {
document.body.classList.add(CONSTANTS.CLASS_NAMESPACE);
this.enabled = true;
this._drawLogo();
this.enableAll();
}

/**
* Enables the custom theme in dark mode (All colors)
*/
enableAll() {
this.disable();
document.querySelector('html').classList.add(CONSTANTS.CLASS_NAMESPACE);
this.enabled = 1;
this.redrawTheme();
}

/**
* Enables the custom theme in light mode (only highlight)
*/
enableHighlight() {
this.disable();
document.querySelector('html').classList.add(CONSTANTS.CLASS_NAMESPACE);
document.body.classList.add(CONSTANTS.CLASS_NAMESPACE_LIGHT);
this.enabled = 2;
this.redrawTheme();
}

/**
* Disables the custom theme
*/
disable() {
document.body.classList.remove(CONSTANTS.CLASS_NAMESPACE);
this.enabled = false;
document.querySelector('html').classList.remove(CONSTANTS.CLASS_NAMESPACE);
document.body.classList.remove(CONSTANTS.CLASS_NAMESPACE_LIGHT);
this.enabled = 0;
this._drawLogo();
}

Expand Down Expand Up @@ -132,13 +160,25 @@ window.GMusicTheme = class GMusicTheme {
}

_substituteColors(styleString) {
// DEV: If replacing all colors
if (this.enabled === 1) {
return styleString
.replace(/<<BACK_PRIMARY>>/g, this.BACK_PRIMARY)
.replace(/<<BACK_SECONDARY>>/g, this.BACK_SECONDARY)
.replace(/<<BACK_HIGHLIGHT>>/g, this.BACK_HIGHLIGHT)
.replace(/<<FORE_PRIMARY>>/g, this.FORE_PRIMARY)
.replace(/<<FORE_SECONDARY>>/g, this.FORE_SECONDARY)
.replace(/<<BACK_SECONDARY_O>>/g, this._rgba(this.BACK_SECONDARY, 0.5))
.replace(/<<NOTIMPORTANT>> \!important/g, '');
}
// DEV: Else remove all rules for anything that isn't the highlight color (foreSecondary)
return styleString
.replace(/<<BACK_PRIMARY>>/g, this.BACK_PRIMARY)
.replace(/<<BACK_SECONDARY>>/g, this.BACK_SECONDARY)
.replace(/<<BACK_HIGHLIGHT>>/g, this.BACK_HIGHLIGHT)
.replace(/<<FORE_PRIMARY>>/g, this.FORE_PRIMARY)
.replace(/\n.+<<BACK_PRIMARY>>.*;\n/g, '')
.replace(/\n.+<<BACK_SECONDARY>>.*;\n/g, '')
.replace(/\n.+<<BACK_HIGHLIGHT>>.*;\n/g, '')
.replace(/\n.+<<FORE_PRIMARY>>.*;\n/g, '')
.replace(/<<FORE_SECONDARY>>/g, this.FORE_SECONDARY)
.replace(/<<BACK_SECONDARY_O>>/g, this._rgba(this.BACK_SECONDARY, 0.5))
.replace(/\n.+<<BACK_SECONDARY_O>>.*;\n/g, '')
.replace(/<<NOTIMPORTANT>> \!important/g, '');
}
};

0 comments on commit 09aaf2c

Please sign in to comment.