Untitled diff

Created Diff never expires
9 removals
Words removed11
Total words1735
Words removed (%)0.63
522 lines
6 additions
Words added19
Total words1743
Words added (%)1.09
520 lines
(function(sox, $, undefined) {
(function(sox, $, undefined) {
'use strict';
'use strict';


sox.features = { //SOX functions must go in here
sox.features = { //SOX functions must go in here
moveBounty: function() {
moveBounty: function() {
// Description: For moving bounty to the top
// Description: For moving bounty to the top


$('.bounty-notification').insertAfter('.question .fw-wrap'); //$('.bounty-notification').length condition isn't necessary; this line will run only if the element exists
$('.bounty-notification').insertAfter('.question .fw-wrap'); //$('.bounty-notification').length condition isn't necessary; this line will run only if the element exists
$('.bounty-link.bounty').closest('ul').insertAfter('.question .fw-wrap');
$('.bounty-link.bounty').closest('ul').insertAfter('.question .fw-wrap');
},
},


dragBounty: function() {
dragBounty: function() {
// Description: Makes the bounty window draggable
// Description: Makes the bounty window draggable


sox.helpers.observe('#start-bounty-popup', function() {
sox.helpers.observe('#start-bounty-popup', function() {
$('#start-bounty-popup').draggable({
$('#start-bounty-popup').draggable({
drag: function() {
drag: function() {
$(this).css({
$(this).css({
'width': 'auto',
'width': 'auto',
'height': 'auto'
'height': 'auto'
});
});
}
}
}).css('cursor', 'move');
}).css('cursor', 'move');
});
});
},
},


renameChat: function() {
renameChat: function() {
// Description: Renames Chat tabs to prepend 'Chat' before the room name
// Description: Renames Chat tabs to prepend 'Chat' before the room name


if (sox.site.type == 'chat') {
if (sox.site.type == 'chat') {
var match = document.title.match(/^(\(\d*\*?\) )?(.* \| [^|]*)$/);
var match = document.title.match(/^(\(\d*\*?\) )?(.* \| [^|]*)$/);
document.title = (match[1] || '') + 'Chat - ' + match[2];
document.title = (match[1] || '') + 'Chat - ' + match[2];
}
}
},
},


markEmployees: function() {
markEmployees: function() {
// Description: Adds an Stack Overflow logo next to users that *ARE* a Stack Overflow Employee
// Description: Adds an Stack Overflow logo next to users that *ARE* a Stack Overflow Employee


function unique(list) {
function unique(list) {
//credit: GUFFA https://stackoverflow.com/questions/12551635/12551709#12551709
//credit: GUFFA https://stackoverflow.com/questions/12551635/12551709#12551709
var result = [];
var result = [];
$.each(list, function(i, e) {
$.each(list, function(i, e) {
if ($.inArray(e, result) == -1) result.push(e);
if ($.inArray(e, result) == -1) result.push(e);
});
});
return result;
return result;
}
}


var $links = $('.comment a, .deleted-answer-info a, .employee-name a, .user-details a').filter('a[href^="/users/"]');
var $links = $('.comment a, .deleted-answer-info a, .employee-name a, .user-details a').filter('a[href^="/users/"]');
var ids = [];
var ids = [];


$links.each(function() {
$links.each(function() {
var href = $(this).attr('href'),
var href = $(this).attr('href'),
id = href.split('/')[2];
id = href.split('/')[2];
ids.push(id);
ids.push(id);
});
});


ids = unique(ids);
ids = unique(ids);
sox.debug('markEmployees user IDs', ids);
sox.debug('markEmployees user IDs', ids);


var url = 'https://api.stackexchange.com/2.2/users/{ids}?pagesize=100&site={site}&key={key}&access_token={access_token}'
var url = 'https://api.stackexchange.com/2.2/users/{ids}?pagesize=100&site={site}&key={key}&access_token={access_token}'
.replace('{ids}', ids.join(';'))
.replace('{ids}', ids.join(';'))
.replace('{site}', sox.site.currentApiParameter)
.replace('{site}', sox.site.currentApiParameter)
.replace('{key}', sox.info.apikey)
.replace('{key}', sox.info.apikey)
.replace('{access_token}', sox.settings.accessToken);
.replace('{access_token}', sox.settings.accessToken);


$.ajax({
$.ajax({
url: url,
url: url,
success: function(data) {
success: function(data) {
sox.debug('markEmployees returned data', data);
sox.debug('markEmployees returned data', data);
for (var i = 0; i < data.items.length; i++) {
for (var i = 0; i < data.items.length; i++) {
var userId = data.items[i].user_id,
var userId = data.items[i].user_id,
isEmployee = data.items[i].is_employee;
isEmployee = data.items[i].is_employee;


if (isEmployee) {
if (isEmployee) {
$links.filter('a[href^="/users/' + userId + '/"]').after('<span class="fab fa-stack-overflow" title="employee" style="padding: 0 5px; color: ' + $('.mod-flair').css('color') + '"></span>');
$links.filter('a[href^="/users/' + userId + '/"]').after('<span class="fab fa-stack-overflow" title="employee" style="padding: 0 5px; color: ' + $('.mod-flair').css('color') + '"></span>');
}
}
}
}
}
}
});
});
},
},


copyCommentsLink: function() {
copyCommentsLink: function() {
// Description: Adds the 'show x more comments' link before the commnents
// Description: Adds the 'show x more comments' link before the commnents
// Test on e.g. https://meta.stackexchange.com/questions/125439/


$('.js-show-link.comments-link').each(function() {
$('.js-show-link.comments-link').each(function() {
if (!$(this).parent().prev().find('.comment-text').length) return; //https://github.com/soscripted/sox/issues/196
if (!$(this).parent().prev().find('.comment-text').length) return; //https://github.com/soscripted/sox/issues/196


var $btnToAdd = $(this).clone();
var $btnToAdd = $(this).clone();

$btnToAdd.click(function() {
$btnToAdd.on('click', function(e) {
$(this).remove();
e.preventDefault();
$(this).hide();
});
});


$(this).parent().parent().prepend($btnToAdd);
$(this).parent().parent().prepend($btnToAdd);


$(this).click(function() {
$(this).click(function() {
$btnToAdd.hide();
$btnToAdd.remove();
});
});
});
});


$(document).on('click', '.js-add-link', function() { //https://github.com/soscripted/sox/issues/239
$(document).on('click', '.js-add-link', function() { //https://github.com/soscripted/sox/issues/239
var commentParent = ($(this).parents('.answer').length ? '.answer' : '.question');
var commentParent = ($(this).parents('.answer').length ? '.answer' : '.question');
$(this).closest(commentParent).find('.js-show-link.comments-link').hide();
$(this).closest(commentParent).find('.js-show-link.comments-link').hide();
});
});
},
},


fixedTopbar: function(settings) {
fixedTopbar: function(settings) {
// Description: For making the topbar fixed (always stay at top of screen)
// Description: For making the topbar fixed (always stay at top of screen)
// Modified by shu8
// Modified by shu8


//Add class to page for topbar, calculated for every page for different sites.
//Add class to page for topbar, calculated for every page for different sites.
//If the Area 51 popup closes or doesn't exist, $('#notify-table').height() = 0
//If the Area 51 popup closes or doesn't exist, $('#notify-table').height() = 0
var $topbar = sox.NEW_TOPBAR ? $('.top-bar') : $('.topbar');
var $topbar = sox.NEW_TOPBAR ? $('.top-bar') : $('.topbar');
var paddingToAdd = $('#notify-table').height() + $topbar.height();
var paddingToAdd = $('#notify-table').height() + $topbar.height();


if ($('.topbar').length) {
if ($('.topbar').length) {
GM_addStyle('.fixed-topbar-sox { padding-top: ' + paddingToAdd + 'px !important}');
GM_addStyle('.fixed-topbar-sox { padding-top: ' + paddingToAdd + 'px !important}');
$topbar.css('margin-top', -$topbar.height() + 'px');
$topbar.css('margin-top', -$topbar.height() + 'px');
}
}


function adjust() { //http://stackoverflow.com/a/31408076/3541881 genius! :)
function adjust() { //http://stackoverflow.com/a/31408076/3541881 genius! :)
setTimeout(function() {
setTimeout(function() {
sox.debug('fixedtopbar adjust function running');
sox.debug('fixedtopbar adjust function running');
var id;
var id;
if (location.href.indexOf('#comment') > -1) {
if (location.href.indexOf('#comment') > -1) {
id = window.location.hash.match(/^#comment(\d+)_/)[1];
id = window.location.hash.match(/^#comment(\d+)_/)[1];
sox.debug('fixedtopbar comment in hash and getBoundingClientRect', $('#comment-' + id)[0], $('#comment-' + id)[0].getBoundingClientRect());
sox.debug('fixedtopbar comment in hash and getBoundingClientRect', $('#comment-' + id)[0], $('#comment-' + id)[0].getBoundingClientRect());
if ($('#comment-' + id)[0].getBoundingClientRect().top < 30) {
if ($('#comment-' + id)[0].getBoundingClientRect().top < 30) {
window.scrollBy(0, -paddingToAdd);
window.scrollBy(0, -paddingToAdd);
sox.debug('fixedtopbar adjusting');
sox.debug('fixedtopbar adjusting');
}
}
} else {
} else {
id = window.location.hash.match(/^#(\d+)/)[1];
id = window.location.hash.match(/^#(\d+)/)[1];
sox.debug('fixedtopbar answer in hash and getBoundingClientRect', $('#answer-' + id)[0], $('#answer-' + id)[0].getBoundingClientRect());
sox.debug('fixedtopbar answer in hash and getBoundingClientRect', $('#answer-' + id)[0], $('#answer-' + id)[0].getBoundingClientRect());
if ($('#answer-' + id)[0].getBoundingClientRect().top < 30) {
if ($('#answer-' + id)[0].getBoundingClientRect().top < 30) {
window.scrollBy(0, -paddingToAdd);
window.scrollBy(0, -paddingToAdd);
sox.debug('fixedtopbar adjusting');
sox.debug('fixedtopbar adjusting');
}
}
}
}
}, 10);
}, 10);
}
}


if (sox.site.type == 'chat') { //For some reason, chats don't need any modification to the body
if (sox.site.type == 'chat') { //For some reason, chats don't need any modification to the body
$topbar.css({
$topbar.css({
'position': 'fixed',
'position': 'fixed',
'z-index': '900',
'z-index': '900',
'margin-top': 0
'margin-top': 0
});
});


//https://github.com/soscripted/sox/issues/221
//https://github.com/soscripted/sox/issues/221
$('.notification').css('margin-top', paddingToAdd + 'px');
$('.notification').css('margin-top', paddingToAdd + 'px');
sox.helpers.observe('.notification', function() {
sox.helpers.observe('.notification', function() {
$('.notification').css('margin-top', paddingToAdd + 'px');
$('.notification').css('margin-top', paddingToAdd + 'px');
});
});
} else {
} else {
if (sox.location.on('askubuntu.com')) {
if (sox.location.on('askubuntu.com')) {
if (!settings.enableOnAskUbuntu) return; //Disable on Ask Ubuntu if user said so
if (!settings.enableOnAskUbuntu) return; //Disable on Ask Ubuntu if user said so
$('#custom-header').css('visibility', 'hidden'); //Preserves spacing, unlike .remove()
$('#custom-header').css('visibility', 'hidden'); //Preserves spacing, unlike .remove()
$topbar.css('width', '100%');
$topbar.css('width', '100%');
$('.topbar-wrapper').css('width', '1060px');
$('.topbar-wrapper').css('width', '1060px');
}
}


$('body').addClass('fixed-topbar-sox');
$('body').addClass('fixed-topbar-sox');


$topbar.css({
$topbar.css({
'position': 'fixed',
'position': 'fixed',
'z-index': '900'
'z-index': '900'
});
});


//Area 51 popup:
//Area 51 popup:
$('#notify-table').css({
$('#notify-table').css({
'position': 'fixed',
'position': 'fixed',
'z-index': '900',
'z-index': '900',
'margin-top': -paddingToAdd + 'px'
'margin-top': -paddingToAdd + 'px'
});
});


//https://github.com/soscripted/sox/issues/74
//https://github.com/soscripted/sox/issues/74
if (location.href.indexOf('#') > -1) adjust();
if (location.href.indexOf('#') > -1) adjust();
$(window).bind('hashchange', adjust);
$(window).bind('hashchange', adjust);
if (typeof MathJax !== "undefined") MathJax.Hub.Queue(adjust);
if (typeof MathJax !== "undefined") MathJax.Hub.Queue(adjust);


sox.helpers.observe('#notify-container,#notify--1', function() { //Area51: https://github.com/soscripted/sox/issues/152#issuecomment-267885889
sox.helpers.observe('#notify-container,#notify--1', function() { //Area51: https://github.com/soscripted/sox/issues/152#issuecomment-267885889
if (!$('#notify--1').length) $('body').attr('style', 'padding-top: ' + $topbar.height() + 'px !important'); //.css() doesn't work...?
if (!$('#notify--1').length) $('body').attr('style', 'padding-top: ' + $topbar.height() + 'px !important'); //.css() doesn't work...?
});
});


//Placing the following in this if statement should hopefully prevent a fixed review bar in Ask Ubuntu. However I can't test this on Stack Overflow's or Ask Ubuntu's review:
//Placing the following in this if statement should hopefully prevent a fixed review bar in Ask Ubuntu. However I can't test this on Stack Overflow's or Ask Ubuntu's review:
if (sox.location.on('/review/')) { //https://github.com/soscripted/sox/issues/180
if (sox.location.on('/review/')) { //https://github.com/soscripted/sox/issues/180
sox.helpers.observe('.review-bar', function() {
sox.helpers.observe('.review-bar', function() {
if ($('.review-bar').css('position') === 'fixed') {
if ($('.review-bar').css('position') === 'fixed') {
$('.review-bar').addClass('fixed-topbar-sox');
$('.review-bar').addClass('fixed-topbar-sox');
$('.review-bar').css('margin-top', paddingToAdd + 'px');
$('.review-bar').css('margin-top', paddingToAdd + 'px');
} else {
} else {
$('.review-bar').removeClass('fixed-topbar-sox');
$('.review-bar').removeClass('fixed-topbar-sox');
}
}
});
});
}
}
}
}
},
},


highlightQuestions: function() {
highlightQuestions: function() {
// Description: For highlighting only the tags of favorite questions
// Description: For highlighting only the tags of favorite questions


function highlight() {
function highlight() {
$('.tagged-interesting').removeClass('tagged-interesting sox-tagged-interesting').addClass('sox-tagged-interesting');
$('.tagged-interesting').removeClass('tagged-interesting sox-tagged-interesting').addClass('sox-tagged-interesting');
}
}


var color;
var color;
if (sox.location.on('superuser.com')) { //superuser
if (sox.location.on('superuser.com')) { //superuser
color = '#00a1c9';
color = '#00a1c9';
} else if (sox.location.on('stackoverflow.com')) { //stackoverflow
} else if (sox.location.on('stackoverflow.com')) { //stackoverflow
color = '#f69c55';
color = '#f69c55';
} else if (sox.location.on('serverfault.com')) {
} else if (sox.location.on('serverfault.com')) {
color = '#EA292C';
color = '#EA292C';
} else { //for all other sites
} else { //for all other sites
color = $('.post-tag').css('color');
color = $('.post-tag').css('color');
}
}


$('<style type="text/css">.sox-tagged-interesting:before{background: ' + color + ';}</style>').appendTo('head');
$('<style type="text/css">.sox-tagged-interesting:before{background: ' + color + ';}</style>').appendTo('head');


highlight();
highlight();


if ($('.question-summary').length) {
if ($('.question-summary').length) {
var target = document.body;
var target = document.body;
// TODO use new observer helper
// TODO use new observer helper


new MutationObserver(function(mutations) {
new MutationObserver(function(mutations) {
$.each(mutations, function(i, mutation) {
$.each(mutations, function(i, mutation) {
if (mutation.attributeName == 'class') {
if (mutation.attributeName == 'class') {
highlight();
highlight();
return false; //no point looping through everything; if *something* has changed, assume everything has
return false; //no point looping through everything; if *something* has changed, assume everything has
}
}
});
});
}).observe(target, {
}).observe(target, {
"attributes": true,
"attributes": true,
"childList": true,
"childList": true,
"characterData": true,
"characterData": true,
"subtree": true
"subtree": true
});
});
}
}
},
},


displayName: function() {
displayName: function() {
// Description: For displaying username next to avatar on topbar
// Description: For displaying username next to avatar on topbar


var name = sox.user.name;
var name = sox.user.name;
var $span = $('<span/>', {
var $span = $('<span/>', {
class: 'reputation links-container',
class: 'reputation links-container',
style: $('.top-bar').css('background-color') == 'rgb(250, 250, 251)' ? 'color: #535a60; padding-right: 12px; font-size: 13px;' : 'color: white; padding-right: 12px; font-size: 13px;',
style: $('.top-bar').css('background-color') == 'rgb(250, 250, 251)' ? 'color: #535a60; padding-right: 12px; font-size: 13px;' : 'color: white; padding-right: 12px; font-size: 13px;',
title: name,
title: name,
text: name
text: name
});
});
$span.insertBefore('.gravatar-wrapper-24');
$span.insertBefore('.gravatar-wrapper-24');
},
},


colorAnswerer: function() {
colorAnswerer: function() {
// Description: For highlighting the names of answerers on comments
// Description: For highlighting the names of answerers on comments



function color() {
function color() {
var answererID;
var answererID;


$('.answercell').each(function(i, obj) {
$('.answercell').each(function(i, obj) {
answererID = +this.querySelector('.post-signature:nth-last-of-type(1) a[href^="/users"]').href.match(/\d+/)[0];
answererID = +this.querySelector('.post-signature:nth-last-of-type(1) a[href^="/users"]').href.match(/\d+/)[0];


$(this.nextElementSibling.querySelectorAll('.comment-user[href^="/users/' + answererID + '"]')).addClass('sox-answerer');
$(this.nextElementSibling.querySelectorAll('.comment-user[href^="/users/' + answererID + '"]')).addClass('sox-answerer');
});
});
}
}


color();
color();
$(document).on('sox-new-comment', color);
$(document).on('sox-new-comment', color);
},
},




kbdAndBullets: function() {
kbdAndBullets: function() {
// Description: For adding buttons to the markdown toolbar to surround selected test with KBD or convert selection into a markdown list
// Description: For adding buttons to the markdown toolbar to surround selected test with KBD or convert selection into a markdown list


function addBullets($node) {
function addBullets($node) {
var list = '- ' + $node.getSelection().text.split('\n').join('\n- ');
var list = '- ' + $node.getSelection().text.split('\n').join('\n- ');
$node.replaceSelectedText(list);
$node.replaceSelectedText(list);
StackExchange.MarkdownEditor.refreshAllPreviews();
StackExchange.MarkdownEditor.refreshAllPreviews();
}
}


function addKbd($node) {
function addKbd($node) {
$node.surroundSelectedText("<kbd>", "</kbd>");
$node.surroundSelectedText("<kbd>", "</kbd>");
var surroundedText = $node.getSelection(),
var surroundedText = $node.getSelection(),
trimmed = surroundedText.text.trim();
trimmed = surroundedText.text.trim();


if ($node.getSelection().text !== '') {
if ($node.getSelection().text !== '') {
//https://github.com/soscripted/sox/issues/240
//https://github.com/soscripted/sox/issues/240
//https://github.com/soscripted/sox/issues/189
//https://github.com/soscripted/sox/issues/189
//if no trimming occured, then we have to add another space
//if no trimming occured, then we have to add another space
$node.replaceSelectedText(trimmed);
$node.replaceSelectedText(trimmed);
$node.insertText(' ', surroundedText.end + (trimmed == surroundedText.text ? 6 : 5), 'collapseToEnd'); //add a space after the `</kbd>`
$node.insertText(' ', surroundedText.end + (trimmed == surroundedText.text ? 6 : 5), 'collapseToEnd'); //add a space after the `</kbd>`
}
}


StackExchange.MarkdownEditor.refreshAllPreviews();
StackExchange.MarkdownEditor.refreshAllPreviews();
}
}


function getTextarea(button) {
function getTextarea(button) {
// li -> ul -> #wmd-button-bar -> .wmd-container
// li -> ul -> #wmd-button-bar -> .wmd-container
return button.parentNode.parentNode.parentNode.querySelector("textarea");
return button.parentNode.parentNode.parentNode.querySelector("textarea");
}
}


function loopAndAddHandlers() {
function loopAndAddHandlers() {
var kbdBtn = '<li class="wmd-button" id="wmd-kbd-button" title="surround selected text with <kbd> tags"><span style="background-image:none;">kbd</span></li>',
var kbdBtn = '<li class="wmd-button" id="wmd-kbd-button" title="surround selected text with <kbd> tags"><span style="background-image:none;">kbd</span></li>',
listBtn = '<li class="wmd-button" id="wmd-bullet-button" title="add dashes (\'-\') before every line to make a bullet list"><span style="background-image:none;">&#x25cf;</span></li>';
listBtn = '<li class="wmd-button" id="wmd-bullet-button" title="add dashes (\'-\') before every line to make a bullet list"><span style="background-image:none;">&#x25cf;</span></li>';


$('[id^="wmd-redo-button"]').each(function() {
$('[id^="wmd-redo-button"]').each(function() {
if (!$(this).parent().find('#wmd-kbd-button').length) $(this).after(kbdBtn + listBtn);
if (!$(this).parent().find('#wmd-kbd-button').length) $(this).after(kbdBtn + listBtn);
});
});
}
}


$(document).on('sox-edit-window', loopAndAddHandlers);
$(document).on('sox-edit-window', loopAndAddHandlers);


loopAndAddHandlers();
loopAndAddHandlers();


document.addEventListener('keydown', function(event) {
document.addEventListener('keydown', function(event) {
var kC = event.keyCode,
var kC = event.keyCode,
target = event.target;
target = event.target;


if (target && /^wmd-input/.test(target.id) && event.altKey) {
if (target && /^wmd-input/.test(target.id) && event.altKey) {
if (kC === 76) addBullets($(target)); // l
if (kC === 76) addBullets($(target)); // l
else if (kC === 75) addKbd($(target)); // k
else if (kC === 75) addKbd($(target)); // k
}
}
});
});


$(document).on('click', '#wmd-kbd-button, #wmd-bullet-button', function(event) {
$(document).on('click', '#wmd-kbd-button, #wmd-bullet-button', function(event) {
var id = this.id,
var id = this.id,
textarea = $(getTextarea(this));
textarea = $(getTextarea(this));


if (id === "wmd-kbd-button") addKbd(textarea);
if (id === "wmd-kbd-button") addKbd(textarea);
else addBullets(textarea);
else addBullets(textarea);
});
});
},
},


editComment: function() {
editComment: function() {
// Description: For adding checkboxes when editing to add pre-defined edit reasons
// Description: For adding checkboxes when editing to add pre-defined edit reasons


function addCheckboxes() {
function addCheckboxes() {
var editCommentField = $('[id^="edit-comment"]');
var editCommentField = $('[id^="edit-comment"]');
if (!editCommentField.length) return; //https://github.com/soscripted/sox/issues/246
if (!editCommentField.length) return; //https://github.com/soscripted/sox/issues/246


function toLocaleSentenceCase(str) {
function toLocaleSentenceCase(str) {
return str.substr(0, 1).toLocaleUpperCase() + str.substr(1);
return str.substr(0, 1).toLocaleUpperCase() + str.substr(1);
}
}
$('#reasons').remove(); //remove the div containing everything, we're going to add/remove stuff now:
$('#reasons').remove(); //remove the div containing everything, we're going to add/remove stuff now:
if (/\/edit/.test(window.location.href) || $('[class^="inline-editor"]').length || $('.edit-comment').length) {
if (/\/edit/.test(window.location.href) || $('[class^="inline-editor"]').length || $('.edit-comment').length) {
$('.form-submit').before('<div id="reasons" style="float:left;clear:both"></div>');
$('.form-submit').before('<div id="reasons" style="float:left;clear:both"></div>');


$.each(JSON.parse(GM_getValue('editReasons')), function(i, obj) {
$.each(JSON.parse(GM_getValue('editReasons')), function(i, obj) {
$('#reasons').append('<label><input type="checkbox" value="' + this[1] + '"</input>' + this[0] + '</label>&nbsp;');
$('#reasons').append('<label><input type="checkbox" value="' + this[1] + '"</input>' + this[0] + '</label>&nbsp;');
});
});


$('#reasons input[type="checkbox"]').css('vertical-align', '-2px');
$('#reasons input[type="checkbox"]').css('vertical-align', '-2px');


$('#reasons label').hover(function() {
$('#reasons label').hover(function() {
$(this).css({ //on hover
$(this).css({ //on hover
'background-color': 'gray',
'background-color': 'gray',
'color': 'white'
'color': 'white'
});
});
}, function() {
}, function() {
$(this).css({ //on un-hover
$(this).css({ //on un-hover
'background-color': 'inherit',
'background-color': 'inherit',
'color': 'inherit'
'color': 'inherit'
});
});
});
});


$('#reasons input[type="checkbox"]').change(function() {
$('#reasons input[type="checkbox"]').change(function() {
if (this.checked) { //Add it to the summary
if (this.checked) { //Add it to the summary
if (!editCommentField.val()) {
if (!editCommentField.val()) {
editCommentField.val(toLocaleSentenceCase($(this).val()));
editCommentField.val(toLocaleSentenceCase($(this).val()));
} else {
} else {
editCommentField.val(editCommentField.val() + '; ' + $(this).val());
editCommentField.val(editCommentField.val() + '; ' + $(this).val());
}
}
var newEditComment = editCommentField.val(); //Remove the last space and last semicolon
var newEditComment = editCommentField.val(); //Remove the last space and last semicolon
editCommentField.val(newEditComment).focus();
editCommentField.val(newEditComment).focus();
} else if (!this.checked) { //Remove it from the summary
} else if (!this.checked) { //Remove it from the summary
editCommentField.val(toLocaleSentenceCase(editCommentField.val().replace(new RegExp(toLocaleSentenceCase($(this).val()) + ';? ?'), ''))); //for beginning values
editCommentField.val(toLocaleSentenceCase(editCommentField.val().replace(new RegExp(toLocaleSentenceCase($(this).val()) + ';? ?'), ''))); //for beginning values
editCommentField.val(editCommentField.val().replace($(this).val() + '; ', '')); //for middle values
editCommentField.val(editCommentField.val().replace($(this).val() + '; ', '')); //for middle values
editCommentField.val(editCommentField.val().replace(new RegExp(';? ?' + $(this).val()), '')); //for last value
editCommentField.val(editCommentField.val().replace(new RegExp(';? ?' + $(this).val()), '')); //for last value
}
}
});
});
}
}
}
}


function displayDeleteValues() {
function displayDeleteValues() {
//Display the items from list and add buttons to delete them
//Display the items from list and add buttons to delete them


$('#currentValues').html(' ');
$('#currentValues').html(' ');
$.each(JSON.parse(GM_getValue('editReasons')), function(i, obj) {
$.each(JSON.parse(GM_getValue('editReasons')), function(i, obj) {
$('#currentValues').append(this[0] + ' - ' + this[1] + '<input type="button" id="' + i + '" value="Delete"><br />');
$('#currentValues').append(this[0] + ' - ' + this[1] + '<input type="button" id="' + i + '" value="Delete"><br />');
});
});
addCheckboxes();
addCheckboxes();
}
}


var div = '<div id="dialogEditReasons" class="sox-centered wmd-prompt-dialog"><span id="closeDialogEditReasons" style="float:right;">Close</span><span id="resetEditReasons" style="float:left;">Reset</span> \
var div = '<div id="dialogEditReasons" class="sox-centered wmd-prompt-dialog"><span id="closeDialogEditReasons" style="float:right;">Close</span><span id="resetEditReasons" style="float:left;">Reset</span> \
<h2>View/Remove Edit Reasons</h2> \
<h2>View/Remove Edit Reasons</h2> \
<div id="currentValues"></div> \
<div id="currentValues"></div> \
<br /> \
<br /> \
<h3>Add a custom reason</h3> \
<h3>Add a custom reason</h3> \
Display Reason: <input type="text" id="displayReason"> \
Display Reason: <input type="text" id="displayReason"> \
<br /> \
<br /> \
Actual Reason: <input type="text" id="actualReason"> \
Actual Reason: <input type="text" id="actualReason"> \
<br /> \
<br /> \
<input type="button" id="submitUpdate" value="Submit"> \
<input type="button" id="submitUpdate" value="Submit"> \
</div>';
</div>';


$('body').append(div);
$('body').append(div);
$('#dialogEditReasons').draggable().css('position', 'absolute').css('text-align', 'center').css('height', '60%').hide();
$('#dialogEditReasons').draggable().css('position', 'absolute').css('text-align', 'center').css('height', '60%').hide();


$('#closeDialogEditReasons').css('cursor', 'pointer').click(function() {
$('#closeDialogEditReasons').css('cursor', 'pointer').click(function() {
$(this).parent().hide(500);
$(this).parent().hide(500);
});
});


$('#resetEditReasons').css('cursor', 'pointer').click(function() { //manual reset
$('#resetEditReasons').css('cursor', 'pointer').click(function() { //manual reset
var options = [ //Edit these to change the default settings
var options = [ //Edit these to change the default settings
['formatting', 'Improved Formatting'],
['formatting', 'Improved Formatting'],
['spelling', 'Corrected Spelling'],
['spelling', 'Corrected Spelling'],
['grammar', 'Fixed grammar'],
['grammar', 'Fixed grammar'],
['greetings', 'Removed thanks/greetings']
['greetings', 'Removed thanks/greetings']
];
];
if (confirm('Are you sure you want to reset the settings to Formatting, Spelling, Grammar and Greetings')) {
if (confirm('Are you sure you want to reset the settings to Formatting, Spelling, Grammar and Greetings')) {
GM_setValue('editReasons', JSON.stringify(options));
GM_setValue('editReasons', JSON.stringify(options));
alert('Reset options to default. Refreshing...');
alert('Reset options to default. Refreshing...');
location.reload();
location.reload();
}
}
});
});


if (GM_getValue('editReasons', -1) == -1) { //If settings haven't been set/are empty
if (GM_getValue('editReasons', -1) == -1) { //If settings haven't been set/are empty
var defaultOptions = [
var defaultOptions = [
['formatting', 'Improved Formatting'],
['formatting', 'Improved Formatting'],
['spelling', 'Corrected Spelling'],
['spelling', 'Corrected Spelling'],
['grammar', 'Fixed grammar'],
['grammar', 'Fixed grammar'],
['greetings', 'Removed thanks/greetings']
['greetings', 'Removed thanks/greetings']
];
];
GM_setValue('editReasons', JSON.stringify(defaultOptions)); //save the default settings
GM_setValue('editReasons', JSON.stringify(defaultOptions)); //save the default settings
} else {
} else {
var options = JSON.parse(GM_getValue('editReasons')); //If they have, get the options
var options = JSON.parse(GM_getValue('editReasons')); //If they have, get the options
}
}


$('#dialogEditReasons').on('click', 'input[value="Delete"]', function() { //Click handler to delete when delete button is pressed
$('#dialogEditReasons').on('click', 'input[value="Delete"]', function() { //Click handler to delete when delete button is pressed
var delMe = $(this).attr('id');
var delMe = $(this).attr('id');
options.splice(delMe, 1); //actually delete it
options.splice(delMe, 1); //actually delete it
GM_setValue('editReasons', JSON.stringify(options)); //save it
GM_setValue('editReasons', JSON.stringify(options)); //save it
displayDeleteValues(); //display the items again (update them)
displayDeleteValues(); //display the items again (update them)
});
});


$('#submitUpdate').click(function() { //Click handler to update the array with custom value
$('#submitUpdate').click(function() { //Click handler to update the array with custom value
if (!$('#displayReason').val() || !$('#actualReason').val()) {
if (!$('#displayReason').val() || !$('#actualReason').val()) {
alert('Please enter something in both the textboxes!');
alert('Please enter something in both the textboxes!');
} else {
} else {
var arrayToAdd = [$('#displayReason').val(), $('#actualReason').val()];
var arrayToAdd = [$('#displayReason').val(), $('#actualReason').val()];
options.push(arrayToAdd); //actually add the value to array
options.push(arrayToAdd); //actually add the value to array


GM_setValue('editReasons', JSON.stringify(options)); //Save the value
GM_setValue('editReasons', JSON.stringify(options)); //Save the value


// moved display call after setvalue call, list now refreshes when items are added
// moved display call after setvalue call, list now refreshes when items are added
displayDeleteValues(); //display the items again (update them)
displayDeleteValues(); //display the items again (update them)


//reset textbox values to empty
//reset textbox values to empty
$('#displayReason').val('');
$('#displayReason').val('');
$('#actualReason').val('');
$('#actualReason').val('');


}
}
});
});


setTimeout(function() {
setTimeout(function() {
addCheckboxes();
addCheckboxes();
//Add the button to update and view the values in the help menu:
//Add the button to update and view the values in the help menu:
$('.topbar-dialog.help-dialog.js-help-dialog > .modal-content ul').append("<li><a href='javascript:void(0)' id='editReasonsLink'>Edit Reasons \
$('.topbar-dialog.help-dialog.js-help-dialog > .modal-content ul').append("<li><a href='javascript:void(0)' id='editReasonsLink'>Edit Reasons \
<span class='item-summary'>Edit your personal edit reasons for SE sites</span></a></li>");
<span class='item-summary'>Edit your personal edit reasons for SE sites</span></a></li>");
$('.topbar-dialog.help-dialog.js-help-dialog > .modal-content ul #editReasonsLink').on('click', function() {
$('.topbar-dialog.help-dialog.js-help-dialog > .modal-content ul #editReasonsLink').on('click', function() {
displayDeleteValues();
displayDeleteValues();
$('#dialogEditReasons').show(500); //Show the dialog to view and update values
$('#dialogEditReasons').show(500); //Show the dialog to view and update values
});
});
}, 500);
}, 500);
$(document).on('sox-edit-window', addCheckboxes);
$(document).on('sox-edit-window', addCheckboxes);


$('.post-menu > .edit-post').click(function() {
$('.post-menu > .edit-post').click(function() {
setTimeout(function() {
setTimeout(function() {
addCheckboxes();
addCheckboxes();
}, 500);
}, 500);
});
});
},
},


shareLinksPrivacy: function() {
shareLinksPrivacy: function() {
// Description: Remove your user ID from the 'share' link
// Description: Remove your user ID from the 'share' link


sox.helpers.observe('.share-tip', function() {
sox.helpers.observe('.share-tip', function() {
const toRemove = ' (includes your user id)';
const toRemove = ' (includes your user id)';
var popup = $('.share-tip');
var popup = $('.share-tip');
var origHtml = popup.html();
var origHtml = popup.html();
if (origHtml.indexOf(toRemove) == -1) return; //don't do anything if the function's already done its thing
if (origHtml.indexOf(toRemove) == -1) return; //don't do anything if the function's already done its thing
popup.html(function() {
popup.html(function() {
return origHtml.replace(toRemove, '');
return origHtml.replace(toRemove, '');
});
});


var inputBox = $('.share-tip input'),
var inputBox = $('.share-tip input'),
origLink = inputBox.val();
origLink = inputBox.val();
inputBox.val(origLink.match(/.+\/(q|a)\/[0-9]+/g));
inputBox.val(origLink.match(/.+\/(q|a)\/[0-9]+/g));
inputBox.select();
inputBox.select();
});
});
},
},


shareLinksMarkdown: function() {
shareLinksMarkdown: function() {
// Description: For changing the 'share' button link to the format [name](link)
// Description: For changing the 'share' button link to the format [name](link)


sox.helpers.observe('.share-tip', function() {
sox.helpers.observe('.share-tip', function() {
var link = $('.share-tip input').val(),
var link = $('.share-tip input').val(),
title = $('meta[name="twitter:title"]').attr('content').replace(/\[(.*?)\]/g, '\[$1\]'); //https://github.com/soscripted/sox/issues/226, https://github.com/soscripted/sox/issues/292
title = $('meta[name="twitter:title"]').attr('content').replace(/\[(.*?)\]/g, '\[$1\]'); //https://github.com/soscripted/sox/issues/226, https://github.com/soscripted/sox/issues/292


if (link.indexOf(title) !== -1) return; //don't do anything if the function's already done its thing
if (link.indexOf(title) !== -1) return; //don't do anything if the function's already done its thing
$('.share-tip input').val('[' + title + '](' + link + ')');
$('.share-tip input').val('[' + title + '](' + link + ')');
$('.share-tip input').select();
$('.share-tip input').select();
document.execCommand('copy'); //https://github.com/soscripted/sox/issues/177
document.execCommand('copy'); //https://github.com/soscripted/sox/issues/177
});
});
},
},


commentShortcuts: function() {
commentShortcuts: function() {
// Descr
// Description: For adding support in comments for Ctrl+K,I,B to add code backticks, italicise, bolden selection

$('.