User:Phlsph7/Readability.js: Difference between revisions

Content deleted Content added
implement SMOG
allow alternate color scheme
Line 1:
/* Userscript to highlight sentences by readability */
 
// Set score colors for css if they have not been defined
var readabilityScoreColors = readabilityScoreColors || [
'rgb(255,96,96)',
'rgb(255,128,128)',
'rgb(255,192,128)',
'rgb(255,224,128)',
'rgb(255,255,128)',
'rgb(214,255,128)',
'rgb(171,255,128)',
'rgb(128,255,128)',
'rgb(128,255,171)',
'rgb(128,255,214)',];
 
 
// Goes through all the p-elements and splits their content into span-elements. Each span corresponds to a sentence.
Line 122 ⟶ 136:
'score-90-80',
'score-100-90'];
 
// css colors for the different score classes
const scoreColors = [
'rgb(255,96,96)',
'rgb(255,128,128)',
'rgb(255,192,128)',
'rgb(255,224,128)',
'rgb(255,255,128)',
'rgb(214,255,128)',
'rgb(171,255,128)',
'rgb(128,255,128)',
'rgb(128,255,171)',
'rgb(128,255,214)',];
// Loop through all sentences, add their score class and their title attribute.
Line 153 ⟶ 154:
 
// Add the style sheet to color the score classes.
addScoreStyleSheet(scoreClasses, scoreColorsreadabilityScoreColors);
 
function getScoreClass(score, scoreClasses){
Line 166 ⟶ 167:
}
 
function addScoreStyleSheet(scoreClasses, scoreColorsreadabilityScoreColors){
const style = document.createElement('style');
for(let i = 0; i < scoreClasses.length; i++){
style.innerHTML += `.${scoreClasses[i]} {background-color: ${scoreColorsreadabilityScoreColors[i]}; } `;
}
document.head.appendChild(style);