- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我只是想为 Angular 对象创建一些扩展,以使 AngularJS 调试更加方便。
但是当我运行 add userscript 时,它找不到 Angular 对象。 AngularJS 库加载在标签底部。
UPD:@estus 提供了正确的答案,但如果您想使用 Chrome,则需要通过 Tampermonkey 安装它扩展名。
您可以找到最终的代码片段here .
最佳答案
事实上,当用户脚本运行时,Angular 不可用,这表明 Angular 是异步加载的,这对于任何 SPA 来说都是很正常的(还要检查 @run-at 是否没有设置为 document-start
,这不是理想的行为)。
用户脚本的通常解决方法是监视所需的变量:
var initWatcher = setInterval(function () {
console.log('watch');
if (unsafeWindow.angular) {
clearInterval(initWatcher);
init();
}
}, 100);
function init() {
console.log('angular', unsafeWindow.angular);
}
如果不需要跨浏览器兼容性,则 FF 专用 Object.prototype.watch可以使用:
unsafeWindow.watch('angular', function (prop, oldVal, newVal) {
console.log('watch');
if (newVal) {
unsafeWindow.unwatch('angular');
// angular is still undefined ATM, run init() a bit later
setTimeout(init);
}
return newVal;
});
function init() {
console.log('angular', unsafeWindow.angular);
}
关于angularjs - 如何在加载 AngularJS 库后运行 userscript(/greasemonkey),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31968159/
我必须将所有站点包含在 tampermonkey 中。这是我必须运行的脚本 // ==UserScript== // @name Phishing Blockz // @namespace
在我的脚本顶部,我有以下内容: // ==UserScript== // @name Test script // @description testing auto-update
现在,我正在为浏览器游戏使用用户脚本。我在沙盒和初始化方面遇到了一些问题。 作为解决方案,我找到了一种方法,即创建新元素(脚本)并将对象插入元素。 var script = document.crea
我有一个小的 Greasemonkey 脚本,它的目的是分散所有的焦点,并将焦点返回到网页的顶层。 代码如下所示: document.addEventListener('keydown', funct
我正在努力尝试编写这个用户脚本的语法,它基本上应该遵循以下逻辑: IF (LeftArrowKeyIsPressed) THEN doSomething;ELSE IF (RightArrowKeyI
我正在尝试更改 HTML 标签并删除标签后的类/样式属性。如果我事先创建代码并替换,我已经知道如何执行此操作,现在我想知道如何在已加载的页面上找到标签并用我的 js 替换它们。 var s = "Bl
我目前正在尝试在 Tampermonkey 中为单独的页面创建 3 个用户脚本。使用 GUI,我可以单击“添加新脚本”,但是每次我在进行更改后保存时,它都会在“我的新用户脚本”顶部重新保存,并且似乎没
似乎没有关于这些功能如何工作的任何信息。我想这些是 Tampermonkey 独有的功能? 看起来它们旨在允许当前运行的 Tampermonkey 脚本之间进行通信;不断轮询 GM_Value 存储以
我注意到编译 CoffeeScript 时,没有保留任何单行注释。 这是有问题的,因为我正在尝试在 CoffeeScript 中编写 Greasemonkey/用户脚本,并且它们依赖于元数据 bloc
下面的代码是我创建的 JavaScript 用户脚本的一部分,用于在 Reddit 上的特定 subreddit 上添加评论按钮: // ==UserScript== // @name
在 chrome 中我的用户脚本导致错误 ReferenceError: jQuery is not defined 但是@require 这行包含了jquery。至少我知道它适用于 greasemo
我想为我经常使用的特定站点创建自己的 Tampermonkey 用户脚本,我想添加一些功能并改进一些东西。 因为它加载了一些 .js 文件,做了一些我不想发生的事情,我想替换这些 .js 文件并在我的
我一直在尝试将 userScript 迁移到我自己的扩展程序中,但由于某种原因我无法运行以下代码: // ==/UserScript== console.info('BEFORE Hooked! MO
我正在尝试用一组不同的颜色替换我设置的所有颜色,现在我有它 console.log'ing 我的 UserScript 加载的页面中元素的所有颜色,所以我知道它正在获取颜色正确,但由于某种原因它没有改
我正在编写一个用户脚本,每当我访问我们的 JIRA 服务器时都会运行该脚本。它将用我们公司的身份证照片商店中的图像替换用户的头像图像。这样,整个组织就不需要单独将图像上传到 JIRA 服务器上,以便用
我想将 UserScript 分发给许多人,但是我需要动态创建脚本(使用 PHP),因为某些参数会发生变化。 我有一个模板脚本;在此脚本中,我有几个参数将在运行中填写,例如,在模板中: var a_p
我正在尝试在 Tampermonkey 中运行脚本,并让它在停止之前在选项卡或给定网页上运行一次。该脚本当前会自动单击其中包含给定单词的任何“a”元素链接。示例 HTML 代码如下: Contact
这个问题在这里已经有了答案: Modify new elements when they are added (2 个答案) 关闭 5 年前。 我有这个简单的用户脚本,用于更改 YouTube 页面
顺便说一下,我是 JS 的新手,这是我的第一个脚本。 我正在编写一个小脚本,它应该允许我使用键盘快捷键在未聚焦的 newtab 中打开 flickr 页面中最大的可用图像。 我目前面临两个问题: 脚本
我花了太多时间试图解决这个问题,由于 JavaScript 不是我的主要语言,也不是 jQuery 大师,我决定我需要寻求帮助。 在生成页面的结构中,出于某种奇怪的原因,它有一个 DIV,没有 ID,
我是一名优秀的程序员,十分优秀!