今天装了 Pow,第一次打开时,它提示 Automatic RVM support is deprecated
然后有个链接 Add this code to .powrc for me
,点击后,就会自动在你的项目加上.powrc 这个文件
在页面源码找了一下相关的 JS,那个链接就是绑定 click 事件到 function addToPowrc 的,好奇怎样实现的,JS 可以操作本地文件?
function addToPowrc(link) {
perform(link, "add_to_powrc",
"This code has been added to your application’s <code>.powrc</code> file."
)
}
function perform(link, action, successHTML) {
if (link.className == "busy") return
link.className = "busy"
xhr = new XMLHttpRequest()
xhr.open("POST", "/__pow__/rvm_deprecation/" + action, true)
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) return
link.className = ""
if (xhr.status == 200) {
var p = link.parentNode
var previousInnerHTML = p.previousInnerHTML
p.previousInnerHTML = p.innerHTML
p.innerHTML = successHTML || previousInnerHTML
}
}
xhr.send()
}