如何在网页上添加用户脚本安装按钮? [英] How do I add a userscript installation button to my web page?

查看:71
本文介绍了如何在网页上添加用户脚本安装按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在公司内部网站上托管用户脚本.如何构建href,以便单击链接时Greasemonkey将安装用户脚本?

I need to host a userscript on an internal company website. How do I build the href so that Greasemonkey will install the userscript when the link is clicked?

我尝试了一个简单的<a href="user.js">Install Userscript</a>,但是Chrome和Firefox仅显示文件源,而不安装用户脚本.

I tried a simple <a href="user.js">Install Userscript</a> but Chrome and Firefox simply show the file source instead of installing the userscript.

推荐答案

您的链接应类似于:

<a href="https://example.com/your_script.user.js">Click to install script X</a>
<small>(A userscript engine, like Tampermonkey, is required.)</small>


为了使您的安装链接正常工作,必须满足以下条件:


In order for your install link to work, the following conditions must be met:

  1. 文件名必须以.user.js结尾.示例:stack_exchange_edit_reasoner.user.js
  2. 浏览器必须正在运行兼容的用户脚本扩展.例如, Tampermonkey Greasemonkey .
  3. 该文件必须不提供text/html内容类型. (要解决此问题,您必须篡改服务器的默认设置.)
  1. The filename must end in .user.js. Example: stack_exchange_edit_reasoner.user.js
  2. The browser must be running a compatible userscript extension. For example, Tampermonkey or Greasemonkey.
  3. The file must NOT be served with text/html content type. (You would have to tamper with your server's default settings for this to be an issue.)

此外,如果您希望自动更新能够正常工作,则应通过https链接提供脚本(否则脚本会变得很复杂).

Also, if you wish for automatic updates to work, the script should be served via an https link (or it gets complicated).

这篇关于如何在网页上添加用户脚本安装按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆