Skip to content

Commit 8a8e5e9

Browse files
committed
v2.6.0 merge
* Fix bugs in various features * Add support for StylishThemes/StackOverflow-Dark theme * Remove dependency on Font Awesome for icons (use SVG sprites instead) * Update many features to work with recent SE HTML markup/CSS changes * Add feature to open imgur image in a modal on click
2 parents 26488ec + fe364bb commit 8a8e5e9

34 files changed

+567
-287
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"extends": "eslint:recommended",
99
"parserOptions": {
10-
"ecmaVersion": 2017
10+
"ecmaVersion": 2018
1111
},
1212
"rules": {
1313
"indent": [
File renamed without changes.
File renamed without changes.
File renamed without changes.

.github/no-response.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Configuration for probot-no-response - https://github.com/probot/no-response
22

33
# Number of days of inactivity before an Issue is closed for lack of response
4-
daysUntilClose: 14
4+
daysUntilClose: 5
55
# Label requiring a response
66
responseRequiredLabel: more-information-needed
77
# Comment to post when closing an Issue for lack of response. Set to `false` to disable

.github/stale.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# Number of days of inactivity before an issue becomes stale
2-
daysUntilStale: 30
2+
daysUntilStale: 15
33
# Number of days of inactivity before a stale issue is closed
44
daysUntilClose: 7
55
# Issues with these labels will never be considered stale
66
exemptLabels:
77
- contributions welcome
88
- confirmed
9-
- in progress
109
- approved
1110
# Label to use when marking an issue as stale
1211
staleLabel: rejected

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2018 soscripted
3+
Copyright (c) 2019 soscripted
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Join the chat at https://gitter.im/soscripted/sox](https://badges.gitter.im/soscripted/sox.svg)](https://gitter.im/soscripted/sox?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
22

3-
### SOX v2.5.0
3+
### SOX v2.6.0
44

55
Stack Overflow Extras (*SOX*) is a project that stemmed from the [Stack Overflow Optional Features (SOOF)](https://github.com/shu8/Stack-Overflow-Optional-Features) project.
66

@@ -22,7 +22,7 @@ Note: This project has no relation to Stack Overflow or Stack Exchange; it is si
2222

2323
2. Install the script. Clicking on 'install' below will make Tampermonkey prompt you automatically to install it.
2424

25-
- Official Version: <kbd>[install](https://github.com/soscripted/sox/raw/v2.5.0/sox.user.js)</kbd>. <kbd>[view source](https://github.com/soscripted/sox/blob/v2.5.0/sox.user.js)</kbd>
25+
- Official Version: <kbd>[install](https://github.com/soscripted/sox/raw/v2.6.0/sox.user.js)</kbd>. <kbd>[view source](https://github.com/soscripted/sox/blob/v2.6.0/sox.user.js)</kbd>
2626
- Development Version: <kbd>[install](https://github.com/soscripted/sox/raw/dev/sox.user.js)</kbd>. <kbd>[view source](https://github.com/soscripted/sox/blob/dev/sox.user.js)</kbd>
2727

2828
3. Go to any site in the Stack Exchange Network (e.g. [Super User](http://superuser.com/) or [Stack Overflow](http://stackoverflow.com/)). You will automatically be asked to choose and save your settings. A toggle button (gears icon) will be added to your topbar where you can change these later on:

icons/sox_access_time.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_checked_box.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_chevron_left.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_chevron_right.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_copy.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_export.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_hot.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_import.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_info.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_key.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_launch.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_search.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_settings.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_toggle_off.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_toggle_on.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_top.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_unchecked_box.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/sox_wrench.svg

Lines changed: 1 addition & 0 deletions
Loading

sox.common.js

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,28 @@
134134
};
135135
}
136136

137+
sox.sprites = {
138+
getSvg: function (name, tooltip, css) {
139+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
140+
const use = document.createElementNS('http://www.w3.org/2000/svg', 'use');
141+
const title = document.createElementNS('http://www.w3.org/2000/svg', 'title');
142+
143+
if (tooltip) {
144+
svg.setAttribute('title', tooltip);
145+
title.textContent = tooltip;
146+
svg.appendChild(title);
147+
}
148+
149+
use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', `#sox_${name}`);
150+
svg.appendChild(use);
151+
152+
if (css) $(svg).css(css);
153+
svg.classList.add('sox-sprite');
154+
svg.classList.add(`sox-sprite-${name}`);
155+
return $(svg);
156+
},
157+
};
158+
137159
sox.helpers = {
138160
getFromAPI: function (details, callback) {
139161
let {
@@ -355,7 +377,7 @@
355377
return idMatch ? +idMatch[1] : null;
356378
},
357379
getSiteNameFromLink: function(link) {
358-
const siteRegex = /(((.+)\.)?(stackexchange|stackoverflow|superuser|serverfault|askubuntu|stackapps|mathoverflow|programmers|bitcoin))\.com/;
380+
const siteRegex = /(((.+)\.)?(((stackexchange|stackoverflow|superuser|serverfault|askubuntu|stackapps))(?=\.com))|mathoverflow\.net)/;
359381
const siteMatch = link.replace(/https?:\/\//, '').match(siteRegex);
360382
return siteMatch ? siteMatch[1] : null;
361383
},
@@ -371,9 +393,10 @@
371393
'class': 's-modal--dialog js-modal-dialog ',
372394
'style': 'min-width: 568px;',// top: 227.736px; left: 312.653px;',
373395
});
396+
if (params.css) $dialogInnerContainer.css(params.css);
374397
const $header = $('<h1/>', {
375-
'class': 's-modal--header fs-headline1 fw-bold mr48 js-first-tabbable',
376-
'text': params.header,
398+
'class': 's-modal--header fs-headline1 fw-bold mr48 js-first-tabbable sox-custom-dialog-header',
399+
'html': params.header,
377400
});
378401
const $mainContent = $('<div/>', {
379402
'class': 's-modal--body sox-custom-dialog-content',
@@ -404,6 +427,57 @@
404427
$li.append($a.append($span));
405428
$('.topbar-dialog.help-dialog.js-help-dialog > .modal-content ul').append($li);
406429
},
430+
surroundSelectedText: function(textarea, start, end) {
431+
// same wrapper code on either side (`$...$`)
432+
if (typeof end === 'undefined') end = start;
433+
434+
/*--- Expected behavior:
435+
When there is some text selected: (unwrap it if already wrapped)
436+
"]text[" --> "**]text[**"
437+
"**]text[**" --> "]text["
438+
"]**text**[" --> "**]**text**[**"
439+
"**]**text**[**" --> "]**text**["
440+
When there is no text selected:
441+
"][" --> "**placeholder text**"
442+
"**][**" --> ""
443+
Note that `]` and `[` denote the selected text here.
444+
*/
445+
446+
const selS = textarea.selectionStart < textarea.selectionEnd ? textarea.selectionStart : textarea.selectionEnd;
447+
const selE = textarea.selectionStart > textarea.selectionEnd ? textarea.selectionStart : textarea.selectionEnd;
448+
const value = textarea.value;
449+
const startLen = start.length;
450+
const endLen = end.length;
451+
452+
let valBefore = value.substring(0, selS);
453+
let valMid = value.substring(selS, selE);
454+
let valAfter = value.substring(selE);
455+
let generatedWrapper;
456+
457+
// handle trailing spaces
458+
const trimmedSelection = valMid.match(/^(\s*)(\S?(?:.|\n|\r)*\S)(\s*)$/) || ['', '', '', ''];
459+
460+
// determine if text is currently wrapped
461+
if (valBefore.endsWith(start) && valAfter.startsWith(end)) {
462+
textarea.value = valBefore.substring(0, valBefore.length - startLen) + valMid + valAfter.substring(endLen);
463+
textarea.selectionStart = valBefore.length - startLen;
464+
textarea.selectionEnd = (valBefore + valMid).length - startLen;
465+
textarea.focus();
466+
} else {
467+
valBefore += trimmedSelection[1];
468+
valAfter = trimmedSelection[3] + valAfter;
469+
valMid = trimmedSelection[2];
470+
471+
generatedWrapper = start + valMid + end;
472+
473+
textarea.value = valBefore + generatedWrapper + valAfter;
474+
textarea.selectionStart = valBefore.length + start.length;
475+
textarea.selectionEnd = (valBefore + generatedWrapper).length - end.length;
476+
textarea.focus();
477+
}
478+
479+
sox.Stack.MarkdownEditor.refreshAllPreviews();
480+
},
407481
};
408482

409483
sox.site = {

0 commit comments

Comments
 (0)