如何使用Firefox Addon Builder记录所选文本?(How can I log selected text with Firefox Addon Builder?)
我已经按照几个教程没有成功。 我认为这是典型的例子,但我无法使其发挥作用。 我可以保存我的项目,安装插件,当我选择一些文本时,我可以看到上下文菜单项“日志选择”,但是当我点击它时没有任何反应。
exports.main = function() { var contextMenu = require("context-menu"); var request = require("request"); var selection = require("selection"); var menuItem = contextMenu.Item({ label: "Log Selection", context: contextMenu.SelectionContext(), contentScript: 'self.on("click", function () {' + ' var text = window.getSelection().toString();' + ' self.postMessage(text);' + '});', onMessage: function (selectionText) { alert(selectionText); } }); }
即使我的插件只包含一个警报,也会安装插件,但不会显示警报。
exports.main = function() { alert("Hello world"); }
额外信息:
- SDK:1.14(最新)
- 附加构建器助手:1.7(最新)
- 在Builder网页上添加: https : //builder.addons.mozilla.org
I have followed several tutorials with no success. I think this is the classic example but I can't make it work. I can save my project, install the addon and I can see the context menu item "Log Selection" when I select some text, but when I click on it nothing happens.
exports.main = function() { var contextMenu = require("context-menu"); var request = require("request"); var selection = require("selection"); var menuItem = contextMenu.Item({ label: "Log Selection", context: contextMenu.SelectionContext(), contentScript: 'self.on("click", function () {' + ' var text = window.getSelection().toString();' + ' self.postMessage(text);' + '});', onMessage: function (selectionText) { alert(selectionText); } }); }
Even if my addon contains only one alert, the addon is installed but the alert is not shown.
exports.main = function() { alert("Hello world"); }
Extra info:
- SDK: 1.14 (up to date)
- Add-on Builder Helper: 1.7 (up to date)
- Add On Builder Webpage: https://builder.addons.mozilla.org
原文:https://stackoverflow.com/questions/18233888
最满意答案
您需要使用npm来安装它,然后在
*ts
文件的顶部声明它。 这是一个使用lodash
的例子:import {Component, OnInit} from '@angular/core'; import {Router} from '@angular/router'; const _ = require('lodash'); @Component({ selector: 'my-component', templateUrl: './my-component.component.html', styleUrls: ['./my-component.component.scss'] })
你会的
const ahrs = require('ahrs');
You need use npm to install it and then declare it at the top of your
*ts
file. Here's an example usinglodash
:import {Component, OnInit} from '@angular/core'; import {Router} from '@angular/router'; const _ = require('lodash'); @Component({ selector: 'my-component', templateUrl: './my-component.component.html', styleUrls: ['./my-component.component.scss'] })
Yours would be
const ahrs = require('ahrs');
相关问答
更多-
我不熟悉Showdown,但如果你想在代码中导入它,你需要有类型定义文件。 如果您使用TypeScript 2.0,只需从npmjs.org安装即可。 我刚刚检查过 - 他们在@types组织中有Showdown的类型定义: https ://www.npmjs.com/search ? q =% 40types%2Fshowdown 只需运行npm i @types/showdown --save-dev 。 如果使用较旧的TypeScript,请使用Typings安装声明。 不要忘记在index.htm ...
-
它没有按原样添加到index.html 。 它将添加到scripts.bundle.js index.html会有一个脚本标记,如下所示, shp.js文件将是scripts.bundle.js一部分,打开此文件,您可以找到shp.js内容。 It doesnt get adde ...
-
您需要定义打印稿才能使用第三方模块。 每个模块都带有一个typescript d.ts文件,它定义了您可以在库中使用的方法。 但是,这并没有包含任何内容,因此您需要编写自己的d.ts文件或检查DefinitelyTyped的回购: https : //github.com/DefinitelyTyped/DefinitelyTyped 只需将d.ts文件添加到您的项目中,即可使用您的库。 You need a definition typescript in order to use third party ...
-
您需要使用npm来安装它,然后在*ts文件的顶部声明它。 这是一个使用lodash的例子: import {Component, OnInit} from '@angular/core'; import {Router} from '@angular/router'; const _ = require('lodash'); @Component({ selector: 'my-component', templateUrl: './my-component.component.html' ...
-
Angular2如何使用AngularCLI添加第三方插件(webpack)(Angular2 how to add 3rd party plugin using AngularCLI (webpack))[2023-01-29]
好吧我明白了。 这就是我所做的。 在angular-cli.json中,我将其添加到脚本中: "scripts": [ "../node_modules/gsap/src/minified/TweenMax.min.js", "../node_modules/scrollmagic/scrollmagic/minified/ScrollMagic.min.js", "../node_modules/scrollmagic/scrollmagic/minified/plug ... -
你必须先初始化它: constructor() { this.md = marked.setOptions({}); } was a systemjs configuration problem.
-
按照以下步骤在angular-cli项目中使用flickity npm install flickity --save 宣告模块'flickity'; 在typings.d.ts 从“flickity”导入*作为Flickity; 在app.component.ts中(需要在需要的地方导入) 像你提到的那样使用它 this.slider = new Flickity('.news-wrapper', { cellAlign: 'left', contain: true, prevNextButtons: f ...
-
我会把它包装成一个自定义指令: @Directive({ selector: '[spinner]' }) export class SpinnerDirective { constructor(private elementRef:ElementRef.nativeElement) { } ngAfterViewInit() { var spinner = new Spinner(opts).spin(this.elementRef); } } 并以这种方式使用它: @Co ...
-
导入第三方库(Import 3rd party library)[2022-05-16]
您必须向tsconfig.json添加路径(和tsconfig.json : { "compilerOptions": { ... "baseUrl: ".", "paths": { "easeljs": ["../node_modules/createjs-easeljs/lib/easeljs-0.8.2.min.js"] }, } } 与easeljs相对于你的tsconfig.json的路径。 之后,您可以使用以下方法导入此库: import * ... -
在nativescript中访问android本机方法时,你需要使用完整的包名和类,例如com.kontakt.sdk.android.common.KontaktSDK.initialize("API_KEY")也是我在开发nativescript插件时拾取的一个小技巧你可以在类上使用console.dump(com.kontakt.sdk.android.common.KontaktSDK) ,它将显示该类中包含的所有方法。 如有疑问,请将其注销 When accessing android nativ ...