mirror of
https://akkoma.dev/AkkomaGang/akkoma-fe
synced 2025-04-30 19:19:29 +08:00
Check for canvas extract permission when initializing favicon service
This commit is contained in:
parent
2914eaf1ca
commit
6373c5a05d
1 changed files with 18 additions and 0 deletions
|
@ -1,3 +1,19 @@
|
||||||
|
const checkCanvasExtractPermission = () => {
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
canvas.width = 1;
|
||||||
|
canvas.height = 1;
|
||||||
|
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
if (!ctx) return false;
|
||||||
|
|
||||||
|
ctx.fillStyle = '#0f161e';
|
||||||
|
ctx.fillRect(0, 0, 1, 1);
|
||||||
|
|
||||||
|
const { data } = ctx.getImageData(0, 0, 1, 1);
|
||||||
|
|
||||||
|
return data.join(',') === '15,22,30,255';
|
||||||
|
};
|
||||||
|
|
||||||
const createFaviconService = () => {
|
const createFaviconService = () => {
|
||||||
const favicons = []
|
const favicons = []
|
||||||
const faviconWidth = 128
|
const faviconWidth = 128
|
||||||
|
@ -6,6 +22,8 @@ const createFaviconService = () => {
|
||||||
const gapWidth = 24
|
const gapWidth = 24
|
||||||
|
|
||||||
const initFaviconService = () => {
|
const initFaviconService = () => {
|
||||||
|
if (!checkCanvasExtractPermission()) return;
|
||||||
|
|
||||||
const nodes = document.querySelectorAll('link[rel="icon"]')
|
const nodes = document.querySelectorAll('link[rel="icon"]')
|
||||||
nodes.forEach(favicon => {
|
nodes.forEach(favicon => {
|
||||||
if (favicon) {
|
if (favicon) {
|
||||||
|
|
Loading…
Reference in a new issue