mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-03 17:49:39 +02:00
[mv3] Stick to int32 instead of 8-char hex strings for file hashes
This commit is contained in:
parent
90f666fce8
commit
f374c05753
3
.github/workflows/mv3.yml
vendored
3
.github/workflows/mv3.yml
vendored
@ -25,6 +25,7 @@ jobs:
|
|||||||
tools/make-mv3.sh full
|
tools/make-mv3.sh full
|
||||||
echo "PACKAGE=$(basename $(ls dist/build/uBOLite_*.mv3.zip))" >> $GITHUB_ENV
|
echo "PACKAGE=$(basename $(ls dist/build/uBOLite_*.mv3.zip))" >> $GITHUB_ENV
|
||||||
echo "TAGNAME=$(basename $(ls dist/build/uBOLite_*.mv3.zip) .mv3.zip)" >> $GITHUB_ENV
|
echo "TAGNAME=$(basename $(ls dist/build/uBOLite_*.mv3.zip) .mv3.zip)" >> $GITHUB_ENV
|
||||||
|
echo "RELEASENAME=${PACKAGE/_/ }" >> $GITHUB_ENV
|
||||||
cp dist/build/uBOLite.mv3/log.txt dist/chromium-mv3/
|
cp dist/build/uBOLite.mv3/log.txt dist/chromium-mv3/
|
||||||
- name: Commit uBOLite MV3 build log file
|
- name: Commit uBOLite MV3 build log file
|
||||||
# https://github.com/marketplace/actions/github-action-for-committing-changes-to-a-repository
|
# https://github.com/marketplace/actions/github-action-for-committing-changes-to-a-repository
|
||||||
@ -39,7 +40,7 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ github.token }}
|
GITHUB_TOKEN: ${{ github.token }}
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ env.TAGNAME }}
|
tag_name: ${{ env.TAGNAME }}
|
||||||
release_name: ${{ env.TAGNAME }}
|
release_name: ${{ env.RELEASENAME }}
|
||||||
prerelease: true
|
prerelease: true
|
||||||
- name: Upload uBOLite MV3 package
|
- name: Upload uBOLite MV3 package
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
|
@ -31,11 +31,6 @@ import { parsedURLromOrigin } from './utils.js';
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const CSS_TYPE = '0'; // jshint ignore:line
|
|
||||||
const JS_TYPE = '1';
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
let scriptingDetailsPromise;
|
let scriptingDetailsPromise;
|
||||||
|
|
||||||
function getScriptingDetails() {
|
function getScriptingDetails() {
|
||||||
@ -110,13 +105,14 @@ const toRegisterable = (fname, entry) => {
|
|||||||
}
|
}
|
||||||
directive.js = [ `/rulesets/js/${fname.slice(0,1)}/${fname.slice(1)}.js` ];
|
directive.js = [ `/rulesets/js/${fname.slice(0,1)}/${fname.slice(1)}.js` ];
|
||||||
directive.runAt = 'document_start';
|
directive.runAt = 'document_start';
|
||||||
if ( fname.at(-1) === JS_TYPE ) {
|
if ( (parseInt(fname,16) & MAIN_WORLD_BIT) !== 0 ) {
|
||||||
directive.world = 'MAIN';
|
directive.world = 'MAIN';
|
||||||
}
|
}
|
||||||
|
|
||||||
return directive;
|
return directive;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MAIN_WORLD_BIT = 0b1;
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const shouldUpdate = (registered, candidate) => {
|
const shouldUpdate = (registered, candidate) => {
|
||||||
@ -192,9 +188,10 @@ async function registerInjectable() {
|
|||||||
const toRegister = new Map();
|
const toRegister = new Map();
|
||||||
|
|
||||||
const checkRealm = (details, prop, hn) => {
|
const checkRealm = (details, prop, hn) => {
|
||||||
const fnames = details[prop]?.get(hn);
|
const fids = details[prop]?.get(hn);
|
||||||
if ( fnames === undefined ) { return; }
|
if ( fids === undefined ) { return; }
|
||||||
for ( const fname of fnames ) {
|
for ( const fid of fids ) {
|
||||||
|
const fname = fid.toString(16).padStart(8,'0');
|
||||||
const existing = toRegister.get(fname);
|
const existing = toRegister.get(fname);
|
||||||
if ( existing ) {
|
if ( existing ) {
|
||||||
existing[prop].push(hn);
|
existing[prop].push(hn);
|
||||||
|
@ -67,8 +67,10 @@ const jsonSetMapReplacer = (k, v) => {
|
|||||||
return v;
|
return v;
|
||||||
};
|
};
|
||||||
|
|
||||||
const uid = (s, l = 8) =>
|
const uidint32 = (s) => {
|
||||||
createHash('sha256').update(s).digest('hex').slice(0,l);
|
const h = createHash('sha256').update(s).digest('hex').slice(0,8);
|
||||||
|
return parseInt(h,16) & 0x7FFFFFFF;
|
||||||
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@ -342,7 +344,7 @@ function loadAllSourceScriptlets() {
|
|||||||
|
|
||||||
const globalPatchedScriptletsSet = new Set();
|
const globalPatchedScriptletsSet = new Set();
|
||||||
|
|
||||||
function addScriptingAPIResources(id, entry, prop, fname) {
|
function addScriptingAPIResources(id, entry, prop, fid) {
|
||||||
if ( entry[prop] === undefined ) { return; }
|
if ( entry[prop] === undefined ) { return; }
|
||||||
for ( const hn of entry[prop] ) {
|
for ( const hn of entry[prop] ) {
|
||||||
let details = scriptingDetails.get(id);
|
let details = scriptingDetails.get(id);
|
||||||
@ -353,15 +355,20 @@ function addScriptingAPIResources(id, entry, prop, fname) {
|
|||||||
};
|
};
|
||||||
scriptingDetails.set(id, details);
|
scriptingDetails.set(id, details);
|
||||||
}
|
}
|
||||||
let fnames = details[prop].get(hn);
|
let fids = details[prop].get(hn);
|
||||||
if ( fnames === undefined ) {
|
if ( fids === undefined ) {
|
||||||
fnames = new Set();
|
fids = new Set();
|
||||||
details[prop].set(hn, fnames);
|
details[prop].set(hn, fids);
|
||||||
}
|
}
|
||||||
fnames.add(fname);
|
fids.add(fid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const toCSSFileId = s => uidint32(s) & ~0b1;
|
||||||
|
const toJSFileId = s => uidint32(s) | 0b1;
|
||||||
|
const fileNameFromId = id => id.toString(16).padStart(8,'0');
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
async function processCosmeticFilters(assetDetails, mapin) {
|
async function processCosmeticFilters(assetDetails, mapin) {
|
||||||
@ -395,7 +402,7 @@ async function processCosmeticFilters(assetDetails, mapin) {
|
|||||||
const cssContentMap = new Map();
|
const cssContentMap = new Map();
|
||||||
for ( const entry of optimized ) {
|
for ( const entry of optimized ) {
|
||||||
// ends-with 0 = css resource
|
// ends-with 0 = css resource
|
||||||
const id = parseInt(uid(entry.selector), 16);
|
const id = uidint32(entry.selector);
|
||||||
let details = cssContentMap.get(id);
|
let details = cssContentMap.get(id);
|
||||||
if ( details === undefined ) {
|
if ( details === undefined ) {
|
||||||
details = { a: entry.selector };
|
details = { a: entry.selector };
|
||||||
@ -477,9 +484,10 @@ async function processCosmeticFilters(assetDetails, mapin) {
|
|||||||
`${JSON.stringify(hostnamesMap, jsonReplacer)}`
|
`${JSON.stringify(hostnamesMap, jsonReplacer)}`
|
||||||
);
|
);
|
||||||
// ends-with 0 = css resource
|
// ends-with 0 = css resource
|
||||||
const fname = uid(patchedScriptlet) + '0';
|
const fid = toCSSFileId(patchedScriptlet);
|
||||||
if ( globalPatchedScriptletsSet.has(fname) === false ) {
|
if ( globalPatchedScriptletsSet.has(fid) === false ) {
|
||||||
globalPatchedScriptletsSet.add(fname);
|
globalPatchedScriptletsSet.add(fid);
|
||||||
|
const fname = fileNameFromId(fid);
|
||||||
writeFile(`${scriptletDir}/${fname.slice(0,1)}/${fname.slice(1)}.js`, patchedScriptlet, {});
|
writeFile(`${scriptletDir}/${fname.slice(0,1)}/${fname.slice(1)}.js`, patchedScriptlet, {});
|
||||||
generatedFiles.push(fname);
|
generatedFiles.push(fname);
|
||||||
}
|
}
|
||||||
@ -488,13 +496,13 @@ async function processCosmeticFilters(assetDetails, mapin) {
|
|||||||
assetDetails.id,
|
assetDetails.id,
|
||||||
{ matches: entry[1].y },
|
{ matches: entry[1].y },
|
||||||
'matches',
|
'matches',
|
||||||
fname
|
fid
|
||||||
);
|
);
|
||||||
addScriptingAPIResources(
|
addScriptingAPIResources(
|
||||||
assetDetails.id,
|
assetDetails.id,
|
||||||
{ excludeMatches: entry[1].n },
|
{ excludeMatches: entry[1].n },
|
||||||
'excludeMatches',
|
'excludeMatches',
|
||||||
fname
|
fid
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -622,12 +630,12 @@ async function processScriptletFilters(assetDetails, mapin) {
|
|||||||
|
|
||||||
for ( const [ token, argsDetails ] of scriptletDetails ) {
|
for ( const [ token, argsDetails ] of scriptletDetails ) {
|
||||||
const argsMap = Array.from(argsDetails).map(entry => [
|
const argsMap = Array.from(argsDetails).map(entry => [
|
||||||
parseInt(uid(entry[0]),16),
|
uidint32(entry[0]),
|
||||||
{ a: entry[1].a, n: entry[1].n }
|
{ a: entry[1].a, n: entry[1].n }
|
||||||
]);
|
]);
|
||||||
const hostnamesMap = new Map();
|
const hostnamesMap = new Map();
|
||||||
for ( const [ argsHash, details ] of argsDetails ) {
|
for ( const [ argsHash, details ] of argsDetails ) {
|
||||||
toHostnamesMap(details.y, parseInt(uid(argsHash),16), hostnamesMap);
|
toHostnamesMap(details.y, uidint32(argsHash), hostnamesMap);
|
||||||
}
|
}
|
||||||
const patchedScriptlet = originalScriptletMap.get(token)
|
const patchedScriptlet = originalScriptletMap.get(token)
|
||||||
.replace(
|
.replace(
|
||||||
@ -638,9 +646,10 @@ async function processScriptletFilters(assetDetails, mapin) {
|
|||||||
`${JSON.stringify(hostnamesMap, jsonReplacer)}`
|
`${JSON.stringify(hostnamesMap, jsonReplacer)}`
|
||||||
);
|
);
|
||||||
// ends-with 1 = scriptlet resource
|
// ends-with 1 = scriptlet resource
|
||||||
const fname = uid(patchedScriptlet) + '1';
|
const fid = toJSFileId(patchedScriptlet);
|
||||||
if ( globalPatchedScriptletsSet.has(fname) === false ) {
|
if ( globalPatchedScriptletsSet.has(fid) === false ) {
|
||||||
globalPatchedScriptletsSet.add(fname);
|
globalPatchedScriptletsSet.add(fid);
|
||||||
|
const fname = fileNameFromId(fid);
|
||||||
writeFile(`${scriptletDir}/${fname.slice(0,1)}/${fname.slice(1)}.js`, patchedScriptlet, {});
|
writeFile(`${scriptletDir}/${fname.slice(0,1)}/${fname.slice(1)}.js`, patchedScriptlet, {});
|
||||||
generatedFiles.push(fname);
|
generatedFiles.push(fname);
|
||||||
}
|
}
|
||||||
@ -649,13 +658,13 @@ async function processScriptletFilters(assetDetails, mapin) {
|
|||||||
assetDetails.id,
|
assetDetails.id,
|
||||||
{ matches: details.y },
|
{ matches: details.y },
|
||||||
'matches',
|
'matches',
|
||||||
fname
|
fid
|
||||||
);
|
);
|
||||||
addScriptingAPIResources(
|
addScriptingAPIResources(
|
||||||
assetDetails.id,
|
assetDetails.id,
|
||||||
{ excludeMatches: details.n },
|
{ excludeMatches: details.n },
|
||||||
'excludeMatches',
|
'excludeMatches',
|
||||||
fname
|
fid
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user