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

Side by Side Diff: lib/css.js

Issue 29410607: Issue 5090 - Use user stylesheets for element hiding if possible (Closed)
Patch Set: Add comment explaining when we inject styles Created April 18, 2017, 9:20 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 /** @module css */
19
20 "use strict";
21
22 /**
23 * Hides elements on the page using the browser.tabs.insertCSS API.
24 *
25 * @param {string} tabId The ID of the tab in which to hide elements
26 * @param {string} frameId The ID of the frame in which to hide elements
27 * @param {string[]} selectors The list of selectors for the elements to hide
28 * @param {Function} callback The function to be called upon completion
29 * @static
30 */
31 exports.hideElements = (tabId, frameId, selectors, callback) =>
32 {
33 let code = selectors.length > 0 ?
34 selectors.join(", ") + "{display: none !important;}" :
35 "";
36
37 try
38 {
39 chrome.tabs.insertCSS(tabId,
40 {
41 code,
42 cssOrigin: "user",
43 frameId,
44 matchAboutBlank: true
45 },
46 () =>
47 {
48 callback(chrome.runtime.lastError);
49 }
50 );
51 }
52 catch (error)
53 {
54 callback(error);
55 }
56 };
OLDNEW
« background.js ('K') | « include.preload.js ('k') | metadata.chrome » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld