Skip to content

Instantly share code, notes, and snippets.

@findoff
Last active March 13, 2018 07:14
Show Gist options
  • Save findoff/5f3b93b66471685d2a40a80e7db49013 to your computer and use it in GitHub Desktop.
Save findoff/5f3b93b66471685d2a40a80e7db49013 to your computer and use it in GitHub Desktop.
/*
add panel with fold/unfold button at top-left
inject with custom-javascript-for-web chrome plugin
( https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija )
*/
~function(){
if(window.pluginFold){
try{
document.body.removeChild(window.pluginFold.panel);
}catch(e){console.error(e);}
}
let p = window.pluginFold = {
setFold(fold){
let cm = document.querySelectorAll(".CodeMirror")[2].CodeMirror;
cm.operation(()=>{
for (var l = cm.firstLine(); l <= cm.lastLine(); ++l)
cm.foldCode({line: l, ch: 0}, null, fold ? "fold" : "unfold");
})
},
};
p.panel = document.createElement("div");
p.panel.style.position = "absolute";
p.panel.style.left = "150px";
p.panel.style.top = "0px";
p.panel.className = "plugin-fold-panel";
//p.panel.style.border = "2px solid red";
//p.panel.style.width = "128px";
//p.panel.style.height = "128px";
p.panel.style.zIndex = 100;
let btn;
btn = document.createElement("button");
btn.textContent = "fold";
btn.onclick = e=>p.setFold(true);
p.panel.appendChild(btn);
btn = document.createElement("button");
btn.textContent = "unfold";
btn.onclick = e=>p.setFold(false);
p.panel.appendChild(btn);
document.body.appendChild(p.panel);
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment