Fix text replace bug.

This commit is contained in:
the1812 2018-07-16 20:15:22 +08:00
parent be7b9e1272
commit b465ab47c3
2 changed files with 2 additions and 2 deletions

View File

@ -61,7 +61,7 @@ function getStyle(key, settings)
settings.filterBrightness = foreground === "#000" ? "0" : "100";
for (key of Object.keys(settings))
{
style = style.replace(`$${key}`, settings[key]);
style = style.replace(new RegExp("\\$" + key, "g"), settings[key]);
}
return style;
};

2
utils/common.min.js vendored
View File

@ -1 +1 @@
function waitForQuery(){const MaxRetry=30;let retry=0;const tryQuery=(query,condition,action,failed)=>{if(retry>=30)failed&&failed();else{const result=query();condition(result)?action(result):(retry++,setTimeout(()=>tryQuery(query,condition,action,failed),500))}};return tryQuery}function getStyle(key,settings){const style=GM_getResourceText(key),replaceCustomColor=(style,settings)=>{const foreground=(()=>{const regex=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(settings.customStyleColor),color=regex?{r:parseInt(regex[1],16),g:parseInt(regex[2],16),b:parseInt(regex[3],16)}:void 0;if(color){const grey=1-(.299*color.r+.587*color.g+.114*color.b)/255;return grey<.35?"#000":"#fff"}return"#fff"})();for(key of(settings.brightness=`${"#000"===foreground?"100":"0"}%`,settings.filterBrightness="#000"===foreground?"0":"100",Object.keys(settings)))style=style.replace(`$${key}`,settings[key]);return style};return replaceCustomColor(style,settings)}
function waitForQuery(){const MaxRetry=30;let retry=0;const tryQuery=(query,condition,action,failed)=>{if(retry>=30)failed&&failed();else{const result=query();condition(result)?action(result):(retry++,setTimeout(()=>tryQuery(query,condition,action,failed),500))}};return tryQuery}function getStyle(key,settings){const style=GM_getResourceText(key),replaceCustomColor=(style,settings)=>{const foreground=(()=>{const regex=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(settings.customStyleColor),color=regex?{r:parseInt(regex[1],16),g:parseInt(regex[2],16),b:parseInt(regex[3],16)}:void 0;if(color){const grey=1-(.299*color.r+.587*color.g+.114*color.b)/255;return grey<.35?"#000":"#fff"}return"#fff"})();for(key of(settings.brightness=`${"#000"===foreground?"100":"0"}%`,settings.filterBrightness="#000"===foreground?"0":"100",Object.keys(settings)))style=style.replace(new RegExp("\\$"+key,"g"),settings[key]);return style};return replaceCustomColor(style,settings)}