【问题标题】:Building a User Script for Chrome using ClojureScript, how can I get the UserScript comment block to exist in compiled output?使用 ClojureScript 为 Chrome 构建用户脚本,如何让用户脚本注释块存在于编译输出中?
【发布时间】:2012-04-16 01:56:42
【问题描述】:
我正在尝试使用 ClojureScript 在 Chrome 中创建用户脚本。我遇到的问题是<name>.user.js 文件顶部需要一个注释块来声明有关用户脚本的属性。
看起来像这样:
// ==UserScript==
// @name CLJS Hello World
// @namespace http://something.com/my_cljs_user_script
// @author spoon16
// @include *
// ==/UserScript==
如何在编译好的 JS 文件中包含这个块?
【问题讨论】:
标签:
comments
userscripts
clojurescript
【解决方案1】:
(正在进行的讨论here)
-
在您的 cljsbuild 构建规范中添加一个 foreign-libs 标记(如果您使用的是 cljsbuild),这是我添加的:
:foreign-libs [{:file "comment-block.js" :provides ["comment.block"]}]
-
添加那个外来的“lib”。这是我的内容:
/**
* @fileoverview
* This file contains nothing but a comment block which is to be preserved
* by the google closure compiler. This comment block contains a comment
* block which is necessary to be in the output of the compiled javascript
* even in advanced compilation mode.
*/
/**
* @preserve
// ==UserScript==
// @description Description of the user script
// @include INCLUDESPEC HERE
// @include ETC ETC
// @name user script name
// ==/UserScript==
*/
-
(需要)您的外部库。
(require [comment.block :as ignored])
-
运行您的(高级)编译。在编译输出的某个地方,会出现 UserScript 块(请注意,用户脚本块必须位于第 0 列,以 // style cmets 开头,这就是为什么在@preserve 之后有换行符的原因。
李>
调用编译后的输出类似于blablabla.user.js(需要后缀'user.js'),greasemonkey 会识别它,从用户脚本块中提取数据,每个人都有独角兽(甚至是素食主义者!)
【解决方案2】:
我认为最好的办法是使用两个单独的文件——一个是保留为 javascript 文件的 UserScript 模板,另一个是实际编译的 ClojureScript。只需包含执行所需 ClojureScript 的函数即可。