正在載入此比較的其餘部分。

Untitled diff

建立於 差異永不過期
12 刪除
522 行
6 新增
520 行
(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