FF bug workaround: retranslate CSS content

This commit is contained in:
tophf 2017-06-10 14:08:03 +03:00
parent 2e86c95842
commit 2687d1e167
3 changed files with 37 additions and 1 deletions

12
dom.js
View File

@ -123,3 +123,15 @@ function $element(opt) {
} }
return element; return element;
} }
function retranslateCSS(selectorToMessageMap) {
// TODO: remove when this bug is fixed in FF
// Note: selectors must be spec-normalized e.g. ::before, not :before
for (const rule of document.styleSheets[0].cssRules) {
const msg = selectorToMessageMap[rule.selectorText];
if (msg) {
rule.style.content = '"' + msg.replace(/__MSG_(\w+)__/g, (_, id) => t(id)) + '"';
}
}
}

View File

@ -1,4 +1,4 @@
/* global messageBox, getStyleWithNoCode */ /* global messageBox, getStyleWithNoCode, retranslateCSS */
'use strict'; 'use strict';
let installed; let installed;
@ -31,6 +31,15 @@ Promise.all([
showStyles(styles); showStyles(styles);
}); });
if (FIREFOX) {
// TODO: remove when this bug is fixed in FF
retranslateCSS({
'.disabled h2::after':
'__MSG_genericDisabledLabel__',
'#update-all-no-updates[data-skipped-edited="true"]::after':
' __MSG_updateAllCheckSucceededSomeEdited__',
});
}
chrome.runtime.onMessage.addListener(onRuntimeMessage); chrome.runtime.onMessage.addListener(onRuntimeMessage);

View File

@ -1,3 +1,4 @@
/* global retranslateCSS */
'use strict'; 'use strict';
let installed; let installed;
@ -16,6 +17,20 @@ getActiveTabRealURL().then(url => {
}); });
}); });
if (FIREFOX) {
// TODO: remove when this bug is fixed in FF
retranslateCSS({
'.blocked::before':
'__MSG_stylusUnavailableForURL__',
'.blocked #installed::before':
'__MSG_stylusUnavailableForURLdetails__',
'.unreachable::before':
'__MSG_unreachableContentScript__',
'.unreachable #installed::before':
'__MSG_unreachableFileHint__',
});
}
chrome.runtime.onMessage.addListener(onRuntimeMessage); chrome.runtime.onMessage.addListener(onRuntimeMessage);
function onRuntimeMessage(msg) { function onRuntimeMessage(msg) {