Changeset 2709451
- Timestamp:
- 04/14/2022 12:15:36 AM (4 years ago)
- Location:
- editor-beautifier/trunk
- Files:
-
- 2 edited
-
js/light-or-dark-bg.js (modified) (6 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
editor-beautifier/trunk/js/light-or-dark-bg.js
r2669493 r2709451 2 2 3 3 function adjustTextColor() { 4 5 element = document.getElementById('profile-bio');4 5 element = document.getElementById('profile-bio'); 6 6 wpBlocks = document.querySelectorAll('.wp-block-group'); 7 7 8 8 [].forEach.call(wpBlocks, function(wpBlock) { 9 9 // Get the element's background color 10 bgColor = window.getComputedStyle(wpBlock, null).getPropertyValue('background-color');10 bgColor = window.getComputedStyle(wpBlock, null).getPropertyValue('background-color'); 11 11 console.log("bgColor",bgColor); 12 12 // Call lightOrDark function to get the brightness (light or dark) … … 35 35 36 36 // If RGB --> Convert it to HEX: http://gist.github.com/983661 37 color = +("0x" + color.slice(1).replace( 38 color.length < 5 && /./g, '$&$&'37 color = +("0x" + color.slice(1).replace( 38 color.length < 5 && /./g, '$&$&' 39 39 ) 40 );40 ); 41 41 42 42 r = color >> 16; … … 47 47 // HSP (Highly Sensitive Poo) equation from http://alienryderflex.com/hsp.html 48 48 hsp = Math.sqrt( 49 0.299 * (r * r) +50 0.587 * (g * g) +51 0.114 * (b * b)49 0.299 * (r * r) + 50 0.587 * (g * g) + 51 0.114 * (b * b) 52 52 ); 53 53 … … 61 61 62 62 window.addEventListener('load', (event) => { 63 adjustTextColor(); 64 65 66 const targetNode = document.querySelector(".wp-block-group"); 63 64 adjustTextColor(); 65 const targetNodes = document.querySelectorAll(".wp-block-group"); 67 66 const config = { childList: false, subtree: true ,attributes: true, attributeOldValue: true}; 68 67 … … 72 71 if(mutation.oldValue.startsWith("background-color")){ 73 72 adjustTextColor(); 74 } 73 } 75 74 } 76 75 } … … 78 77 79 78 const observer = new MutationObserver(callback); 80 observer.observe(targetNode, config); 79 80 [].forEach.call(targetNodes, function(targetNode) { 81 observer.observe(targetNode, config); 82 }); 83 81 84 }); 82 83 -
editor-beautifier/trunk/readme.txt
r2613970 r2709451 48 48 == Changelog == 49 49 50 = 2.1, Apr 13 2022 = 51 * Fix background color detector script 52 50 53 = 2.0, Oct 16 2021 = 51 54 * Fix block-editors colors depending on background lightness
Note: See TracChangeset
for help on using the changeset viewer.