Check WooCommerce plugins

by PhilQ

HTML

<div id="result"></div>

CSS

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
	background: #e6e6e6;
	font-family: Proxima Nova, sans-serif;
}

#result {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 1em;
	margin: 2em;
}

#result > div {
	display: flex;
	flex-direction: row;
	gap: 1em;
	border-radius: 2em;
	padding: 1em;
	background: #fff;
}

#result > div > div {
	display: flex;
	flex-direction: column;
	justify-content: space-around;
	/*
	gap: 0.5em;
	justify-content: space-around;
	*/
	padding: 0.4em 0 0.25em;
}

.title {
	display: inline-block;
	width: 100%;
	font-weight: bold;
	font-size: 1.2em;
}

.version {
	font-family: monospace;
	font-size: 1.6em;
	color: #111;
}

img {
	flex-shrink: 0;
	width: 80px;
	height: 80px;
	border-radius: 1em;
	overflow: hidden;
}

JavaScript

let getPluginsInfo = async () => {

	const woo_plugins = [
		'automatewoo',
		'custom-user-registration-fields-for-woocommerce', // maybe replace with: custom-fields-for-woocommerce
		'storefront-powerpack',
		'woocommerce-memberships',
		'woocommerce-order-status-control',
		'woocommerce-subscriptions',
	];

	const results = await Promise.allSettled(
		woo_plugins
		// .slice(0, 1)
		.map(async (plugin) => {
			const url = `https://woocommerce.com/products/${plugin}/`;
			const docs = `https://woocommerce.com/document/${plugin}/`;

			const alt1 = ["https://cors-get-proxy.sirjosh.workers.dev/?url=", {}];
			const alt2 = ["https://proxy.cors.sh/", {'x-cors-api-key': 'temp_335333632c1cebcbc8a2386b1a9ba425'}];
			try {
				const response = await fetch(`${alt1[0]}${url}`, {
					headers: alt1[1],
					// headers: {
					// 	"Host": "woocommerce.com",
					// 	//"Content-Type": "application/json",
					// 	"Accept": "text/html",
					// },
					// mode: "no-cors",
					credentials: "omit",
					referrerPolicy: "no-referrer",
				});

				// if (!response.ok) {
				//   throw new Error(`Network response was not OK: ${response.status}`);
				// }
				// console.log(...response.headers);

				let body = await response.text();
				//console.log(body);

				// body = body.match(/<aside[^>]*>([\s\S]+)<\/aside>/i)?.[1];
				// console.log(body);

				body = body.match(/\sdata-props="({&quot;productId&quot;:[^"]+)"/i)?.[1];
				// console.log(body);

				const json = JSON.parse(body.replace(/&quot;/g, '"'));
				const name = json?.productName ?? 'unkown';
				const version = json?.version ?? 'unkown';
				const icon = json?.icon ?? false;

				return { name, version, icon };

				/*
				const p = document.createElement('div');
				p.append(body);
				console.log(plugin, p);

				const name = p.querySelector('.wccom-product-title__product-name')?.innerHTML ?? `Unknown [${plugin}]`;
				const latest_version =...