Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions src/features/accesskit/disable_gifs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import { canvas, div } from '../../utils/dom.js';
import { buildStyle, postSelector } from '../../utils/interface.js';
import { memoize } from '../../utils/memoize.js';
import { pageModifications } from '../../utils/mutations.js';
import { getPreferences } from '../../utils/preferences.js';

/** @type {AbortController} */ let loadEventController;
/** @type {"eager" | "lazy"} */ let loadingMode;

const canvasClass = 'xkit-paused-gif-placeholder';
const pausedPosterAttribute = 'data-paused-gif-use-poster';
const pausedBackgroundImageVar = '--xkit-paused-gif-background-image';
const hoverContainerAttribute = 'data-paused-gif-hover-container';
const labelAttribute = 'data-paused-gif-label';
Expand Down Expand Up @@ -65,7 +62,6 @@ export const styleElement = buildStyle(`
.${canvasClass}${parentHovered},
[${labelAttribute}="after"]${hovered}::after,
[${labelAttribute}="before"]${hovered}::before,
[${pausedPosterAttribute}]:not(${hovered}) > ${keyToCss('loader')} > ${keyToCss('knightRiderLoader')},
[${labelAttribute}]:not(${hovered}) > ${keyToCss('loader')} > ${keyToCss('knightRiderLoader')} {
display: none !important;
}
Expand All @@ -75,16 +71,6 @@ ${keyToCss('background')}[${labelAttribute}="before"]::before {
display: none;
}

[${pausedPosterAttribute}]:not(${hovered}) > img${keyToCss('poster')} {
visibility: visible !important;
}
[${pausedPosterAttribute}="eager"]:not(${hovered}) > img:not(${keyToCss('poster')}) {
visibility: hidden !important;
}
[${pausedPosterAttribute}="lazy"]:not(${hovered}) > img:not(${keyToCss('poster')}) {
display: none;
}

[style*="${pausedBackgroundImageVar}"]:not(${hovered}) {
background-image: var(${pausedBackgroundImageVar}) !important;
}
Expand Down Expand Up @@ -206,13 +192,6 @@ const processGifs = function (gifElements) {

gifElement.decoding = 'sync';

const posterElement = gifElement.parentElement.querySelector(keyToCss('poster'));
if (posterElement) {
gifElement.parentElement.setAttribute(pausedPosterAttribute, loadingMode);
addLabel(posterElement);
return;
}

if (gifElement.complete && gifElement.currentSrc) {
pauseGif(gifElement);
} else {
Expand Down Expand Up @@ -271,13 +250,6 @@ const processRows = function (rowsElements) {
const processHoverableElements = elements =>
elements.forEach(element => element.toggleAttribute(hoverContainerAttribute, true));

const onStorageChanged = async function (changes) {
const { 'accesskit.preferences.disable_gifs_loading_mode': modeChanges } = changes;
if (modeChanges?.oldValue === undefined) return;

loadingMode = modeChanges.newValue;
};

const processNativeGifPlayButtons = async buttons => {
buttons.forEach(button => button.click());

Expand All @@ -298,8 +270,6 @@ const processNativeGifPlayButtons = async buttons => {
export const main = async function () {
loadEventController = new AbortController();

({ disable_gifs_loading_mode: loadingMode } = await getPreferences('accesskit'));

const gifImage = `
:is(
${
Expand Down Expand Up @@ -340,13 +310,10 @@ export const main = async function () {
`:is(${postSelector}, ${keyToCss('blockEditorContainer')}) ${keyToCss('rows')}`,
processRows,
);

browser.storage.local.onChanged.addListener(onStorageChanged);
};

export const clean = async function () {
loadEventController.abort();
browser.storage.local.onChanged.removeListener(onStorageChanged);

pageModifications.unregister(processGifs);
pageModifications.unregister(processBackgroundGifs);
Expand All @@ -362,7 +329,6 @@ export const clean = async function () {
$(`.${canvasClass}`).remove();
$(`[${labelAttribute}]`).removeAttr(labelAttribute);
$(`[${labelSizeAttribute}]`).removeAttr(labelSizeAttribute);
$(`[${pausedPosterAttribute}]`).removeAttr(pausedPosterAttribute);
$(`[${hoverContainerAttribute}]`).removeAttr(hoverContainerAttribute);
[...document.querySelectorAll(`[style*="${pausedBackgroundImageVar}"]`)]
.forEach(element => element.style.removeProperty(pausedBackgroundImageVar));
Expand Down
9 changes: 0 additions & 9 deletions src/features/accesskit/feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
"label": "Pause GIFs until they are hovered over",
"default": false
},
"disable_gifs_loading_mode": {
"type": "select",
"label": "Download paused GIFs",
"options": [
{ "value": "eager", "label": "immediately" },
{ "value": "lazy", "label": "when hovered" }
],
"default": "eager"
},
"boring_tag_chiclets": {
"type": "checkbox",
"label": "De-animate the Changes/Staff Picks/etc. links carousel",
Expand Down