How to add user script js file as a Chrome extension?

倖福魔咒の 提交于 2020-01-05 05:48:11

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/40796949/how-to-add-user-script-js-file-as-a-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!