Skip to content

Commit

Permalink
fix: mamba errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Acorn221 committed Jan 11, 2024
1 parent 29c0a61 commit eeb8bbd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
15 changes: 7 additions & 8 deletions src/contents/relay.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
import { relayMessage } from '@plasmohq/messaging';


relayMessage(
{
name: 'pong',
}
},
);

relayMessage(
{
name: 'getImages',
}
},
);

relayMessage(
{
name: 'getImageInfo',
}
},
);

relayMessage(
{
name: 'sendAnalyticsEvent',
}
},
);

relayMessage(
{
name: 'getProfile',
}
},
);

relayMessage(
{
name: 'getPeople',
}
},
);

relayMessage({
name: 'bumbleID',
})
});
14 changes: 13 additions & 1 deletion src/contentsHelpers/ImageHandler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable class-methods-use-this */
/* eslint-disable consistent-return */
/* eslint-disable no-restricted-syntax */
Expand Down Expand Up @@ -47,6 +48,8 @@ class ImageHandler {

site: Sites;

requestedImages: boolean = false;

/**
* @param {Boolean} debug
*/
Expand Down Expand Up @@ -107,6 +110,7 @@ class ImageHandler {
* Adds the images to the images array, then it prunes the old ones off (if the array gets to big)
*/
addNewImage(image: ImageType | ImageType[]) {
console.log('adding new image', image);
if (!image) return;
if (Array.isArray(image)) {
this.images.push(...image);
Expand Down Expand Up @@ -146,11 +150,19 @@ class ImageHandler {
try {
while (true) {
// eslint-disable-next-line no-await-in-loop

let complete = false;

if (!this.requestedImages) {
complete = true;
this.requestedImages = true;
}

const imageData = await sendToBackground({
name: 'getImages',
body: {
site: this.site,
complete: this.images.length === 0,
complete,
} as getImagesRequest,
});
if (debug) console.log(`Successfully got images for ${Sites[this.site]}, ${imageData.images.length} images`);
Expand Down
27 changes: 14 additions & 13 deletions src/contentsHelpers/MambaJamba.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable class-methods-use-this */
import ImageHandler from '@/contentsHelpers/ImageHandler';
import { createMambaOverlayNode } from './Misc';
import { Sites } from '@/misc/types';
import { Sites, type ImageType } from '@/misc/types';

/**
* This class handles the image overlay for mamba.ru
Expand Down Expand Up @@ -37,28 +38,28 @@ class MambaJamba extends ImageHandler {
const image = this.imagesOnPage[i];
const existingOverlay = image.parentElement.querySelector('div.overlayBox, div.topBox');
if (!existingOverlay) {
this.createOverlay(image);
const imageSrc = (image as HTMLImageElement).src;
const record = this.images.find((x) => x.url === imageSrc);
if (!record) {
console.log(`record not found in createOverlayNode ${imageSrc}`);
} else {
this.createOverlay(image, record);
}
} else {
// check to see if the overlay 'aria-url' matches the current image
const overlayURL = existingOverlay.getAttribute('aria-label');
const imageURL = this.images.find((x) => x.url === image.getAttribute('src'))?.url;
if (overlayURL !== imageURL) {
const record = this.images.find((x) => x.url === image.getAttribute('src'));
if (overlayURL !== record?.url && record) {
// if it doesn't, then remove the overlay and create a new one
existingOverlay.remove();
this.createOverlay(image);
this.createOverlay(image, record);
}
}
}
}

async createOverlay(image: Element): Promise<Element | null> {
const imageSrc = image.getAttribute('src');
const imageRecord = this.images.find((x) => x.url === imageSrc);
if (!imageRecord) {
console.log(`imageRecord not found in createOverlayNode ${imageSrc}`);
return null;
}
const overlayNode = createMambaOverlayNode(image, imageRecord);
async createOverlay(image: Element, record: ImageType): Promise<Element | null> {
const overlayNode = createMambaOverlayNode(image, record);
// append the overlay to the parent of the image
image.parentElement.appendChild(overlayNode);

Expand Down

0 comments on commit eeb8bbd

Please sign in to comment.