Skip to content

Commit

Permalink
Correctly set CSS property priority
Browse files Browse the repository at this point in the history
Process style sheets at DOMContentLoaded
Bump version
  • Loading branch information
Gofake1 committed Oct 7, 2018
1 parent 71010eb commit 721eb76
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Nightlight/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.3</string>
<string>1.1</string>
<key>CFBundleVersion</key>
<string>7</string>
<key>LSApplicationCategoryType</key>
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Browse the internet more comfortably at night

Nightlight is a Safari app extension that darkens websites while attempting to preserve their original designs.

To Little Snitch users: you'll notice that SafariExtension sends HTTP(S) requests to work around Safari limitations.

### Acknowledgements

* [Solar](https://github.com/ceeK/Solar) (MIT)
Expand Down
2 changes: 1 addition & 1 deletion SafariExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0.3</string>
<string>1.1</string>
<key>CFBundleVersion</key>
<string>7</string>
<key>LSMinimumSystemVersion</key>
Expand Down
25 changes: 13 additions & 12 deletions SafariExtension/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,13 @@ function onMutation(mutations) {

// Darken before document finishes loading
function quickStart() {
return [BASIC].reduce(makeStyleSheetBuiltinBundle, []);
const builtin = [BASIC].reduce(makeStyleSheetBuiltinBundle, []);
const override = [].slice.call(document.styleSheets)
.reduce(makeStyleSheetOverrideBundle, []);
return builtin.concat(override);
}

function start() {
const styleSheets = [].slice.call(document.styleSheets)
.reduce(makeStyleSheetOverrideBundle, []);
const styleAttributes = [].slice.call(document.querySelectorAll('[style]'))
.reduce(makeStyleAttributeBundle, []);
const svgFills = [].slice.call(document.querySelectorAll('[fill]'))
Expand All @@ -302,7 +303,7 @@ function start() {
.reduce(makeSvgStopColorBundle, []);
const images = [].slice.call(document.getElementsByTagName('img'))
.reduce(makeImageBundle, []);
return styleSheets.concat(styleAttributes).concat(svgFills).concat(images);
return styleAttributes.concat(svgFills).concat(images);
}

// --- Bundle helpers ---
Expand Down Expand Up @@ -517,10 +518,11 @@ function makeRuleStr(str, rule) {
// Returns string
function makeSheetDeclStr(decl) {
function makeCtx(prop, f) {
return {
prop: prop,
value: decl[prop],
important: decl.getPropertyPriority(prop) == 'important',
return {
prop: prop,
value: decl[prop],
isImportant: decl.getPropertyPriority(CSS_NAME_FOR_PROP[prop]) ==
'important',
f: f
};
}
Expand All @@ -530,7 +532,7 @@ function makeSheetDeclStr(decl) {
const newValue = ctx.f(ctx.value);
if(newValue) {
str += CSS_NAME_FOR_PROP[ctx.prop]+':'+newValue+
(ctx.important ? ' !important;' : ';');
(ctx.isImportant ? '!important;' : ';');
}
}
return str;
Expand All @@ -556,7 +558,7 @@ function makeAttributeDeclStr(decl) {
function makeCtx(prop, f) {
return {
prop: prop,
important: decl.getPropertyPriority(prop) == 'important',
priority: decl.getPropertyPriority(CSS_NAME_FOR_PROP[prop]),
f: f
};
}
Expand All @@ -566,8 +568,7 @@ function makeAttributeDeclStr(decl) {
if(value == '') {
return;
}
decl.setProperty(CSS_NAME_FOR_PROP[ctx.prop], ctx.f(value),
(ctx.important ? 'important' : ''));
decl.setProperty(CSS_NAME_FOR_PROP[ctx.prop], ctx.f(value), ctx.priority);
}

const div = document.createElement('div');
Expand Down

0 comments on commit 721eb76

Please sign in to comment.