Skip to content

Commit 35aefed

Browse files
committedSep 7, 2020
Add support to chain :style() to procedural operators
Related issue: - uBlockOrigin/uBlock-issues#382 Additionally, remnant code for pseudo-user stylesheets has been removed. Related commit: - 5c68867
1 parent 3a51ca0 commit 35aefed

11 files changed

+281
-472
lines changed
 

‎platform/chromium/vapi-background.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ window.addEventListener('webextFlavor', function() {
5656

5757
/******************************************************************************/
5858

59+
vAPI.randomToken = function() {
60+
const n = Math.random();
61+
return String.fromCharCode(n * 26 + 97) +
62+
Math.floor(
63+
(0.25 + n * 0.75) * Number.MAX_SAFE_INTEGER
64+
).toString(36).slice(-8);
65+
};
66+
67+
/******************************************************************************/
68+
5969
vAPI.app = {
6070
name: manifest.name.replace(/ dev\w+ build/, ''),
6171
version: (( ) => {
@@ -339,7 +349,10 @@ vAPI.Tabs = class {
339349
return tabs.length !== 0 ? tabs[0] : null;
340350
}
341351

342-
async insertCSS() {
352+
async insertCSS(tabId, details) {
353+
if ( vAPI.supportsUserStylesheets ) {
354+
details.cssOrigin = 'user';
355+
}
343356
try {
344357
await webext.tabs.insertCSS(...arguments);
345358
}
@@ -357,7 +370,10 @@ vAPI.Tabs = class {
357370
return Array.isArray(tabs) ? tabs : [];
358371
}
359372

360-
async removeCSS() {
373+
async removeCSS(tabId, details) {
374+
if ( vAPI.supportsUserStylesheets ) {
375+
details.cssOrigin = 'user';
376+
}
361377
try {
362378
await webext.tabs.removeCSS(...arguments);
363379
}
@@ -1003,9 +1019,6 @@ vAPI.messaging = {
10031019
frameId: sender.frameId,
10041020
matchAboutBlank: true
10051021
};
1006-
if ( vAPI.supportsUserStylesheets ) {
1007-
details.cssOrigin = 'user';
1008-
}
10091022
if ( msg.add ) {
10101023
details.runAt = 'document_start';
10111024
}

‎platform/chromium/vapi-client.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ if (
3939
/******************************************************************************/
4040

4141
vAPI.randomToken = function() {
42-
const now = Date.now();
43-
return String.fromCharCode(now % 26 + 97) +
44-
Math.floor((1 + Math.random()) * now).toString(36);
42+
const n = Math.random();
43+
return String.fromCharCode(n * 26 + 97) +
44+
Math.floor(
45+
(0.25 + n * 0.75) * Number.MAX_SAFE_INTEGER
46+
).toString(36).slice(-8);
4547
};
4648

4749
vAPI.sessionId = vAPI.randomToken();

‎src/js/background.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ const µBlock = (( ) => { // jshint ignore:line
138138

139139
// Read-only
140140
systemSettings: {
141-
compiledMagic: 28, // Increase when compiled format changes
142-
selfieMagic: 28, // Increase when selfie format changes
141+
compiledMagic: 29, // Increase when compiled format changes
142+
selfieMagic: 29, // Increase when selfie format changes
143143
},
144144

145145
// https://github.com/uBlockOrigin/uBlock-issues/issues/759#issuecomment-546654501

0 commit comments

Comments
 (0)
Please sign in to comment.