更新 Chrome 中的 Greasemonkey 脚本而不重新安装?
我只是希望能够保存、刷新页面,并像在 Firefox 中一样显示我的更改。每次都必须将其拖过来并安装,这很烦人。
有什么想法吗?
I just want to be able to save, refresh the page, and have my changes show up like I do in Firefox. Having to drag it over and install it every time gets annoying.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,有一种方法可以做到这一点。使用这个精彩答案中采用的方法(^ _^),您可以就地编辑脚本,只需点击“重新加载”链接即可使更改生效。
此方法还有一个额外的好处,即 Chrome 的扩展程序文件夹1不会因难以辨认的文件夹和文件名而变得混乱,并且您可以轻松找到要调整的脚本。
以下是如何设置您的工作环境以允许轻松更新脚本:
创建一个您方便的目录,并且不是 Chrome 通常查找扩展程序的目录 1.. 例如,创建:
C:\MyChromeScripts\
。这将是您将来所有脚本的驻留位置。
为每个脚本创建自己的子目录。 例如,
Script_1
、Script_2
等。每个子目录都应包含其脚本、EG
MyScript1.user.js
以及任何文件由该脚本使用。现在秘密武器...您还必须在该子目录中创建一个清单文件,并且它必须命名为:
manifest.json
。示例内容至少:
<前><代码>{
“清单版本”:2,
“内容脚本”:[ {
“排除_globs”:[],
“include_globs”:[“*”],
"js": [ "MyScript1.user.js" ],
“匹配”:[“https://stackoverflow.com/*”,
“https://stackoverflow.com/*”
]
}],
"description": "此脚本执行 X、Y 和 Z。",
"name": "我的脚本编号 1",
“版本”:“1”
}
现在,在 Chrome 的扩展程序管理器 (URL = chrome://extensions/) 中,展开开发者模式 。
单击加载解压的扩展...按钮。
对于文件夹,请粘贴脚本的文件夹,例如:
C:\MyChromeScripts\Script_1
。您的脚本将被安装并可运行。
保持“扩展”页面打开。现在,当您保存对 *.js 文件的任何更改时,请点击重新加载链接以使它们立即生效。
享受吧!
1 扩展文件夹默认为:
尽管您可以通过使用
--user-data-dir=
选项运行 Chrome 来更改它。Yes, there is a way to do this. Using the method adopted from this brilliant answer (^_^), you can edit scripts -- in place -- and just hit a "Reload" link for the changes to take effect.
This method has the added bonus that Chrome's Extensions folder1 doesn't get cluttered with indecipherable folder and file names, and you can easily find the script you want to tweak.
Here's how to set up your work environment to allow easy script updating:
Create a directory that's convenient to you, and not where Chrome normally looks for extensions1. For example, Create:
C:\MyChromeScripts\
.This will be where all your scripts will reside in the future.
For each script create its own subdirectory. For example,
Script_1
,Script_2
, etc.Each subdirectory should contain its script, EG
MyScript1.user.js
, and any files used by that script.Now for the secret sauce... You must also create a manifest file in that subdirectory, and it must be named:
manifest.json
.Sample contents, at a minimum:
Now, in Chrome's Extension manager (URL = chrome://extensions/), Expand Developer mode.
Click the Load unpacked extension... button.
For the folder, paste in the folder for your script, For example:
C:\MyChromeScripts\Script_1
.Your script will be installed and operational.
Keep the Extensions page open. Now, when you save any changes to your *.js file, Hit the Reload link for them to take effect immediately.
Enjoy!
1 The extensions folder defaults to:
Although you can change it by running Chrome with the
--user-data-dir=
option.如果您有可以导入更改后的文件的服务器,则可以这样做。
像这样,
这首先加载 jQuery,然后加载我的自定义脚本,当我运行网页时,它总是重新加载整个脚本。
也许这对你也有帮助。
You can do that if you have somewhere server where you can import your changed file.
Like this
This loads first jQuery then my custom script, when i run the webpage it always reloads the whole script.
Maybe this helps you too.
如果您不想重新安装脚本,可以重新启动chrome。
这应该会使您的更改生效。
我同意这很烦人
If you don't want to reinstall the script, you can restart chrome.
This should make your changes to take effect.
I agree this is very annoying
一个简单的方法是使用两个文件:
userscript.user.js
,其中包含加载script.js
的 GM 标头。您可以让它每天清除缓存(告诉它加载添加了随机查询字符串的script.js
)script.js
。例如,我已经在此处完成了该操作
该脚本加载
script.js?purge=xyz
,其中xyz
取决于日期。清除查询字符串可确保脚本仅缓存一天而不是更多 - 到第二天,它将重新加载。对于开发用途,"script.js?purge="+Math.random()
更好。如果脚本位于您的本地计算机上,则您无需担心自己的缓存。现在,如果您对
script.js
进行更改,到明天每个人都将使用更新的版本。An easy way to do this is to use two files:
userscript.user.js
with GM headers which loadsscript.js
. You can make it purge the cache every day (tell it to loadscript.js
with a random query string added)script.js
which contains the actual script.For example, I've done that here
The script loads
script.js?purge=xyz
, wherexyz
depends on the date. The purge query string makes sure that the script is only cached for a day and not more--by next day, it will be loaded afresh. For development uses,"script.js?purge="+Math.random()
is better. If the script is on your local machine though, you need not worry about the cache for yourself.Now, if you make a change to
script.js
, by tomorrow everyone will be using the updated version.