Skip to content

Commit

Permalink
Add support to chain :style() to procedural operators
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uBlock-issues#382

Additionally, remnant code for pseudo-user stylesheets
has been removed. Related commit:
- 5c68867
  • Loading branch information
gorhill committed Sep 7, 2020
1 parent 3a51ca0 commit 35aefed
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 472 deletions.
23 changes: 18 additions & 5 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ window.addEventListener('webextFlavor', function() {

/******************************************************************************/

vAPI.randomToken = function() {
const n = Math.random();
return String.fromCharCode(n * 26 + 97) +
Math.floor(
(0.25 + n * 0.75) * Number.MAX_SAFE_INTEGER
).toString(36).slice(-8);
};

/******************************************************************************/

vAPI.app = {
name: manifest.name.replace(/ dev\w+ build/, ''),
version: (( ) => {
Expand Down Expand Up @@ -339,7 +349,10 @@ vAPI.Tabs = class {
return tabs.length !== 0 ? tabs[0] : null;
}

async insertCSS() {
async insertCSS(tabId, details) {
if ( vAPI.supportsUserStylesheets ) {
details.cssOrigin = 'user';
}
try {
await webext.tabs.insertCSS(...arguments);
}
Expand All @@ -357,7 +370,10 @@ vAPI.Tabs = class {
return Array.isArray(tabs) ? tabs : [];
}

async removeCSS() {
async removeCSS(tabId, details) {
if ( vAPI.supportsUserStylesheets ) {
details.cssOrigin = 'user';
}
try {
await webext.tabs.removeCSS(...arguments);
}
Expand Down Expand Up @@ -1003,9 +1019,6 @@ vAPI.messaging = {
frameId: sender.frameId,
matchAboutBlank: true
};
if ( vAPI.supportsUserStylesheets ) {
details.cssOrigin = 'user';
}
if ( msg.add ) {
details.runAt = 'document_start';
}
Expand Down
8 changes: 5 additions & 3 deletions platform/chromium/vapi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ if (
/******************************************************************************/

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

vAPI.sessionId = vAPI.randomToken();
Expand Down
4 changes: 2 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ const µBlock = (( ) => { // jshint ignore:line

// Read-only
systemSettings: {
compiledMagic: 28, // Increase when compiled format changes
selfieMagic: 28, // Increase when selfie format changes
compiledMagic: 29, // Increase when compiled format changes
selfieMagic: 29, // Increase when selfie format changes
},

// https://github.com/uBlockOrigin/uBlock-issues/issues/759#issuecomment-546654501
Expand Down
Loading

0 comments on commit 35aefed

Please sign in to comment.