我使用Chrome开发者工具来调试我的JavaScript代码,但是我对Chrome在“脚本”选项卡下让你编辑JavaScript文件的方式有一个小抱怨。有时,我没有意识到自己正在使用Chrome,并开始更改“脚本”选项卡下的代码,直到我刷新后才意识到我刚刚做的更改从未保存到磁盘上!
我想知道是否有一种方法可以使“脚本”选项卡中显示的代码只读,以便如果我尝试在Chrome中编辑文件,我会看到它是不可编辑的,然后意识到我没有在我的IDE中。
我使用Chrome开发者工具来调试我的JavaScript代码,但是我对Chrome在“脚本”选项卡下让你编辑JavaScript文件的方式有一个小抱怨。有时,我没有意识到自己正在使用Chrome,并开始更改“脚本”选项卡下的代码,直到我刷新后才意识到我刚刚做的更改从未保存到磁盘上!
我想知道是否有一种方法可以使“脚本”选项卡中显示的代码只读,以便如果我尝试在Chrome中编辑文件,我会看到它是不可编辑的,然后意识到我没有在我的IDE中。
使用以下步骤在Chrome 32+中使脚本源代码只读:
Go to the chrome://flags/#enable-devtools-experiments URL
Select Allow UI Themes
Open Chrome Dev Tools
Select Settings (Press F1 or click on the three dots on the far right)
Select Allow UI Themes
Create a DevTools theme with the following style:
.content-view.script > .text-editor { -webkit-user-modify: read-only !important; }
Publish it the the Chrome Web Store
Install the Theme
Restart Chrome
参考资料
对于Chrome 31及以下版本,请使用旧流程:
使用用户样式表来完全禁用脚本选项卡:
.toolbar-item.scripts { display:none !important; } /* Hide Scripts Tab */
.text-editor-editable { -webkit-user-modify: read-only !important; } /* Old selector */
.content-view.script > .text-editor { -webkit-user-modify: read-only !important; } /* Older selector */
.editing { -webkit-user-modify: read-only !important; } /* Generic Selector */
chrome.devtools.inspectedWindow.onResourceContentCommitted.addListener(function(resource, content) {
alert("WARNING: Your changes will not be saved!!");
// Optional, but and extra layer of "protection", if you don't want/need it just remove the "experimental" permission from the manifest
if (chrome.experimental) {
chrome.experimental.devtools.console.addMessage("error", "WARNING: Your changes will not be saved!!");
// Shows in red
}
});
解决方案一:安装拓展程序(未打包的,则首先在 chrome://flags 中启用实验性拓展API):http://www.mediafire.com/?wb1r67ron0x6szh
修改源代码并运行自定义构建:
另一个选项就是修改开发工具源码,请参见https://developers.google.com/chrome-developer-tools/docs/contributing获取更多信息。如果您这样做,只需从编辑器容器中删除 text-editor-editable
类(位于第 1279 行中的DefaultTextEditor.js),即可完成。
让 Chrome 自动保存您的文件:
第三个选项是启用 Chrome 保存您的文件,有很多扩展可以实现此功能,比如 Tincr。Tincr 还可以实时重新加载文件,并提供完整的语法高亮显示。
个人认为这是最佳解决方案。
:before
创建一个透明遮罩在编辑器上。你仍然可以进行调试,但不能选择或编辑。 - A.M.K