Skip to content

Commit

Permalink
Added Global/Current to Styles; Added Text-editor mode to Websites; O…
Browse files Browse the repository at this point in the history
…ther changes
  • Loading branch information
adokseo committed Sep 14, 2020
1 parent 85dc8c8 commit 6cf1fc0
Show file tree
Hide file tree
Showing 12 changed files with 872 additions and 843 deletions.
11 changes: 10 additions & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,14 @@
},
"websites": {
"message": "Websites"
},
"global": {
"message": "Global"
},
"current": {
"message": "Current"
},
"textEditorMode": {
"message": "Text editor mode"
}
}
}
35 changes: 28 additions & 7 deletions content-scripts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var settings = {};
var settings = {},
current_website;

function getFilters(settings) {
var string = '',
Expand All @@ -12,7 +13,7 @@ function getFilters(settings) {
bluelight.style.position = 'absolute';
bluelight.style.visibility = 'hidden';
bluelight.style.pointerEvents = 'none';
bluelight.innerHTML = '<svg version=1.1 xmlns=//www.w3.org/2000/svg viewBox="0 0 1 1"><filter id="bluelight-filter" color-interpolation-filters="sRGB"><feColorMatrix type=matrix values="1 0 0 0 0 0 1 0 0 0 0 0 ' + (1 - parseFloat(settings.bluelight) / 100) + ' 0 0 0 0 0 1 0"></feColorMatrix></filter></svg>';
bluelight.innerHTML = '<svg version=1.1 viewBox="0 0 1 1"><filter id="bluelight-filter" color-interpolation-filters="sRGB"><feColorMatrix type=matrix values="1 0 0 0 0 0 1 0 0 0 0 0 ' + (1 - parseFloat(settings.bluelight) / 100) + ' 0 0 0 0 0 1 0"></feColorMatrix></filter></svg>';

document.documentElement.appendChild(bluelight);

Expand All @@ -22,7 +23,7 @@ function getFilters(settings) {
}

if (settings.invert_colors === true || settings.invert_colors === undefined) {
string += 'html,body{background:#000 0 0}';
string += 'html,body{background:#000 0 0 !important}';
string += 'body > *,body [style*="url("],body [style*=background-position],body canvas,body iframe,body img:not([src*="/ic_"]):not([src*=_ic_]):not([class*=icon]),body pre,body video{-webkit-filter:invert(1)!important;filter:invert(1)!important}';
}

Expand Down Expand Up @@ -87,6 +88,16 @@ function update() {
} else if (schedule_time.to < schedule_time.from && current_time < schedule_time.to) {
schedule_time.from = 0;
}

if (settings.websites) {
for (var key in settings.websites) {
try {
if (location.hostname.indexOf(key) !== -1 || new RegExp(key).test(location.href)) {
current_website = settings.websites[key];
}
} catch (err) {}
}
}

for (var key in settings.websites) {
if (settings.websites[key].enabled === true) {
Expand All @@ -97,8 +108,8 @@ function update() {

var sett = {};

if (settings.websites && settings.websites[location.hostname] && settings.websites[location.hostname].filters) {
sett = settings.websites[location.hostname].filters;
if (settings.websites && current_website && current_website.filters) {
sett = current_website.filters;
}

if (sett.invert_colors === undefined) {
Expand Down Expand Up @@ -136,14 +147,20 @@ function update() {
) {
injectStyle(getFilters(sett), 'night-mode-extension-filters', settings.schedule);

if (settings.websites && settings.websites[location.hostname] && settings.websites[location.hostname].styles) {
injectStyle(settings.websites[location.hostname].styles, 'night-mode-extension-styles', settings.schedule);
injectStyle(settings.styles, 'night-mode-extension-global-styles', settings.schedule);

if (settings.websites && current_website && current_website.styles) {
injectStyle(current_website.styles, 'night-mode-extension-styles', settings.schedule);
}
} else {
if (document.querySelector('#night-mode-extension-filters')) {
document.querySelector('#night-mode-extension-filters').remove();
}

if (document.querySelector('#night-mode-extension-global-styles')) {
document.querySelector('#night-mode-extension-global-styles').remove();
}

if (document.querySelector('#night-mode-extension-styles')) {
document.querySelector('#night-mode-extension-styles').remove();
}
Expand All @@ -161,6 +178,10 @@ chrome.storage.onChanged.addListener(function(changes) {
document.querySelector('#night-mode-extension-filters').remove();
}

if (document.querySelector('#night-mode-extension-global-styles')) {
document.querySelector('#night-mode-extension-global-styles').remove();
}

if (document.querySelector('#night-mode-extension-styles')) {
document.querySelector('#night-mode-extension-styles').remove();
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Dark Mode",
"version": "1.25",
"version": "1.40",
"description": "Dark Mode, read at night. Blue Light Filter for Every Website. Relax your eyes at night and day.",

"default_locale": "en",
Expand Down
37 changes: 37 additions & 0 deletions popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ button
4.0 Title
5.0 Right section
6.0 Switch
7.0 Vertical menu
---------------------------------------------------------------*/

/*---------------------------------------------------------------
Expand Down Expand Up @@ -258,9 +259,15 @@ body[data-appearance='home'] .satus-text--title

.satus-switch--night-mode
{
display: none;
padding: 0;
}

body[data-appearance='home'] .satus-switch--night-mode
{
display: flex;
}

.satus-switch--night-mode:hover
{
background-color: transparent;
Expand All @@ -285,6 +292,21 @@ body[data-appearance='home'] .satus-text--title
{
background: #777;
}


/*---------------------------------------------------------------
7.0 VERTICAL MENU
---------------------------------------------------------------*/

.satus-dialog--vertical-menu-button
{
display: none
}

body[data-appearance='websites'] .satus-dialog--vertical-menu-button
{
display: block
}

/*---------------------------------------------------------------
>>> TABLE OF CONTENTS:
Expand All @@ -310,6 +332,21 @@ body[data-appearance='home'] .satus-text--title
flex: 1;
}

.websites-textfield
{
display: none
}

body[data-website-text-editor="true"] .websites-list
{
display: none
}

body[data-website-text-editor="true"] .websites-textfield
{
display: block
}


/*---------------------------------------------------------------
2.0 SECTION
Expand Down
Loading

0 comments on commit 6cf1fc0

Please sign in to comment.