From 5684be9b369b5fcf6409d0cbef793a7e84481cf5 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 19 Jun 2011 10:56:16 -0400 Subject: [PATCH] Add support for regexp site-filters to :style. --- common/locale/en-US/styling.xml | 6 +++--- common/modules/styles.jsm | 17 ++++++++++------- pentadactyl/NEWS | 1 + 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/common/locale/en-US/styling.xml b/common/locale/en-US/styling.xml index ff3c7017..331d1496 100644 --- a/common/locale/en-US/styling.xml +++ b/common/locale/en-US/styling.xml @@ -152,9 +152,9 @@

Add CSS styles to the browser or to web pages. filter is a comma-separated list of site-filters for which the style will - apply. Regular expression filters may not be used and the ! - character may not be used to invert the sense of the match. - css is a full CSS rule set (e.g., body { color: blue; }). + apply. The ! character may not be used to invert the sense + of the match. css is a full CSS rule set (e.g., body { + color: blue; }).

The following options are available:

diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 19dc8e41..2586ac83 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -68,17 +68,20 @@ update(Sheet.prototype, { get fullCSS() { let filter = this.sites; let css = this.css; + + let preamble = "/* " + this.uri + (this.agent ? " (agent)" : "") + " */\n\n" + namespace + "\n"; if (filter[0] == "*") - return namespace + css; + return preamble + css; let selectors = filter.map(function (part) - (/[*]$/.test(part) ? "url-prefix" : - /[\/:]/.test(part) ? "url" - : "domain") - + '("' + part.replace(/"/g, "%22").replace(/\*$/, "") + '")') + !/^(?:[a-z-]+:|[a-z-.]+$)/.test(filter) ? "regexp(" + part.quote() + ")" : + (/[*]$/.test(part) ? "url-prefix" : + /[\/:]/.test(part) ? "url" + : "domain") + + '("' + part.replace(/"/g, "%22").replace(/\*$/, "") + '")') .join(",\n "); - return "/* " + this.uri + (this.agent ? " (agent)" : "") + " */\n\n" - + namespace + "\n@-moz-document " + selectors + " {\n\n" + css + "\n\n}\n"; + + return preamble + "@-moz-document " + selectors + " {\n\n" + css + "\n\n}\n"; } }); diff --git a/pentadactyl/NEWS b/pentadactyl/NEWS index 3efffdd3..ce6f627a 100644 --- a/pentadactyl/NEWS +++ b/pentadactyl/NEWS @@ -90,6 +90,7 @@ and linking to source code locations). [b4] - :downloads now opens a download list in the multi-line output buffer. Added -sort flag. [b6][b7] + - :style now supports regexp site-filters on Firefox 6+. [b7] - :qa closes only the current window, per Vim. [b7] - Added :exit command. [b7] - Added :dlclear command. [b7]