fetch-css 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/package.json +4 -6
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{parse as e}from"acorn";import t from"rfdc";import n from"postcss";import{parseFragment as r}from"parse5";import i from"unzipper";import a from"url-toolkit";import o
|
|
1
|
+
import{parse as e}from"acorn";import t from"rfdc";import n from"postcss";import{parseFragment as r}from"parse5";import i from"unzipper";import a from"url-toolkit";import{createHash as o}from"node:crypto";import{fetch as s}from"undici";import c from"fetch-enhanced";function l(e,t,n,r){let i=0;return i+=e,i+=t<<8,i+=n<<16,i+=r<<24>>>0,i}function u(e,t,n){let r=``;for(let i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function d(e){let t=new Uint8Array(e);if(t[0]===80&&t[1]===75&&t[2]===3&&t[3]===4)throw Error(`Input is not a CRX file, but a ZIP file.`);if(t[0]!==67||t[1]!==114||t[2]!==50||t[3]!==52)throw p(t)?Error(`Input is not a CRX file, but possibly a ZIP file.`):Error(`Invalid header: Does not start with Cr24.`);if(t[4]!==2&&t[4]!==3||t[5]||t[6]||t[7])throw Error(`Unexpected crx format version number.`);let n;if(t[4]===2){let e=l(t[8],t[9],t[10],t[11]),r=l(t[12],t[13],t[14],t[15]);n=16+e+r,btoa(u(t,16,16+e))}else n=12+l(t[8],t[9],t[10],t[11]),f(t,12,n);return e.slice(n)}function f(e,t,n){function r(){let n=e[t]&127;if(e[t++]<128||(n|=(e[t]&127)<<7,e[t++]<128)||(n|=(e[t]&127)<<14,e[t++]<128)||(n|=(e[t]&127)<<21,e[t++]<128))return n;if(n=(n|(e[t]&15)<<28)>>>0,e[t++]&128)throw Error(`proto: not a uint32`);return n}let i=[],a;for(;t<n;){let o=r(),s=r();if(o===80002){let n=r(),i=r();if(n!==10)throw Error(`proto: Unexpected key in signed_header_data: ${n}`);if(i!==16)throw Error(`proto: Unexpected signed_header_data length ${s}`);if(a)throw Error(`proto: Unexpected duplicate signed_header_data`);a=e.subarray(t,t+16),t+=i;continue}if(o!==18){if(o!==26)throw Error(`proto: Unexpected key: ${o}`);t+=s;continue}let c=t+s,l=r(),d=r();if(l===18){if(t+=d,t>=c)continue;l=r(),d=r()}if(l!==10)throw t+=d,Error(`proto: Unexpected key in AsymmetricKeyProof: ${l}`);if(t+d>n)throw Error(`proto: size of public_key field is too large`);i.push(u(e,t,t+d)),t=c}if(!i.length)throw Error(`proto: Did not find any public key`);if(!a)throw Error(`proto: Did not find crx_id`);let s=Buffer.from(a).toString(`hex`);for(let e of i)if(o(`sha256`).update(e,`latin1`).digest(`hex`).slice(0,32)===s)return btoa(e);throw Error(`proto: None of the public keys matched with crx_id`)}function p(e){for(let t=e.length-22,n=Math.max(0,t-65535);t>=n;--t)if(e[t]===80&&e[t+1]===75&&e[t+2]===5&&e[t+3]===6)return!0;return!1}const m=c(s,{undici:!0}),h=t();async function g(e,t){try{return await m(e,t)}catch(t){throw t.message=`${t.message} (${e})`,t}}async function _(e){let t=[],n=[],r=await e.text();for(let n of y(r))t.push(a.buildAbsoluteURL(e.url,n));for(let e of b(r))n.push(e);return[t,n]}function v(e,t,n){if(e.status===200)return;let r=`Failed to fetch ${t}: ${e.status} ${e.statusText}`;if(n)throw Error(r);console.warn(`(fetch-css) Warning: ${r}`)}function y(e){return(e.match(/<link.+?>/g)||[]).map(e=>{let t={};for(let n of r(e).childNodes[0].attrs)t[n.name]=n.value;return t.href&&t.rel===`stylesheet`||t.href&&/\.css$/i.test(t.href.replace(/\?.+/,`undefined`))?t.href:null}).filter(Boolean)}function b(e){return Array.from((e||``).matchAll(/<style.*?>([\s\S]*?)<\/style>/g)||[]).map(e=>e[1]).map(e=>e.trim()).filter(Boolean)}function x(e){try{let t=n.parse(e);if(t&&t.type===`root`&&Array.isArray(t.nodes)&&t.nodes.length>=1&&t.nodes.every(e=>e.type===`rule`))return!0}catch{}return!1}function S(e){let t=Buffer.alloc(e.byteLength),n=new Uint8Array(e);for(let e=0;e<t.length;++e)t[e]=n[e];return t}function C(t){let n=``;return e(t,{ecmaVersion:`latest`,onToken:e=>{if(e.type.label===`string`){let t=e.value.trim().replace(/\n/g,``).replace(/^\);\}/,``);t.length>25&&x(t)&&(n+=`${t}\n`)}}}),n.trim()}async function w({crx:e,contentScriptsOnly:t,strict:n}){let r=`https://clients2.google.com/service/update2/crx`;r+=`?response=redirect`,r+=`&os=linux`,r+=`&arch=x86-64`,r+=`&os_arch=x86-64`,r+=`&acceptformat=crx3`,r+=`&prod=chromiumcrx`,r+=`&prodchannel=unknown`,r+=`&prodversion=9999.0.9999.0`,r+=`&x=id%3D${e}`,r+=`%26uc`;let a=await g(r);v(a,r,n);let o=S(await a.arrayBuffer()),s=Buffer.from(d(o)),c={};for(let e of(await i.Open.buffer(s)||{files:[]}).files)c[e.path]=e;if(!c[`manifest.json`])throw Error(`manifest.json not found in extension ${e}`);let l=[],u=[];if(!t)for(let e of Object.keys(c))e.endsWith(`.css`)&&l.push(e),e.endsWith(`.js`)&&u.push(e);let f=JSON.parse(String(await c[`manifest.json`].buffer()));for(let{css:e,js:t}of f.content_scripts||[])Array.isArray(e)&&e.length&&l.push(...e),Array.isArray(t)&&t.length&&u.push(...t);l=Array.from(new Set(l)),u=Array.from(new Set(u)),l=l.map(e=>e.replace(/^\//,``)),u=u.map(e=>e.replace(/^\//,``));let p=``;for(let e of l)p+=`${String(await c[e].buffer())}\n`;for(let e of u){let t=String(await c[e].buffer());p+=C(t)}return p}async function T(e){e=h(e);let t=[];for(let n of e)if(`url`in n&&Array.isArray(n.url))for(let e of n.url)t.push({...n,url:e});else t.push(n);e=t;let n=await Promise.all(e.map(e=>{if(!e.url)return Promise.resolve(null);let{pathname:t}=new URL(e.url);return t.endsWith(`.css`)||t.endsWith(`.js`)?Promise.resolve(null):g(e.url,e.fetchOpts)}));for(let[t,r]of n.entries()){let n=e[t];if(n.urls=[],n.styleTags=[],r){v(r,n.url,n.strict);let[e,t]=await _(r);n.urls.push(...e),n.styleTags.push(...t)}else n.url&&(n.urls=[n.url])}let r=await Promise.all(e.map(e=>e.url?Promise.all(e.urls.map(async e=>(await g(e)).text())):Promise.resolve(null)));for(let[t,n]of r.entries()){let r=e[t];r.crx?r.css=await w(r):r.url.endsWith(`.js`)?r.css=C(n.join(`
|
|
2
2
|
`)):(r.css=n.join(`
|
|
3
3
|
`),r.styleTags?.length&&(r.css+=`\n${r.styleTags.join(`
|
|
4
|
-
`)}`))}return e}export{
|
|
4
|
+
`)}`))}return e}export{T as default};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fetch-css",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Extract CSS from websites and browser extensions",
|
|
5
5
|
"author": "silverwind",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "silverwind/fetch-css"
|
|
8
|
+
"url": "git+https://github.com/silverwind/fetch-css.git"
|
|
9
9
|
},
|
|
10
10
|
"license": "BSD-2-Clause",
|
|
11
11
|
"type": "module",
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"acorn": "8.18.0",
|
|
32
|
-
"
|
|
33
|
-
"fetch-enhanced": "13.0.0",
|
|
32
|
+
"fetch-enhanced": "13.0.1",
|
|
34
33
|
"parse5": "8.0.1",
|
|
35
34
|
"postcss": "8.5.28",
|
|
36
35
|
"rfdc": "1.4.1",
|
|
@@ -39,7 +38,6 @@
|
|
|
39
38
|
"url-toolkit": "2.2.5"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
|
-
"@types/crypto-js": "4.2.2",
|
|
43
41
|
"@types/node": "26.6.2",
|
|
44
42
|
"@types/unzipper": "0.10.11",
|
|
45
43
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
@@ -48,7 +46,7 @@
|
|
|
48
46
|
"tsdown": "0.23.0",
|
|
49
47
|
"tsdown-config-silverwind": "4.1.1",
|
|
50
48
|
"typescript": "6.0.3",
|
|
51
|
-
"typescript-config-silverwind": "
|
|
49
|
+
"typescript-config-silverwind": "21.0.0",
|
|
52
50
|
"updates": "19.0.0",
|
|
53
51
|
"updates-config-silverwind": "4.0.6",
|
|
54
52
|
"versions": "15.5.0"
|