我正在尝试修改Firefox扩展程序。有一个“panel.html”页面,带有关联的“panel.js”文件。 “Panel.js”似乎导出了一堆类。我不确定它是如何实际执行的。对我来说有点难以理解;它看起来很神秘,我没有用这种方式使用JavaScript。基本上,有一个开关,我想在打开Firefox时自动切换“打开”。
我没有使用Firefox扩展开发的经验。似乎“bootstrap.js”是沙箱。因此,当我尝试导入“panel.js”时,我会收到诸如“未定义文档”之类的错误。当您单击面板图标并打开时,我已经切换到开关,但是当Firefox打开时我需要这样做。
有人能指出我正确的方向吗?
Bootstrap.js
const { utils: Cu } = Components;
const rootURI = __SCRIPT_URI_SPEC__.replace("bootstrap.js", "");
const COMMONJS_URI = "resource://gre/modules/commonjs";
const { require } = Cu.import(COMMONJS_URI + "/toolkit/require.js", {});
const { Bootstrap } = require(COMMONJS_URI + "/sdk/addon/bootstrap.js");
var { startup, shutdown, install, uninstall } = new Bootstrap(rootURI);
Panel.js
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// Created by Valentin Shergin.
// Copyright (c) 2015 AnchorFree. All rights reserved.
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _WdgtUniversalPipePipeOut = require('Wdgt/../universal/pipe/PipeOut');
var _WdgtUniversalPipePipeOut2 = _interopRequireDefault(_WdgtUniversalPipePipeOut);
var promise = null;
function remoteCakeTubeSDK() {
if (!promise) {
promise = new _WdgtUniversalPipePipeOut2['default']('CakeTubeSDK');
}
return promise;
}
exports['default'] = remoteCakeTubeSDK;
module.exports = exports['default'];
},{"Wdgt/../universal/pipe/PipeOut":12}],
(此后大约有200多个出口) 相关课程:
42:[function(require,module,exports){
// Created by Valentin Shergin.
// Copyright (c) 2015 AnchorFree. All rights reserved.
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
require('./ToolbarConnectionSwitcher.less');
require('./Spinner.less');
var _CommonSwitcherSwitcher = require('../Common/Switcher/Switcher');
var _CommonSwitcherSwitcher2 = _interopRequireDefault(_CommonSwitcherSwitcher);
var _remoteCakeTubeSDK = require('remoteCakeTubeSDK');
var _remoteCakeTubeSDK2 = _interopRequireDefault(_remoteCakeTubeSDK);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _PanelController = require('../PanelController');
var _PanelController2 = _interopRequireDefault(_PanelController);
var _reactSpinner = require('react-spinner');
var _reactSpinner2 = _interopRequireDefault(_reactSpinner);
var ToolbarConnectionSwitcher = (function (_Component) {
_inherits(ToolbarConnectionSwitcher, _Component);
function ToolbarConnectionSwitcher() {
var _this = this;
_classCallCheck(this, ToolbarConnectionSwitcher);
_get(Object.getPrototypeOf(ToolbarConnectionSwitcher.prototype), 'constructor', this).call(this);
this.state = {
connected: true
};
this.cakeTubeSDK().then(function (CakeTubeSDK) {
CakeTubeSDK.connectionService.dispatcher.register(_this.handleConnectionService.bind(_this));
});
//**********************************
//Here I can add this line to make it connect when the panel is opened
this.handleConnect();
//**********************************
this.checkConnectionStatus();
}
_createClass(ToolbarConnectionSwitcher, [{
key: 'cakeTubeSDK',
value: function cakeTubeSDK() {
return (0, _remoteCakeTubeSDK2['default'])();
}
}, {
key: 'checkConnectionStatus',
value: function checkConnectionStatus() {
var _this2 = this;
this.cakeTubeSDK().then(function (CakeTubeSDK) {
return CakeTubeSDK.connectionService.getStatus().then(function (status) {
var connectingOrDisconnecting = status == 'connecting' || status == 'disconnecting';
var connected = status == 'connected';
_this2.refs.self.getDOMNode().classList.toggle('connecting-or-disconnecting', connectingOrDisconnecting);
if (!connectingOrDisconnecting) {
_this2.setState({ connected: connected });
_this2.refs.switcher.setState({ state: connected });
}
});
});
}
}, {
key: 'handleConnectionService',
value: function handleConnectionService() {
this.checkConnectionStatus();
}
}, {
key: 'handleConnect',
value: function handleConnect() {
var _this3 = this;
this.cakeTubeSDK().then(function (CakeTubeSDK) {
return CakeTubeSDK.connectionService.connect().then(function () {
_this3.checkConnectionStatus();
});
})['catch'](function (error) {
_this3.reportError(error);
});
}
}, {
key: 'handleDisconnect',
value: function handleDisconnect() {
var _this4 = this;
this.cakeTubeSDK().then(function (CakeTubeSDK) {
return CakeTubeSDK.connectionService.disconnect().then(function () {
_this4.checkConnectionStatus();
});
})['catch'](function (error) {
_this4.reportError(error);
});
}
}, {
key: 'handleSignOut',
value: function handleSignOut() {
var _this5 = this;
this.cakeTubeSDK().then(function (CakeTubeSDK) {
return CakeTubeSDK.connectionService.disconnect().then(CakeTubeSDK.clientService.logOut());
})['catch'](function (error) {
_this5.reportError(error);
});
}
}, {
key: 'reportError',
value: function reportError(error) {
this.checkConnectionStatus();
_PanelController2['default'].panelController().showProblem(error);
}
}, {
key: 'handleSwitcherChanged',
value: function handleSwitcherChanged() {
var switcher = this.refs.switcher;
var state = !!switcher.state.state;
if (state) {
this.handleDisconnect();
} else {
this.handleConnect();
}
}
}, {
key: 'render',
value: function render() {
var rvalue = _react2['default'].createElement(
'div',
{ className: 'toolbar-connection-switcher', ref: 'self' },
_react2['default'].createElement(_CommonSwitcherSwitcher2['default'], { ref: 'switcher', onChanged: this.handleSwitcherChanged.bind(this) }),
_react2['default'].createElement(
'div',
{ className: 'spinner' },
_react2['default'].createElement(_reactSpinner2['default'], null)
)
);
return rvalue;
}
}]);
return ToolbarConnectionSwitcher;
})(_react.Component);
exports['default'] = ToolbarConnectionSwitcher;
module.exports = exports['default'];
},{"../Common/Switcher/Switcher":21,"../PanelController":31,"./Spinner.less":41,"./ToolbarConnectionSwitcher.less":43,"react":206,"react-spinner":51,"remoteCakeTubeSDK":1}],43:[function(require,module,exports){
(function() { var head = document.getElementsByTagName('head')[0]; var style = document.createElement('style'); style.type = 'text/css';var css = ".toolbar-connection-switcher{position:absolute;top:11px;right:11px}.toolbar-connection-switcher .switcher{opacity:1}.toolbar-connection-switcher .spinner{position:absolute;top:13px;left:6px;pointer-events:none;opacity:0}.toolbar-connection-switcher .switcher,.toolbar-connection-switcher .spinner{transition:opacity .25s}.toolbar-connection-switcher.connecting-or-disconnecting .switcher{opacity:0}.toolbar-connection-switcher.connecting-or-disconnecting .spinner{opacity:1}";if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style);}())
},{}],
答案 0 :(得分:1)
这是使用jpm xpi
为附加SDK扩展生成的 .xpi 文件。您需要查看文件 package.json 。该文件中的属性main
的值将告诉您始终在Firefox启动时运行的文件的名称或此加载项的安装/启用。
您显示的 bootstrap.js 与使用该版本jpm
创建的所有附加SDK扩展中包含的完全相同的代码。
您应该不修改 bootstrap.js 。在任何附加SDK扩展程序中,该文件为附加SDK扩展以及分配给startup
,shutdown
,install
,{{的功能设置环境1}}(使用uninstall
)运行首次安装加载项时启用的 package.json 中定义的var { startup, shutdown, install, uninstall } = new Bootstrap(rootURI);
属性所指向的文件中包含的代码,或启动Firefox(以及其他时间)。
您的问题缺乏足够的信息来提供有关如何完成您所需内容的更详细信息。例如,我们不知道完整代码到底是什么(您没有提供实际扩展的链接)。另外,我们不知道&#34;切换&#34;您希望自动切换到哪个。这甚至可能不是实现你想要的最合适的方法。实际上,您没有为我们提供足够的信息来确定您实际希望发生的事情。