如何将用户脚本js文件添加为Chrome扩展? [英] How to add user script js file as a Chrome extension?

查看:1499
本文介绍了如何将用户脚本js文件添加为Chrome扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究可以在不使用Tampermonkey的情况下运行的Chrome用户脚本。今天,我向Chrome扩展程序中添加了第三方扩展程序(userscript js):

  // == UserScript == 
// @name作业转换器
// @namespace Marshmellows
// @version 0.1
// @description将'Stack'中的'Jobs'改为Hello!
// @match http://stackoverflow.com/*
// @grant none
// @ run-at document-start
// == / UserScript = =

document.addEventListener('DOMContentLoaded',function(){
document.getElementById('nav-jobs')。innerHTML ='Hello!';
},false );

我通过简单地将文件拖入内容(它工作正常)将其添加到Chrome扩展中。 p>

我重新启动了Chrome并发现它完全阻止了我的js文件扩展名。
我似乎无法找到解决这个问题的方法。我参加了Chrome的论坛,并试图找到创建 .crx 文件的方法。但是因为我对Web开发和DOM很陌生,所以我觉得我需要一些指导。可以做任何事情吗?

当你发现,虽然你仍然可以安装一个简单的用户脚本通过拖动到 chrome:// extensions / 页面,当Chrome重新启动时,它将自动禁用。 Google声称这是为了保护用户来自恶意扩展



为了让您的脚本不被自动禁用,您必须手动将其包含到扩展中。请参阅此答案控制脚本和名称部分中的步骤。



以这种方式安装的扩展程序不会自动禁用,但它们将 在Chrome的每一个开始处触发弹出式警告

Google拒绝为开发者提供任何追踪该弹出窗口的动作。为避免这种情况,您必须在Google Pay Store中注册您的新扩展程序。



除非您打算毕业到扩展开发,或者您只是喜欢不必要的麻烦,否则愚蠢的做一个用户脚本。只需安装Tampermonkey,即可享受简单而强大的用户脚本开发。


I have been currently working on user scripts for Chrome that can function without the use of Tampermonkey. Today I added a third party extension (a userscript js) to the Chrome extensions:

// ==UserScript==
// @name       "job changer"
// @namespace  Marshmellows
// @version    0.1
// @description  Change 'Jobs' in stackoverflow to Hello!
// @match      http://stackoverflow.com/*
// @grant      none
// @run-at     document-start
// ==/UserScript==

document.addEventListener('DOMContentLoaded', function() {
    document.getElementById('nav-jobs').innerHTML = 'Hello!';
}, false);

I added this to the Chrome extensions by simply dragging the file inside (it worked fine).

I restarted Chrome and discovered that it had completely blocked my js file extension. I can't seem to find a solution for this problem. I went on Chrome's forum and tried to find ways to create a .crx file. But because I am quite new to web development and the DOM, I feel like I need some guidance. Can anything be done?

解决方案

As you discovered, although you can still install a plain userscript by dragging it to the chrome://extensions/ page, it will be automatically disabled when Chrome restarts. Google claims that this is to "protect" users from malicious extensions.

To keep your userscript from being auto disabled, you must pack it into an extension manually. See the steps at the "Controlling the Script and name" section of this answer.

Extensions installed this way will not be auto-disabled, but they will trigger a popup warning on every single start of Chrome!
Google refuses to provide developers any recourse to that popup. To avoid it, you must register your new extension in the Google Pay Store.

Unless you plan to graduate to extension development, or you just love needless hassle, it would be foolish to do this for a userscript. Just install Tampermonkey and enjoy how easy and powerful userscript development can be.

这篇关于如何将用户脚本js文件添加为Chrome扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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