Skip to content

Instantly share code, notes, and snippets.

@brasofilo
Last active January 28, 2021 05:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brasofilo/a539c1905608b253fcb6 to your computer and use it in GitHub Desktop.
Save brasofilo/a539c1905608b253fcb6 to your computer and use it in GitHub Desktop.
CommentsFormattingShortcuts.js (scripts here are linked from stackapps.com)

#Stack Apps Userscripts

###⎈ (SE) Customize help menu       Homepage | Install
      Remove default items and take over the help menu.
      

      


###⎈ Disable Enter key on comments on Stack Exchange       Homepage | Install
      Disable Enter key on comments on Stack Exchange.


###⎈ (SE) Markdown on Share links       Homepage | Install
      Changes the share links on Q&As to [question-title](http://post-link)


###⎈ Add keyboard shortcuts to comments       Homepage | Install


###⎈ (SOPT) Adicionar Underline em Links       Homepage | Install


###⎈ Expand Code Blocks

      Homepage | Install

// ==UserScript==
// @name Stack Exchange comments formatting shortcuts
// @namespace stackexchange
// @version 1.3
// @description Adds Ctrl+B (bold), Ctrl+I (italic), Ctrl+K (code), and Ctrl+L (link) keyboard shortcuts to comments.
// @icon http://i.stack.imgur.com/6xzO1.png
// @homepage http://stackapps.com/q/2103/5418
// @author Kip Robinson - http://stackoverflow.com/users/18511/kip
// @contributor Rodolfo Buaiz - http://stackapps.com/users/10590/brasofilo
// @match *://*.askubuntu.com/*
// @match *://*.mathoverflow.net/*
// @match *://*.serverfault.com/*
// @match *://*.stackapps.com/*
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// @exclude *://chat.*
// @exclude *://blog.*
// @exclude *://api.*
// @exclude *://data.*
// @updateURL https://gist.github.com/raw/a539c1905608b253fcb6/CommentsFormattingShortcuts.user.js
// @downloadURL https://gist.github.com/raw/a539c1905608b253fcb6/CommentsFormattingShortcuts.user.js
// @grant none
// ==/UserScript==
if( filter_so_check_page() ) {
with_jquery( start_up );
}
/**
* Check current page to determine if needs to run
*/
function filter_so_check_page() {
var will_run = false;
if( StackExchange ) {
var routes = ['Review/Task', 'Questions/Show'];
var route = StackExchange.options.routeName;
if( ( routes.indexOf(route) !== -1 ) ) {
will_run = true;
}
}
return will_run;
}
/**
* Inject the script into the page
*/
function with_jquery( callback ) {
var script = document.createElement("script");
script.type = "text/javascript";
script.textContent = "(" + callback.toString() + ")(jQuery)";
document.body.appendChild( script );
}
/**
* The real deal
*/
function start_up( $ ) {
$(document).on( 'keydown', 'textarea[name=comment]', function(e) {
//Ctrl+[BIKL]
if( (e.ctrlKey||e.metaKey) && !e.altKey && (e.which == 66 || e.which == 73 || e.which == 75 || e.which == 76))
{
//all text
var text = $(this).val();
//text before selection
var before = text.substring(0,this.selectionStart);
//selectect text
var selected = text.substring(this.selectionStart,this.selectionEnd);
//text after selection
var after = text.substring(this.selectionEnd,text.length);
//length of selection
var selLen = selected.length;
//markup character that will go before/after section. (Note: link is handled a bit differently.)
var markup = '';
var isLink = false;
if(e.which == 66)
markup = '**';
else if(e.which == 73)
markup = '*';
else if(e.which == 75)
markup = '`';
else
isLink = true;
//markup length
var mLen = markup.length;
//replace is what the selected text will be replaced with
var replace = '';
if( selLen == 0 )
{
//nothing selected. just print the markup
if(isLink)
{
var url = prompt('Please input link URL');
var linkText = prompt('Please input link text');
replace = '[' + linkText + '](' + url + ')';
}
else
{
replace = markup;
}
}
else if(
!isLink && selLen > 2*mLen
&& selected.substring(0,mLen) == markup
&& selected.substring(selLen - mLen, selLen) == markup
)
{
//We have selected something that starts and ends with the markup. We will remove the markup in
//this case. For example, "*sometext*" becomes just "sometext". This is not available for links.
replace = selected.substring(mLen, selLen - mLen);
}
else
{
//we have selected something. put the markup before and after it.
if(isLink)
{
var url = prompt('Please input link URL');
replace = '[' + selected + '](' + url + ')';
}
else
{
replace = markup + selected + markup;
}
}
//now update the text
$(this).val(before + replace + after);
if(selLen > 0)
{
//if something was selected, make the result selected too.
this.selectionStart = before.length;
this.selectionEnd = before.length + replace.length;
}
else
{
//nothign was selected, so put the cursor at the end of the updated text.
this.selectionEnd = this.selectionStart = before.length + replace.length;
}
e.stopPropagation(); //prevent bubbling (new-school)
return false; //prevent bubbling (old-school)
}
});
}
// ==UserScript==
// @name (SE) Customize help menu
// @namespace stackapps.com/users/10590/brasofilo
// @version 1.0
// @description Thanks for the help, but no thanks, I want the help for myself :D
// @icon http://i.stack.imgur.com/at65n.png
// @homepage http://stackapps.com/q/4921/10590
// @author brasofilo
// @copyright 2014, Rodolfo Buaiz (http://stackapps.com/users/10590/brasofilo)
// @license MIT http://opensource.org/licenses/MIT
// @match *://*.askubuntu.com/*
// @match *://*.mathoverflow.net/*
// @match *://*.serverfault.com/*
// @match *://*.stackapps.com/*
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// @updateURL https://gist.github.com/raw/a539c1905608b253fcb6/CustomizeHelpMenu.user.js
// @downloadURL https://gist.github.com/raw/a539c1905608b253fcb6/CustomizeHelpMenu.user.js
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
/**
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Icons from https://www.iconfinder.com/
*
* Kudos to Brock Adams and all his GM answers http://stackoverflow.com/tags/greasemonkey/topusers
*
* jQuery plugin Repeatable Fields by Rhyzz https://github.com/Rhyzz/repeatable-fields
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
var jqui_url = '//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js';
var sendLStorage = GM_getValue("helpSE_v1");
if( window.location.hash ) // prevents Ajax bug when URL has a hash
setTimeout(function(){ help_se_add_jquery( start_up ); }, 3000 );
else
help_se_add_jquery( start_up );
/**
* Save GM Storage
* http://stackoverflow.com/a/14255440/1287812
*/
window.addEventListener ("message", receiveSaveMessage, false);
function receiveSaveMessage ( event ) {
if ( ! event.data || ! event.data.post )
return; // -- not our data
var safeValue = JSON.stringify (event.data.post);
GM_setValue ("helpSE_v1", safeValue);
}
/**
* Our thing
*/
function start_up( localStore ) {
/**
* jQuery Repeatable Fields v1.1.4
* http://www.rhyzz.com/repeatable-fields.html
* Copyright (c) 2014 Rhyzz
* License MIT
*
* @require was not working on GM
*/
(function(e){e.fn.repeatable_fields=function(t){function i(t){e(r.wrapper,t).each(function(t,n){var s=this;var o=e(s).children(r.container);
e(o).children(r.template).hide().find(":input").each(function(){$(this).prop("disabled",true)});e(s).on("click",r.add,function(t){t.stopImmediatePropagation();
var n=e(e(o).children(r.template).clone().removeClass(r.template.replace(".",""))[0].outerHTML);$(n).find(":input").each(function(){jQuery(this).prop("disabled",false)});
if(typeof r.before_add==="function"){r.before_add(o)}var s=e(n).fadeIn().appendTo(o);if(typeof r.after_add==="function"){r.after_add(o,s)}i(s)});
e(s).on("click",r.remove,function(t){t.stopImmediatePropagation();var n=e(this).parents(r.row).first();if(typeof r.before_remove==="function"){r.before_remove(o,n)}n.fadeOut(150, function() { $(this).remove(); });
if(typeof r.after_remove==="function"){r.after_remove(o)}});if(r.is_sortable===true&&typeof e.ui!=="undefined"&&typeof e.ui.sortable!=="undefined"){
var u=r.sortable_options!==null?r.sortable_options:{};u.handle=r.move;e(s).find(r.container).sortable(u)}})}function s(t,n){
var i=e(t).children(r.row).filter(function(){return!$(this).hasClass(r.template.replace(".",""))}).length;e("*",n).each(function(){
e.each(this.attributes,function(e,t){this.value=this.value.replace(/{{row-count-placeholder}}/,i-1)})})}var n={wrapper:".wrapper",container:".container",
row:".row",add:".add",remove:".remove",move:".move",template:".template",is_sortable:true,before_add:null,after_add:s,before_remove:null,
after_remove:null,sortable_options:null};var r=e.extend(n,t);i(this)}})($)
/**
* Init some vars
*/
var $userMenu,
$setBlankMenu,
$removeHelpCenter,
// Repeatable fields HTML and CSS base at http://jsfiddle.net/brasofilo/eLo13rk3/
repeater_table = '\
<div id="the-settings-page">\
<button id="close-modal" class="edit-count unread-count" title="close settings (without saving, changes are not lost if page not refreshed)">close</button>\
<br />\
<div class="repeat">\
<table id="the-table" class="wrapper">\
<thead>\
<tr>\
<td class="w10" colspan="2">\
<div class="add"><img src="http://i.stack.imgur.com/NXQWY.png" class="icon-img" title="add item" /></div>\
</td>\
<td class="w10" colspan="2">\
<div class="save"><img src="http://i.stack.imgur.com/NgmLj.png" class="icon-img" title="save settings" /></div>\
</td>\
</tr>\
</thead>\
<tbody class="container">\
<tr class="template row">\
<td class="w5">\
<span class="move"><img src="http://i.stack.imgur.com/DmPYx.png" class="icon-img" title="move item" /></span>\
</td>\
<td class="w30">\
<input type="text" placeholder="Menu name" name="a-name[]" />\
</td>\
<td class="w60">\
<input type="text" placeholder="URL [ profile links contain only ?tab=etc ]" name="an-url[]" />\
</td>\
<td class="w5 w5r">\
<span class="remove"><img src="http://i.stack.imgur.com/a8KLT.png" class="icon-img" title="remove item" /></span>\
</td>\
</tr>\
</tbody>\
</table>\
</div>\
</div>\
',
remove_items = [ /* items to remove */
'.topbar-dialog.help-dialog ul li:nth-of-type(3)',
'.topbar-dialog.help-dialog ul li:nth-of-type(1)'
];
remove_meta = [
'.topbar-dialog.help-dialog ul li:nth-of-type(4)',
'.topbar-dialog.help-dialog ul li:nth-of-type(2)',
'.topbar-dialog.help-dialog ul li:nth-of-type(1)'
],
defaults = {
'help_blank': false,
'remove_help': false,
'menu': [
{ 'name': 'Your menu!', 'url': 'http://stackapps.com/q/4921/10590' },
{ 'name': 'Your favorites', 'url': '?tab=favorites&sort=added' },
{ 'name': 'Users by rep this week', 'url': 'users?tab=Reputation&filter=week' },
]
};
/**
* Get URL query strings
* http://stackoverflow.com/a/901144/1287812
*/
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? false : decodeURIComponent(results[1].replace(/\+/g, " "));
}
/**
* Read options or set defaults
*/
var setup_local_storage = function() {
if ( localStore === undefined ) {
$userMenu = defaults.menu;
$setBlankMenu = defaults.help_blank;
$removeHelpCenter = defaults.remove_help;
}
else {
$userMenu = localStore.menu;
$setBlankMenu = localStore.help_blank;
$removeHelpCenter = localStore.remove_help;
}
/* Change config using URL params */
if( ( setBlank = getParameterByName('help-blank') ) !== false ) {
if( 'yes' === setBlank ) {
$setBlankMenu = true;
}
else {
$setBlankMenu = false;
}
window.postMessage ( {'post':{ 'help_blank':$setBlankMenu, 'remove_help': $removeHelpCenter, 'menu':$userMenu}}, "*" );
}
/* idem */
if( ( removeHC = getParameterByName('help-remove') ) !== false ) {
if( 'yes' === removeHC ) {
$removeHelpCenter = true;
}
else {
$removeHelpCenter = false;
}
window.postMessage ( {'post':{ 'help_blank':$setBlankMenu, 'remove_help': $removeHelpCenter, 'menu':$userMenu}}, "*" );
}
};
/**
* Localstorage for saving options
*/
var update_storage = function( values ) {
$userMenu = values;
window.postMessage ( {'post':{ 'help_blank':$setBlankMenu, 'remove_help': $removeHelpCenter, 'menu':values}}, "*" );
rebuild_menu();
};
/**
* Remove menu help items
*/
var remove_modify_items = function() {
if( $removeHelpCenter ) {
$('.topbar-dialog.help-dialog ul li').remove();
}
else {
if ( StackExchange.options.site.isMetaSite && StackExchange.options.site.isChildMeta ) { // Meta.All
$( remove_meta.join(',') ).remove();
}
else { // Main sites & Meta.SE
$( remove_items.join(',') ).remove();
}
}
if( $setBlankMenu )
$('.topbar-dialog.help-dialog ul li a[href="/help"]').attr('target','_blank');
}
/**
* Bonus button: back to top
* http://www.developerdrive.com/?p=4321
*/
var create_back2top = function() {
$('body').append('<a href="#" class="back-to-top">Back to Top</a>');
var offset = 420;
var duration = 150;
$(window).scroll(function() {
if ($(this).scrollTop() > offset) {
$('.back-to-top').fadeIn(duration);
} else {
$('.back-to-top').fadeOut(duration);
}
});
$('.back-to-top').click(function(event) {
event.preventDefault();
$('html, body').animate({scrollTop: 0}, duration);
return false;
});
};
/**
* After saving settings
*/
var rebuild_menu = function() {
var i=0, $lis = $('div.topbar-dialog.help-dialog.js-help-dialog div.modal-content ul li');
for( i; i < ( $lis.length - 2 ) ; i++ ) {
$lis[i].remove();
}
create_menu();
};
/**
* At startup and after saving
*/
var create_menu = function() {
var reverseClone = $userMenu.slice(0).reverse();
$.each( reverseClone, function(index, value) {
var url = value.url,
is_tab = ( value.url.indexOf('?tab') === 0 ),
zero_url = ( value.url.length === 0 ),
the_link;
if( is_tab )
url = StackExchange.options.user.profileUrl + value.url;
if( StackExchange.options.user.isAnonymous && is_tab )
the_link = '<a style="opacity:.5; cursor:default;">' + value.name + '</a>';
else if( zero_url )
the_link = '<a>' + value.name + '</a>';
else
the_link = '<a href="' + url + '">' + value.name + '</a>';
$('.topbar-dialog.help-dialog ul').prepend('<li>' + the_link + '</li>');
});
};
/**
* Creates icon at topbar
*/
var create_help_menu = function(){
$('.links-container a.icon-help.js-help-button')
.html('<img src="http://i.stack.imgur.com/LCLqA.png" width="16" height="16" />')
.attr('title', 'favorites')
.attr('id','halp-btn')
.addClass('gm-active');
$('.topbar-dialog.help-dialog').css('width','135px');
/* Add items to menu */
create_menu();
if( StackExchange.options.user.isAnonymous === undefined )
$('.topbar-dialog.help-dialog ul').append('<li><div class="help-div"><a href="#" id="help-settings">{ settings }</a></div></li>');
};
/**
* Creates modal settings screen and repeatable fields
*/
var create_settings_modal = function(){
$( repeater_table ).insertBefore( "body div.container" );
$(document).on('click', '#help-settings, #close-modal', function(e){
e.preventDefault();
var to_toggle = 'body div.container, .topbar-wrapper .network-items, .topbar-wrapper .search-container, #halp-btn, .topbar-wrapper .links-container a[href="/review"], #footer, #the-settings-page';
$(to_toggle).fadeToggle('slow', function(){
if( $('#the-settings-page').is(':visible') )
$('#the-settings-page').css('display','inline-block');
});
});
$('.repeat').each(function () {
$(this).repeatable_fields({
wrapper: 'table',
container: 'tbody',
row: 'tr',
cell: 'td',
add: '.add',
remove: '.remove',
move: '.move',
template: '.template',
before_add: null,
after_add: null,
before_remove: null,
after_remove: null,
sortable_options: {
placeholder: "template",
//forcePlaceholderSize: true,
opacity: 0.5
},
});
});
$('.save').click(function (e) {
var _all = new Array();
$('#the-table tbody tr:gt(0)').each(function () {
_all.push({
'name': $(this).find('td:nth-of-type(2) input').val(),
'url': $(this).find('td:nth-of-type(3) input').val()
});
});
update_storage(_all);
$('#close-modal').click();
});
$.each( $userMenu, function(index, value) {
var button = $('#the-table tbody tr.template.row').clone().appendTo('#the-table tbody').removeClass('template').show();
$(button).find('td.w30 input').val(value.name).prop("disabled", false);
$(button).find('td.w60 input').val(value.url).prop("disabled", false);
});
};
create_back2top();
setup_local_storage();
remove_modify_items();
create_help_menu();
create_settings_modal();
}
/**
* Inject jQuery UI and call init function
*/
function help_se_add_jquery( callback ){
var script = document.createElement( 'script' );
script.setAttribute( 'src', jqui_url );
script.addEventListener( 'load', function()
{
var script = document.createElement('script');
script.textContent = '(' + callback.toString() + ')(' + sendLStorage + ');';
document.body.appendChild( script );
}, false );
document.body.appendChild( script );
}
/**
* CSS
* http://stackapps.com/a/4800/10590
*/
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css
head.appendChild(style);
}
addGlobalStyle (function(){/*
html,body { height: 100%; margin: 0; padding: 0; }
#the-settings-page { padding-top: 1em; background-color: #DEDADA; width:100%; height:100%; position:absolute; top:10; left:0; z-index:999; display:none; overflow:auto }
#help-settings { float: right; color: #8C8C8C; font-size:.5em }
#the-table {
border-collapse: collapse;
-webkit-box-shadow: 9px 9px 12px 0px rgba(50, 50, 50, 0.2);
-moz-box-shadow: 9px 9px 12px 0px rgba(50, 50, 50, 0.2);
box-shadow: 9px 9px 12px 0px rgba(50, 50, 50, 0.2);
}
#the-table thead td:nth-of-type(1) { text-align: left; }
#the-table thead td:nth-of-type(2) { text-align: right; }
#the-table td, #the-table tr { background-color: #ccc; padding:2px; margin:0; text-align:center; vertical-align:middle; }
#the-table .w5 { width: 5%; }
#the-table .w5r { opacity: .15;}
#the-table .w10 { width: 10% }
#the-table .w30 { width: 30% }
#the-table .w60 { width: 65% }
#the-table .move img { width: 100%; max-width: 20px; -webkit-filter: invert(100%); opacity: .25; }
#the-table input { padding: 3px; font-size: 14px; margin: 0; width: 95%; border: 1px solid #E4E4E4; }
div.repeat { width:60%;margin:1em auto; padding-bottom:3.5em }
#close-modal { float: right;margin-right: 20%; }
.back-to-top {
position: fixed; bottom: 2em; right: -3px; text-decoration: none;
color: #000000; background-color: rgba(235, 235, 235, 0.80); font-size: 12px;
padding: .5em; display: none; border-radius: 5px
}
.back-to-top:hover { background-color: rgba(135, 135, 135, 0.50); }
.links-container a.icon-help.js-help-button.gm-active { -webkit-filter: invert(20%);padding-right: 4px; }
.help-div { width: 100%; height: 100%; text-align: right; float: right; }
.add, .save, #close-modal {cursor:pointer}
.move {cursor:move}
.add { position: relative; top: 5px; left: 3px; }
.save { position: relative; top: 5px; right: 5px; }
.remove {cursor:crosshair; }
.topbar-dialog.help-dialog ul li span.item-summary { display: none; }
.topbar-dialog .modal-content { max-height: 100% }
*/
}.toString().slice(14,-3));
// ==UserScript==
// @name Disable Enter key on comments on Stack Exchange
// @namespace http://stackapps.com/a/4910/10590
// @version 1.1
// @description Disable Enter key on comments on Stack Exchange
// @homepage http://stackapps.com/q/2061
// @icon http://i.stack.imgur.com/6xzO1.png
// @match *://*.askubuntu.com/questions*
// @match *://*.mathoverflow.net/questions*
// @match *://*.serverfault.com/questions*
// @match *://*.stackapps.com/questions*
// @match *://*.stackexchange.com/questions*
// @match *://*.stackoverflow.com/questions*
// @match *://*.superuser.com/questions*
// ==/UserScript==
function inject() {
for ( var i = 0; i < arguments.length; ++i ) {
if ( typeof(arguments[i]) == 'function' ) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.textContent = '(' + arguments[i].toString() + ')(jQuery)';
document.body.appendChild(script);
}
}
}
inject(function ($) {
setTimeout( function() {
// Run only on individual posts
if( ( StackExchange.options.routeName.indexOf('Questions/Show') === -1 ) )
return;
$(document).delegate(".comments-link, .comment-edit", "click", function(e) {
var events = $(this).closest("td").find("textarea[name=comment]").data("events");
var makeShift = { handler: function(e) {
if( e.keyCode === 13 && e.shiftKey )
e.shiftKey = false;
else
e.shiftKey = true;
} };
try {
events.keyup.splice(0, 0, makeShift);
events.keypress.splice(0, 0, makeShift);
}
catch (evt) {
console.error('Disable Enter key on comments on Stack Exchange failed to load');
}
});
}, 500 );
});
// ==UserScript==
// @name Expand code blocks on Stack Exchange sites
// @namespace stackapps
// @version 1.1
// @description Click a code block with scroll bars and it automatically expands
// @icon http://i.stack.imgur.com/EmeVj.png
// @match *://*.serverfault.com/questions*
// @match *://*.serverfault.com/review*
// @match *://*.stackapps.com/questions*
// @match *://*.stackapps.com/review*
// @match *://*.stackoverflow.com/questions*
// @match *://*.stackoverflow.com/review*
// @match *://*.superuser.com/questions*
// @match *://*.superuser.com/review*
// @match *://*.wordpress.stackexchange.com/questions*
// @match *://*.wordpress.stackexchange.com/review*
// @grant none
// @author Alconja
// @contributor brasofilo
// ==/UserScript==
/**
* Adapted from http://stackoverflow.com/a/8971716/1287812
*/
$.fn.has_scrollbar = function() {
var divnode = this.get(0);
if(divnode.scrollHeight > divnode.clientHeight || divnode.scrollWidth > divnode.clientWidth )
return true;
};
/**
* Expand <pre>
*/
function expando( pre ) {
var maxHeight = null;
pre.css("z-index", 1000);
var code = pre.children("code");
if (maxHeight === null) {
maxHeight = pre.css("max-height");
if( pre.attr('max-height') === undefined )
pre.attr('max-height',maxHeight);
}
var oldWidth = pre.width();
var codeWidth = Math.max(code.width(), oldWidth);
var maxWidth = $(window).width() - 20;
var width = Math.min(maxWidth, codeWidth);
var maxLeft = (-1 * pre.offset().left) + 5;
var idealLeft = (oldWidth - width) / 4.5;
var left = Math.max(maxLeft, idealLeft);
pre.css({width: width + "px", position: "relative", left: left + "px", maxHeight: "inherit"});
if (width < codeWidth) { //last ditch attempt to fit...
var pc = 100 * width / codeWidth;
pc = Math.max(pc, 70); //any smaller & you can't read it...
pre.css("font-size", pc + "%");
}
}
/**
* Contract <pre>
*/
function contracto( pre ) {
pre.css({width: "auto", position: "static", maxHeight: pre.attr('max-height'), fontSize: "100%"});
}
/**
* Check page and add arrows
*/
function addArrows() {
var count_pre = 1;
$('pre').each(function(){
if( $(this).has_scrollbar() ) {
$(this).before('<span class="expander-arrow-small-hide" id="expander-id-' + count_pre + '" style="float:right"></span>');
$('#expander-id-'+count_pre).click(function(){
if( $(this).hasClass('expander-arrow-small-hide') ){
expando( $(this).next() );
if( location.host.indexOf('wordpress.stackexchange') > -1 ) {
$('#content').css('overflow','visible');
}
$(this).removeClass('expander-arrow-small-hide').addClass('expander-arrow-small-show');
}
else {
if( location.host.indexOf('wordpress.stackexchange') > -1 ) {
$('#content').css('overflow','auto');
}
contracto( $(this).next() );
$(this).removeClass('expander-arrow-small-show').addClass('expander-arrow-small-hide');
}
}).css('cursor','pointer');
count_pre++;
}
});
}
/**
* Run when reviewing
*/
if( StackExchange.options.routeName === 'Review/Task' ) {
$(document).ajaxComplete(function( event, xhr, settings ){
if( settings.url.indexOf('review/task-reviewed') !== -1 || settings.url.indexOf('review/next-task') !== -1 ) {
addArrows();
}
});
}
/**
* Run when viewing a question
*/
if( StackExchange.options.routeName == "Questions/Show" ) {
// Only SO has this property as visible, which is needed to fully expand the blocks
if( location.host.indexOf('stackoverflow.com') === -1 && location.host.indexOf('wordpress.stackexchange') === -1 ) {
if( $('#content').css('overflow') === 'auto' )
$('#content').css('overflow','visible');
}
addArrows();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment