Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/css.js

Issue 29410607: Issue 5090 - Use user stylesheets for element hiding if possible (Closed)
Patch Set: Check platform and platform version for user stylesheet support Created April 20, 2017, 12:42 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include.preload.js ('k') | metadata.chrome » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/css.js
diff --git a/lib/css.js b/lib/css.js
new file mode 100644
index 0000000000000000000000000000000000000000..db49b244107e892686ff8ecd58e16c566317c73b
--- /dev/null
+++ b/lib/css.js
@@ -0,0 +1,67 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2017 eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus 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 Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** @module css */
+
+"use strict";
+
+const info = require("info");
+
+/**
+ * Whether user stylesheets are supported on this platform.
+ *
+ * @type {boolean}
+ * @static
+ */
+exports.userStylesheetsSupported = info.platform == "gecko" &&
+ info.platformVersion.split(".")[0] >= 53;
+
+/**
+ * Hides elements on the page using the browser.tabs.insertCSS API.
+ *
+ * @param {string} tabId The ID of the tab in which to hide elements
+ * @param {string} frameId The ID of the frame in which to hide elements
+ * @param {string[]} selectors The list of selectors for the elements to hide
+ * @param {Function} callback The function to be called upon completion
+ * @static
+ */
+exports.hideElements = (tabId, frameId, selectors, callback) =>
+{
+ let code = selectors.length > 0 ?
+ selectors.join(", ") + "{display: none !important;}" :
+ "";
+
+ try
kzar 2017/04/21 11:20:22 I guess we don't really need this try catch here a
Manish Jethani 2017/04/21 13:39:32 Removed.
+ {
+ chrome.tabs.insertCSS(tabId,
+ {
kzar 2017/04/21 11:20:22 Nit: We'd normally put the semicolon on the above
kzar 2017/04/21 11:21:57 Arg, of course I meant `{` not `;`! Like this chr
Manish Jethani 2017/04/21 13:39:32 It did pass linting. I've seen this style in many
kzar 2017/04/21 14:36:51 I'll defer to Sebastian there.
+ code,
+ cssOrigin: "user",
+ frameId,
+ matchAboutBlank: true
+ },
+ () =>
+ {
+ callback(chrome.runtime.lastError);
+ }
+ );
+ }
+ catch (error)
+ {
+ callback(error);
+ }
+};
« no previous file with comments | « include.preload.js ('k') | metadata.chrome » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld