2014-09-11 16:52:34 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
µBlock - a Chromium browser extension to block requests.
|
|
|
|
Copyright (C) 2014 Raymond Hill
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 this program. If not, see {http://www.gnu.org/licenses/}.
|
|
|
|
|
|
|
|
Home: https://github.com/gorhill/uBlock
|
|
|
|
*/
|
|
|
|
|
2014-10-19 13:11:27 +02:00
|
|
|
/* global µBlock, vAPI */
|
|
|
|
'use strict';
|
2014-09-11 16:52:34 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
µBlock.XAL = (function(){
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var exports = {};
|
2014-10-07 16:46:10 +02:00
|
|
|
var noopFunc = function(){};
|
2014-09-11 16:52:34 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
2014-09-28 20:38:17 +02:00
|
|
|
exports.injectScript = function(id, details) {
|
|
|
|
chrome.tabs.executeScript(id, details);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-10-11 22:44:56 +02:00
|
|
|
exports.keyvalSetOne = function(key, val, callback) {
|
2014-10-06 20:02:44 +02:00
|
|
|
var bin = {};
|
|
|
|
bin[key] = val;
|
2014-10-17 21:44:19 +02:00
|
|
|
vAPI.storage.set(bin, callback || noopFunc);
|
2014-10-06 20:02:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-10-11 22:44:56 +02:00
|
|
|
exports.keyvalSetMany = function(dict, callback) {
|
2014-10-17 21:44:19 +02:00
|
|
|
vAPI.storage.set(dict, callback || noopFunc);
|
2014-10-07 14:59:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
exports.keyvalRemoveAll = function(callback) {
|
2014-10-17 21:44:19 +02:00
|
|
|
vAPI.storage.clear(callback || noopFunc);
|
2014-10-07 14:59:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
exports.restart = function() {
|
2014-10-17 21:44:19 +02:00
|
|
|
if (vAPI.chrome) {
|
|
|
|
chrome.runtime.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO? for cross-browser solution:
|
|
|
|
// window.location.reload();
|
|
|
|
// plus close all extension tabs
|
2014-10-07 14:59:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-10-10 19:26:43 +02:00
|
|
|
exports.destroyTab = function(tabId) {
|
2014-10-17 21:44:19 +02:00
|
|
|
vAPI.tabs.remove(tabId, function() {
|
2014-10-10 19:26:43 +02:00
|
|
|
// required by chrome API, or else warnings at console (also, mind jshint)
|
|
|
|
if ( chrome.runtime.lastError ) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-09-11 16:52:34 +02:00
|
|
|
return exports;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|