Skip to content

Instantly share code, notes, and snippets.

@cnicodeme
Last active December 24, 2015 01:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnicodeme/6725674 to your computer and use it in GitHub Desktop.
Save cnicodeme/6725674 to your computer and use it in GitHub Desktop.
Switch the Cryptocat discussion page from fixed layout to full width layout :)
// Inject css rules in Cryptocat conversation for a full width display
// Also add a "body click to text focus" action (using jQuery, already embedded in Cryptocat)
// Note: Only tested on IE 6 ! (Ok, I'm kidding, only Chrome)
// Author : Cyril N.
(function (){
var newcss = "#userInput>#userInputText {width : 84%;} body>div#bubble {width : auto; margin : 0 auto; position : absolute; top : 0; bottom : 0; left : 0; right : 0; height : auto; border-radius: 0}";
newcss += "div#conversationWindow .line1, div#conversationWindow .line2, div#conversationWindow .line3, div#conversationWindow .line4 {max-width : 96%;}";
newcss += "div#buddyWrapper {width : 14%;}";
newcss += "div#buddyList {width : 100%; overflow-y : hidden;}";
console.log (newcss);
if ('\v'=='v') /* ie only */ {
document.createStyleSheet().cssText = newcss;
} else {
var tag = document.createElement('style'); tag.type = 'text/css'; document.getElementsByTagName('head')[0].appendChild(tag);
tag[ (typeof document.body.style.WebkitAppearance=='string') /* webkit only */ ? 'innerText' : 'innerHTML'] = newcss;
}
document.getElementById("bubble").style.marginTop = 0;
$('#bubble').on ('click', function() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
if (text != "") {
return ;
}
$('#userInputText').trigger('focus');
});
})();
@cnicodeme
Copy link
Author

And here's the bookmarklet :

(function(){var b="#userInput>#userInputText {width : 84%;} body>div#bubble {width : auto; margin : 0 auto; position : absolute; top : 0; bottom : 0; left : 0; right : 0; height : auto; border-radius: 0}";b+="div#conversationWindow .line1, div#conversationWindow .line2, div#conversationWindow .line3, div#conversationWindow .line4 {max-width : 96%;}";b+="div#buddyWrapper {width : 14%;}";b+="div#buddyList {width : 100%; overflow-y : hidden;}";console.log(b);if("\v"=="v"){document.createStyleSheet().cssText=b}else{var a=document.createElement("style");a.type="text/css";document.getElementsByTagName("head")[0].appendChild(a);a[(typeof document.body.style.WebkitAppearance=="string")?"innerText":"innerHTML"]=b}document.getElementById("bubble").style.marginTop=0;$("#bubble").on("click",function(){var c="";if(window.getSelection){c=window.getSelection().toString()}else{if(document.selection&&document.selection.type!="Control"){c=document.selection.createRange().text}}if(c!=""){return}$("#userInputText").trigger("focus")})})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment