Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
a2a7668840
1 changed files with 52 additions and 42 deletions
|
@ -298,56 +298,66 @@ class Tinter {
|
||||||
|
|
||||||
for (let i = 0; i < document.styleSheets.length; i++) {
|
for (let i = 0; i < document.styleSheets.length; i++) {
|
||||||
const ss = document.styleSheets[i];
|
const ss = document.styleSheets[i];
|
||||||
if (!ss) continue; // well done safari >:(
|
try {
|
||||||
// Chromium apparently sometimes returns null here; unsure why.
|
if (!ss) continue; // well done safari >:(
|
||||||
// see $14534907369972FRXBx:matrix.org in HQ
|
// Chromium apparently sometimes returns null here; unsure why.
|
||||||
// ...ah, it's because there's a third party extension like
|
// see $14534907369972FRXBx:matrix.org in HQ
|
||||||
// privacybadger inserting its own stylesheet in there with a
|
// ...ah, it's because there's a third party extension like
|
||||||
// resource:// URI or something which results in a XSS error.
|
// privacybadger inserting its own stylesheet in there with a
|
||||||
// See also #vector:matrix.org/$145357669685386ebCfr:matrix.org
|
// resource:// URI or something which results in a XSS error.
|
||||||
// ...except some browsers apparently return stylesheets without
|
// See also #vector:matrix.org/$145357669685386ebCfr:matrix.org
|
||||||
// hrefs, which we have no choice but ignore right now
|
// ...except some browsers apparently return stylesheets without
|
||||||
|
// hrefs, which we have no choice but ignore right now
|
||||||
|
|
||||||
// XXX seriously? we are hardcoding the name of vector's CSS file in
|
// XXX seriously? we are hardcoding the name of vector's CSS file in
|
||||||
// here?
|
// here?
|
||||||
//
|
//
|
||||||
// Why do we need to limit it to vector's CSS file anyway - if there
|
// Why do we need to limit it to vector's CSS file anyway - if there
|
||||||
// are other CSS files affecting the doc don't we want to apply the
|
// are other CSS files affecting the doc don't we want to apply the
|
||||||
// same transformations to them?
|
// same transformations to them?
|
||||||
//
|
//
|
||||||
// Iterating through the CSS looking for matches to hack on feels
|
// Iterating through the CSS looking for matches to hack on feels
|
||||||
// pretty horrible anyway. And what if the application skin doesn't use
|
// pretty horrible anyway. And what if the application skin doesn't use
|
||||||
// Vector Green as its primary color?
|
// Vector Green as its primary color?
|
||||||
// --richvdh
|
// --richvdh
|
||||||
|
|
||||||
// Yes, tinting assumes that you are using the Riot skin for now.
|
// Yes, tinting assumes that you are using the Riot skin for now.
|
||||||
// The right solution will be to move the CSS over to react-sdk.
|
// The right solution will be to move the CSS over to react-sdk.
|
||||||
// And yes, the default assets for the base skin might as well use
|
// And yes, the default assets for the base skin might as well use
|
||||||
// Vector Green as any other colour.
|
// Vector Green as any other colour.
|
||||||
// --matthew
|
// --matthew
|
||||||
|
|
||||||
if (ss.href && !ss.href.match(new RegExp('/theme-' + this.theme + '.css$'))) continue;
|
// stylesheets we don't have permission to access (eg. ones from extensions) have a null
|
||||||
if (ss.disabled) continue;
|
// href and will throw exceptions if we try to access their rules.
|
||||||
if (!ss.cssRules) continue;
|
if (!ss.href || !ss.href.match(new RegExp('/theme-' + this.theme + '.css$'))) continue;
|
||||||
|
if (ss.disabled) continue;
|
||||||
|
if (!ss.cssRules) continue;
|
||||||
|
|
||||||
if (DEBUG) console.debug("calcCssFixups checking " + ss.cssRules.length + " rules for " + ss.href);
|
if (DEBUG) console.debug("calcCssFixups checking " + ss.cssRules.length + " rules for " + ss.href);
|
||||||
|
|
||||||
for (let j = 0; j < ss.cssRules.length; j++) {
|
for (let j = 0; j < ss.cssRules.length; j++) {
|
||||||
const rule = ss.cssRules[j];
|
const rule = ss.cssRules[j];
|
||||||
if (!rule.style) continue;
|
if (!rule.style) continue;
|
||||||
if (rule.selectorText && rule.selectorText.match(/#mx_theme/)) continue;
|
if (rule.selectorText && rule.selectorText.match(/#mx_theme/)) continue;
|
||||||
for (let k = 0; k < this.cssAttrs.length; k++) {
|
for (let k = 0; k < this.cssAttrs.length; k++) {
|
||||||
const attr = this.cssAttrs[k];
|
const attr = this.cssAttrs[k];
|
||||||
for (let l = 0; l < this.keyRgb.length; l++) {
|
for (let l = 0; l < this.keyRgb.length; l++) {
|
||||||
if (rule.style[attr] === this.keyRgb[l]) {
|
if (rule.style[attr] === this.keyRgb[l]) {
|
||||||
this.cssFixups[this.theme].push({
|
this.cssFixups[this.theme].push({
|
||||||
style: rule.style,
|
style: rule.style,
|
||||||
attr: attr,
|
attr: attr,
|
||||||
index: l,
|
index: l,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Catch any random exceptions that happen here: all sorts of things can go
|
||||||
|
// wrong with this (nulls, SecurityErrors) and mostly it's for other
|
||||||
|
// stylesheets that we don't want to proces anyway. We should not propagate an
|
||||||
|
// exception out since this will cause the app to fail to start.
|
||||||
|
console.log("Failed to calculate CSS fixups for a stylesheet: " + ss.href, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
|
Loading…
Reference in a new issue