我在元块中定义了我的用户脚本的版本,如下所示:
// ==UserScript==
// @name Script Name
// @description Something about what this script does
// @include http://www.example.com/
// @version 5.3.0
// @run-at document-end
// ==/UserScript==
Run Code Online (Sandbox Code Playgroud)
有没有办法获得我定义的版本号?我希望能够做类似的事情alert("This is version " + SCRIPT_VERSION + ".");.
在PHP中,如何测试是否设置了环境变量?我想这样的行为:
// Assuming MYVAR isn't defined yet.
isset(MYVAR); // returns false
putenv("MYVAR=foobar");
isset(MYVAR); // returns true
Run Code Online (Sandbox Code Playgroud) 我正在编写一个 PowerShell 脚本,其中许多整数必须转换为字符串。我正在使用该ToString方法来执行此操作,如下所示:
$i = 5
$i.ToString()
Run Code Online (Sandbox Code Playgroud)
不幸的是,这似乎很慢(我省略了执行策略警告):
PS I:\ADCC\Scripting Performance> .\int_to_str.ps1
6.747561
PS I:\ADCC\Scripting Performance> .\int_to_str.py
0.37243021680382793
Run Code Online (Sandbox Code Playgroud)
我正在使用 PowerShell 2 和 Python 3。
PS I:\ADCC\Scripting Performance> $PSVersionTable
Name Value
---- -----
CLRVersion 2.0.50727.5485
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
PS I:\ADCC\Scripting Performance> python --version
Python 3.6.1
Run Code Online (Sandbox Code Playgroud)
这是内容int_to_str.ps1:
(Measure-Command {
ForEach($i in 1..1000000){
$i.ToString()
}
}).TotalSeconds
Run Code Online (Sandbox Code Playgroud)
这是内容int_to_str.py:
#!/usr/bin/env python3
import time
start = time.perf_counter()
for i in …Run Code Online (Sandbox Code Playgroud) 假设我在Scheme中创建了一个向量/数组:
(let* ((x #(1 2 3)))
(list-ref x 0)) ; returns error
Run Code Online (Sandbox Code Playgroud)
我可以在list-ref的位置使用什么语法或函数1?
编辑:我正在使用Script-Fu和GIMP 2.8,array-ref这似乎不起作用.
我需要知道是否window.close()真的要关闭窗口.这不是关闭窗口的重复- 如何确定窗口的打开方式?因为该解决方案依赖于检查window.name,这不是万无一失的; 弹出窗口可以使用不同的名称打开,但仍然可以通过window.close().
我不能只检查是否window.opener定义为null,因为在Firefox和Chrome中,如果用户关闭了开启者,则window.opener设置为null.例如:
// In parent window:
window.open();
// In child window:
console.log(window.opener); // outputs a Window object
// Now, click the X on the parent window.
// Continue below in child window:
console.log(window.opener); // outputs null
// However, you can still close the window!
window.close(); // closes the child window
Run Code Online (Sandbox Code Playgroud)
另一方面,如果用户在新选项卡中加载了包含此代码的页面:
console.log(window.opener); // also outputs null
window.close(); // doesn't work; window remains …Run Code Online (Sandbox Code Playgroud) 我正在编写一个脚本,必须在某一点做这样的事情:Math.pow(-2,1.5).结果应该是大约-2.82843,但Javascript返回NaN.(我在Google Chrome 17和Mozilla Firefox 11中都试过这个.)如果指数是整数,例如in Math.pow(-2,3),则Javascript将返回正确的答案,在本例中为-8.正数也正确地提升到非整数幂; Math.pow(2,1.5)评估约为2.8284271247461903.有什么方法可以让Javascript计算负数的值到非整数幂?
我想使用CSS将背景图像的顶部与元素的底部对齐(这样我就可以transition在悬停或动画中进行渲染,以防您想知道).此元素没有设定高度; 我不知道元素的高度是多少.有人知道怎么做这个吗?解决方案不必与IE兼容; 它只需要在最新版本的Chrome和Firefox中使用.
编辑:<body>如果在赏金结束时有这样的答案,我会将赏金奖励给也适用于该元素的答案.
我注意到,如果我只指定图像的一个维度,使用标记上的width和height属性img或使用CSS,浏览器会自动按比例缩放其他维度.
例如,如果我有一个100x150图像,并且我指定width="50"或width:50px;,则浏览器会自动将高度设置为75像素.
这是否适用于所有浏览器?为了节省时间,我可以省略一个吗?我正在使用JavaScript预加载图像并动态插入它们,所以我不必担心下载时影响布局的图像.
javascript ×3
arrays ×1
css ×1
dimension ×1
dimensions ×1
exponent ×1
firefox ×1
greasemonkey ×1
image ×1
int ×1
isset ×1
math ×1
nan ×1
performance ×1
php ×1
positioning ×1
powershell ×1
scaling ×1
scheme ×1
string ×1
vector ×1
version ×1