Skip to content

Commit

Permalink
Merge pull request #70 from cachho/chore/UpdateToNewQcPhotos
Browse files Browse the repository at this point in the history
chore: update to match new qc.photos api
  • Loading branch information
cachho authored Jul 5, 2023
2 parents 9348331 + 017b435 commit 672f171
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/content_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ async function main(settings: Settings) {
try {
if (settings.onlineFeaturesQcPhotos) {
const qcAvailable = await promiseQcAvailable;
if (qcAvailable && qcAvailable.state === 0 && qcAvailable.data) {
addQcElement(qcAvailable, elem);
if (qcAvailable?.success && qcAvailable.data?.product_has_qc) {
addQcElement(link, elem);
}
}
} catch (qcAvailableError) {
Expand Down
7 changes: 2 additions & 5 deletions src/lib/api/getQcAvailable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ export async function getQcAvailable(
cnLink: CnLink
): Promise<QcAvailable | null> {
const link = encodeURIComponent(cnLink.as('raw').href);
const url = `https://product2.rep.ninja/checkforqc?key=reparchiveqctest&url=${link}`;
const url = `https://api.qc.photos/v3/checkIfProductHasQcImages?url=${link}`;
const d = await fetchData(url);
return {
...d,
link: `https://qc.photos/?url=${link}`,
};
return d;
}
9 changes: 3 additions & 6 deletions src/lib/html/addQcElement.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import type { QcAvailable } from '../../models';
import type { CnLink } from 'cn-links';

export function addQcElement(
qcAvailable: QcAvailable,
link: HTMLAnchorElement
) {
export function addQcElement(cnLink: CnLink, link: HTMLAnchorElement) {
const elem = document.createElement('a');
elem.href = qcAvailable.link;
elem.href = `https://qc.photos/?url=${cnLink.as('raw')}`;
elem.target = '_blank';
elem.rel = 'nofollow norefferer noopener';
elem.textContent = '📷';
Expand Down
9 changes: 8 additions & 1 deletion src/models/QcAvailable.ts
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
export type QcAvailable = { data: boolean; state: 0 | 1; link: string };
export type QcAvailable = {
data?: {
product_has_qc: boolean;
qc_platform_with_qc_found: string;
};
message: string;
success: boolean;
};
10 changes: 5 additions & 5 deletions src/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { getImageAgent } from './lib/html/getImageAgent';
import { getPlatformImage } from './lib/html/getPlatformImage';
import { loadSettings } from './lib/loadSettings';
import type { Agent, AgentWithRaw, CurrentPage, QcAvailable } from './models';
import type { Agent, AgentWithRaw, CurrentPage } from './models';

const BodyElement = () => {
const elem = document.createElement('div');
Expand All @@ -32,8 +32,8 @@ const BodyElement = () => {
return elem;
};

const QC = (response: QcAvailable) => {
const qc = Button(response.link);
const QC = (link: CnLink) => {
const qc = Button(`https://qc.photos/?url=${link.as('raw')}`);
qc.innerText = `📷 QC Pics available`;
return qc;
};
Expand Down Expand Up @@ -144,8 +144,8 @@ async function toolbar() {
} else {
try {
const response = await getQcAvailable(currentPage.link);
if (response && response.state === 0 && response.data) {
qcString = QC(response).outerHTML;
if (response?.success && response.data?.product_has_qc) {
qcString = QC(currentPage.link).outerHTML;
}
} catch (err) {
console.error(err);
Expand Down

0 comments on commit 672f171

Please sign in to comment.