mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
[mv3][safari] Workaround for user styles issue with bfcache
Related issue: https://github.com/uBlockOrigin/uBOL-home/issues/518
This commit is contained in:
parent
f9bb6d7f7e
commit
22d2ecc472
9 changed files with 150 additions and 33 deletions
|
|
@ -194,7 +194,7 @@ function registerGeneric(context, genericDetails) {
|
|||
|
||||
if ( js.length === 0 ) { return; }
|
||||
|
||||
js.unshift('/js/scripting/isolated-api.js');
|
||||
js.unshift('/js/scripting/css-api.js', '/js/scripting/isolated-api.js');
|
||||
js.push('/js/scripting/css-generic.js');
|
||||
|
||||
const { none, basic, optimal, complete } = filteringModeDetails;
|
||||
|
|
@ -306,7 +306,7 @@ function registerProcedural(context) {
|
|||
|
||||
normalizeMatches(matches);
|
||||
|
||||
js.unshift('/js/scripting/isolated-api.js');
|
||||
js.unshift('/js/scripting/css-api.js', '/js/scripting/isolated-api.js');
|
||||
js.push('/js/scripting/css-procedural.js');
|
||||
|
||||
const excludeMatches = [];
|
||||
|
|
@ -373,7 +373,7 @@ function registerSpecific(context) {
|
|||
|
||||
normalizeMatches(matches);
|
||||
|
||||
js.unshift('/js/scripting/isolated-api.js');
|
||||
js.unshift('/js/scripting/css-api.js', '/js/scripting/isolated-api.js');
|
||||
js.push('/js/scripting/css-specific.js');
|
||||
|
||||
const excludeMatches = [];
|
||||
|
|
|
|||
33
platform/mv3/extension/js/scripting/css-api.js
Normal file
33
platform/mv3/extension/js/scripting/css-api.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*******************************************************************************
|
||||
|
||||
uBlock Origin Lite - a comprehensive, MV3-compliant content blocker
|
||||
Copyright (C) 2025-present Raymond Hill
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
|
||||
Home: https://github.com/gorhill/uBlock
|
||||
*/
|
||||
|
||||
(api => {
|
||||
if ( typeof api === 'object' ) { return; }
|
||||
self.cssAPI = {
|
||||
insert(css) {
|
||||
chrome.runtime.sendMessage({
|
||||
what: 'insertCSS',
|
||||
css,
|
||||
}).catch(( ) => {
|
||||
});
|
||||
},
|
||||
};
|
||||
})(self.cssAPI);
|
||||
|
|
@ -188,7 +188,7 @@ const uBOL_processNodes = ( ) => {
|
|||
if ( styleSheetTimer !== undefined ) { return; }
|
||||
styleSheetTimer = self.requestAnimationFrame(( ) => {
|
||||
styleSheetTimer = undefined;
|
||||
uBOL_injectCSS(`${styleSheetSelectors.join(',')}{display:none!important;}`);
|
||||
self.cssAPI.insert(`${styleSheetSelectors.join(',')}{display:none!important;}`);
|
||||
styleSheetSelectors.length = 0;
|
||||
});
|
||||
};
|
||||
|
|
@ -214,16 +214,6 @@ const uBOL_processChanges = mutations => {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
const uBOL_injectCSS = css => {
|
||||
chrome.runtime.sendMessage({
|
||||
what: 'insertCSS',
|
||||
css,
|
||||
}).catch(( ) => {
|
||||
});
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
const stopAll = ( ) => {
|
||||
if ( domChangeTimer !== undefined ) {
|
||||
self.clearTimeout(domChangeTimer);
|
||||
|
|
|
|||
|
|
@ -29,14 +29,6 @@ if ( self.ProceduralFiltererAPI !== undefined ) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
const uBOL_injectCSS = css => {
|
||||
chrome.runtime.sendMessage({
|
||||
what: 'insertCSS',
|
||||
css,
|
||||
}).catch(( ) => {
|
||||
});
|
||||
};
|
||||
|
||||
const nonVisualElements = {
|
||||
head: true,
|
||||
link: true,
|
||||
|
|
@ -688,7 +680,7 @@ class ProceduralFilterer {
|
|||
if ( styleToken !== undefined ) { return styleToken; }
|
||||
styleToken = randomToken();
|
||||
this.styleTokenMap.set(style, styleToken);
|
||||
uBOL_injectCSS(`[${styleToken}]\n{${style}}\n`);
|
||||
self.cssAPI.insert(`[${styleToken}]\n{${style}}\n`);
|
||||
return styleToken;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -103,11 +103,7 @@ if ( declaratives.length !== 0 ) {
|
|||
sheetText.push(ruleText);
|
||||
}
|
||||
if ( sheetText.length !== 0 ) {
|
||||
chrome.runtime.sendMessage({
|
||||
what: 'insertCSS',
|
||||
css: sheetText.join('\n'),
|
||||
}).catch(( ) => {
|
||||
});
|
||||
self.cssAPI.insert(sheetText.join('\n'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,11 +65,7 @@ const exceptedSelectors = exceptions.length !== 0
|
|||
: selectors;
|
||||
if ( exceptedSelectors.length === 0 ) { return; }
|
||||
|
||||
chrome.runtime.sendMessage({
|
||||
what: 'insertCSS',
|
||||
css: `${exceptedSelectors.join(',')}{display:none!important;}`,
|
||||
}).catch(( ) => {
|
||||
});
|
||||
self.cssAPI.insert(`${exceptedSelectors.join(',')}{display:none!important;}`);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
|
|||
46
platform/mv3/safari/css-api.js
Normal file
46
platform/mv3/safari/css-api.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*******************************************************************************
|
||||
|
||||
uBlock Origin Lite - a comprehensive, MV3-compliant content blocker
|
||||
Copyright (C) 2025-present Raymond Hill
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
|
||||
Home: https://github.com/gorhill/uBlock
|
||||
*/
|
||||
|
||||
(api => {
|
||||
if ( typeof api === 'object' ) { return; }
|
||||
|
||||
const inserted = new Set();
|
||||
|
||||
self.cssAPI = {
|
||||
insert(css) {
|
||||
chrome.runtime.sendMessage({
|
||||
what: 'insertCSS',
|
||||
css,
|
||||
}).catch(( ) => {
|
||||
});
|
||||
inserted.add(css);
|
||||
},
|
||||
};
|
||||
|
||||
self.addEventListener('pageshow', ( ) => {
|
||||
chrome.runtime.sendMessage({
|
||||
what: 'insertCSS',
|
||||
css: Array.from(inserted).join('\n'),
|
||||
}).catch(( ) => {
|
||||
});
|
||||
});
|
||||
|
||||
})(self.cssAPI);
|
||||
62
platform/mv3/safari/css-user.js
Normal file
62
platform/mv3/safari/css-user.js
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*******************************************************************************
|
||||
|
||||
uBlock Origin Lite - a comprehensive, MV3-compliant content blocker
|
||||
Copyright (C) 2019-present Raymond Hill
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
|
||||
Home: https://github.com/gorhill/uBlock
|
||||
*/
|
||||
|
||||
(async function uBOL_cssUser() {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
const docURL = new URL(document.baseURI);
|
||||
const details = await chrome.runtime.sendMessage({
|
||||
what: 'injectCustomFilters',
|
||||
hostname: docURL.hostname,
|
||||
}).catch(( ) => {
|
||||
});
|
||||
|
||||
if ( details?.proceduralSelectors?.length ) {
|
||||
if ( self.ProceduralFiltererAPI ) {
|
||||
self.customProceduralFiltererAPI = new self.ProceduralFiltererAPI();
|
||||
self.customProceduralFiltererAPI.addSelectors(
|
||||
details.proceduralSelectors.map(a => JSON.parse(a))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const inserted = new Set();
|
||||
|
||||
if ( Array.isArray(details?.plainSelectors) ) {
|
||||
inserted.add(`${details.plainSelectors.join(',\n')}{display:none!important;}`);
|
||||
}
|
||||
|
||||
self.addEventListener('pageshow', ( ) => {
|
||||
chrome.runtime.sendMessage({
|
||||
what: 'insertCSS',
|
||||
css: Array.from(inserted).join('\n'),
|
||||
}).catch(( ) => {
|
||||
});
|
||||
});
|
||||
|
||||
self.customFilters = details;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
})();
|
||||
|
||||
void 0;
|
||||
|
|
@ -101,6 +101,8 @@ cp platform/mv3/extension/*.json "$UBOL_DIR"/
|
|||
cp platform/mv3/extension/css/* "$UBOL_DIR"/css/
|
||||
cp -R platform/mv3/extension/js/* "$UBOL_DIR"/js/
|
||||
cp platform/mv3/"$PLATFORM"/ext-compat.js "$UBOL_DIR"/js/ 2>/dev/null || :
|
||||
cp platform/mv3/"$PLATFORM"/css-api.js "$UBOL_DIR"/js/scripting/ 2>/dev/null || :
|
||||
cp platform/mv3/"$PLATFORM"/css-user.js "$UBOL_DIR"/js/scripting/ 2>/dev/null || :
|
||||
cp platform/mv3/extension/img/* "$UBOL_DIR"/img/
|
||||
cp platform/mv3/"$PLATFORM"/img/* "$UBOL_DIR"/img/ 2>/dev/null || :
|
||||
cp -R platform/mv3/extension/_locales "$UBOL_DIR"/
|
||||
|
|
|
|||
Loading…
Reference in a new issue