不,他们不会发生冲突。我不清楚greasemonkey的执行模式的细节,但我做了一个测试。 我创造了这个HTML文件,它使用lodash一个按钮被点击时:
<html>
<head>
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.13.1/lodash.min.js'></script>
</head>
<body>
<input type='button' id="btn" value="Invoke lodash">
<script type="text/javascript">
\t el = document.getElementById("btn")
\t el.addEventListener('click',function (argument) {
\t \t console.log("3 =", _.add(1,2));
\t })
</script>
</body>
</html>
我还创建了一个userscript,这消除_:
// ==UserScript==
// @name Test greasmonkey overriding
// @namespace gm-overriding
// @version 1
// @grant none
// ==/UserScript==
_ = null
console.log("here is _:", _);
用户脚本不是影响lodash依赖性,并且按钮点击仍然打印预期的输出。
来源
2016-07-12 16:16:54
aom
该测试存在缺陷,您的结论不准确。脚本始终与页面互相干扰。 [这是一类示例](http://stackoverflow.com/questions/12146445/jquery-in-greasemonkey-1-0-conflicts-with-websites-using-jquery)。 ...在你的测试脚本中使用'window._ = null;'看看会发生什么。 –