Created
November 19, 2023 14:24
-
-
Save qguv/1616e2cafdf5870cf229449daf31b5a5 to your computer and use it in GitHub Desktop.
Filimin fix gradient (User script)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Filimin fix gradient | |
// @version 1 | |
// @include https://manager.filimin.com/products/*/edit | |
// ==/UserScript== | |
function make_stops(start_deg, end_deg, n_stops) { | |
const stops = []; | |
const span_deg = ( | |
end_deg > start_deg | |
? (end_deg - start_deg) | |
: (360 - start_deg) + end_deg | |
); | |
const stop_deg = span_deg / n_stops; | |
for (let i = 0; i < n_stops; i++) { | |
stops.push((start_deg + i * stop_deg) % 360) | |
} | |
return stops; | |
} | |
const range_el = document.querySelector('span.text-xs.text-gray-500.font-mono'); | |
const range = range_el.innerHTML.trim(); | |
const [start_byte, end_byte] = range.substring(1, range.length - 1).split('–'); | |
const start_deg = start_byte * 360 / 256; | |
const end_deg = end_byte * 360 / 256; | |
const circle_el = document.querySelector('div.absolute.inset-0.w-14.h-14.opacity-60.rounded-full'); | |
const stops = make_stops(start_deg, end_deg, 36); | |
const stop_colors = stops.map(deg => `hsl(${deg} 100% 50%)`); | |
for (let el of document.querySelectorAll('div[style^="background: conic-gradient"]')) { | |
el.setAttribute('style', `background: conic-gradient(${stop_colors});`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment