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