Only replace CSS if the CSS changed

This commit is contained in:
Tamius Han 2019-08-24 17:04:53 +02:00
parent eeddbe9cc6
commit 13104609cd
2 changed files with 14 additions and 8 deletions

View File

@ -650,7 +650,8 @@ class Resizer {
if (!this.userCss) {
this.injectCss(newCssString);
this.userCss = newCssString;
} else {
} else if (newCssString !== this.userCss) {
// we only replace css if it
this.replaceCss(this.userCss, newCssString);
this.userCss = newCssString;
}

View File

@ -69,16 +69,21 @@ class UWServer {
}
}
async removeCss(css, sender) {
if (BrowserDetect.firefox || BrowserDetect.edge) {
browser.tabs.removeCSS(sender.tab.id, {code: css, cssOrigin: 'user', frameId: sender.frameId});
} else if (BrowserDetect.chrome) {
chrome.tabs.removeCSS(sender.tab.id, {code: css, cssOrigin: 'user', frameId: sender.frameId});
}
try {
if (BrowserDetect.firefox || BrowserDetect.edge) {
browser.tabs.removeCSS(sender.tab.id, {code: css, cssOrigin: 'user', frameId: sender.frameId});
} else if (BrowserDetect.chrome) {
// this doesn't work currently, but hopefully chrome will get this feature in the future
chrome.tabs.removeCSS(sender.tab.id, {code: css, cssOrigin: 'user', frameId: sender.frameId});
}
} catch (e) { }
}
async replaceCss(oldCss, newCss, sender) {
this.injectCss(newCss, sender);
this.removeCss(oldCss, sender);
if (oldCss !== newCss) {
this.injectCss(newCss, sender);
this.removeCss(oldCss, sender);
}
}
scheduleGc(timeout) {