1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| if (document.getElementById('post-cover')) { const img = document.getElementById('post-cover').getAttribute('data-lazy-src') RGBaster.colors(img, { paletteSize: 30, exclude: ["rgb(255,255,255)", "rgb(0,0,0)", "rgb(254,254,254)"], success: function(t) { if (t.dominant != 'rgb()'){ const c = t.dominant.match(/\d+/g); const Color = `rgba(${c[0]},${c[1]},${c[2]},0.8)`; let fontColor; const grayLevel = c[0] * 0.213 + c[1] * 0.715 + c[2] * 0.072; if (grayLevel >= 255/2) { fontColor = '#000'; metaColor = '#1C1C1C'; } else { fontColor = '#fff'; metaColor = '#eee'; } document.styleSheets[0].addRule(":root", "--mj-main:" + Color + "!important") document.styleSheets[0].addRule(":root", "--mj-titlecolor:" + fontColor + "!important") document.styleSheets[0].addRule(":root", "--mj-metacolor:" + metaColor + "!important") } else { document.styleSheets[0].addRule(":root", "--mj-main: rgba(255,250,240,0.5) !important") document.styleSheets[0].addRule(":root", "--mj-titlecolor: #000 !important") document.styleSheets[0].addRule(":root", "--mj-metacolor: #1C1C1C !important") } }, error: function() { document.styleSheets[0].addRule(":root", "--mj-main: rgba(255,250,240,0.5) !important") document.styleSheets[0].addRule(":root", "--mj-titlecolor: #000 !important") document.styleSheets[0].addRule(":root", "--mj-metacolor: #1C1C1C !important") } }) } else { document.styleSheets[0].addRule(":root", "--mj-main: transparent !important") document.styleSheets[0].addRule(":root", "--mj-titlecolor: var(--light-grey) !important") }
|