我可以从插件/扩展中禁用 Firefox/Chrome 组件吗?
Can I disable Firefox / Chrome components from an addon / extension?
我已经为 Firefox 制作了一些插件和 Chrome 的扩展,但现在我有了一个疯狂的想法,我想知道我是否可以禁用 Firefox / Chrome来自插件/扩展的组件。
当我说禁用组件时,我的意思是(主要是 FF 示例):
- 火狐你好
- Pocket(Firefox 现在默认集成了 Pocket)
- 历史
- 收藏夹
- 其他已安装的扩展程序
- "Print" 和 "Developer Tools"
等资源
- 等等
我搜索了整个 Firefox Addon Developer Hub,但没有找到我是否可以做类似的事情。如果您知道答案,我该怎么做或为什么不能?
您无需说明为什么(或不可能)可行以及我如何实现,但在这种情况下请提供有用且有趣的链接。
从 Firefox 中禁用其他东西非常容易。
例如,这会通过 id 禁用插件:
//this checks to see if AdBlock Plus is enabled
AddonManager.getAddonsByIDs(["{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}"], function ([aAddon1]) {
console.log(aAddon1);
var isAddonEnabled = aAddon1.isActive;
alert('AdBlock plus enabled = ' + isAddonEnabled)
//for other properties see here: https://developer.mozilla.org/en-US/Add-ons/Add-on_Manager/Addon#Required_properties
});
组件的处理方式略有不同,您必须使用 nsICategoryManager,这会禁用默认的 pdf reader:
var CONTENT_TYPE = 'application/pdf';
// Update the category manager in case the plugins are already loaded.
let categoryManager = Cc['@mozilla.org/categorymanager;1'];
categoryManager.getService(Ci.nsICategoryManager).deleteCategoryEntry('Gecko-Content-Viewers', CONTENT_TYPE, false);
// Update pref manager to prevent plugins from loading in future
var stringTypes = '';
var types = [];
var PREF_DISABLED_PLUGIN_TYPES = 'plugin.disable_full_page_plugin_for_types';
if (Services.prefs.prefHasUserValue(PREF_DISABLED_PLUGIN_TYPES)) {
stringTypes = Services.prefs.getCharPref(PREF_DISABLED_PLUGIN_TYPES);
}
if (stringTypes !== '') {
types = stringTypes.split(',');
}
if (types.indexOf(CONTENT_TYPE) === -1) {
types.push(CONTENT_TYPE);
}
Services.prefs.setCharPref(PREF_DISABLED_PLUGIN_TYPES, types.join(','));
我已经为 Firefox 制作了一些插件和 Chrome 的扩展,但现在我有了一个疯狂的想法,我想知道我是否可以禁用 Firefox / Chrome来自插件/扩展的组件。
当我说禁用组件时,我的意思是(主要是 FF 示例):
- 火狐你好
- Pocket(Firefox 现在默认集成了 Pocket)
- 历史
- 收藏夹
- 其他已安装的扩展程序
- "Print" 和 "Developer Tools" 等资源
- 等等
我搜索了整个 Firefox Addon Developer Hub,但没有找到我是否可以做类似的事情。如果您知道答案,我该怎么做或为什么不能?
您无需说明为什么(或不可能)可行以及我如何实现,但在这种情况下请提供有用且有趣的链接。
从 Firefox 中禁用其他东西非常容易。
例如,这会通过 id 禁用插件:
//this checks to see if AdBlock Plus is enabled
AddonManager.getAddonsByIDs(["{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}"], function ([aAddon1]) {
console.log(aAddon1);
var isAddonEnabled = aAddon1.isActive;
alert('AdBlock plus enabled = ' + isAddonEnabled)
//for other properties see here: https://developer.mozilla.org/en-US/Add-ons/Add-on_Manager/Addon#Required_properties
});
组件的处理方式略有不同,您必须使用 nsICategoryManager,这会禁用默认的 pdf reader:
var CONTENT_TYPE = 'application/pdf';
// Update the category manager in case the plugins are already loaded.
let categoryManager = Cc['@mozilla.org/categorymanager;1'];
categoryManager.getService(Ci.nsICategoryManager).deleteCategoryEntry('Gecko-Content-Viewers', CONTENT_TYPE, false);
// Update pref manager to prevent plugins from loading in future
var stringTypes = '';
var types = [];
var PREF_DISABLED_PLUGIN_TYPES = 'plugin.disable_full_page_plugin_for_types';
if (Services.prefs.prefHasUserValue(PREF_DISABLED_PLUGIN_TYPES)) {
stringTypes = Services.prefs.getCharPref(PREF_DISABLED_PLUGIN_TYPES);
}
if (stringTypes !== '') {
types = stringTypes.split(',');
}
if (types.indexOf(CONTENT_TYPE) === -1) {
types.push(CONTENT_TYPE);
}
Services.prefs.setCharPref(PREF_DISABLED_PLUGIN_TYPES, types.join(','));