Skip to content

Commit

Permalink
v2.0.1 merge (#109)
Browse files Browse the repository at this point in the history
* Update README.md

* changes

* don't use stack.read if not available

* fixes script on Firefox hopefully

should fix #75, #76, #71

* fixes #73

* bump version

* fixes some bugs

fixes:
- #89,
- #95,
- bug relating to #98
- change to #88
- fixes SBS (part of #72)
- fixes #80 and part of #72
- fixes #72 entirely
- fixes compatibility issue between SBS and enhanced editor features

* changes

#72, #98, #73

* fixes

- fixes #72
- should fix #98
- added logs for #73

* #93

* #73

* #95

* #75, #95

* clean-up, add debugging for #98

* add debugging for #98, cleanup

* #73

* #73, #102

* #102

* #98

* 2.0.1i

* #98

* #95

* #98

* fixes #104, #105

* fixes #103, changes to #104

* v2.0.1 final
  • Loading branch information
shu8 authored Oct 1, 2016
1 parent 37198c2 commit 29d87e3
Show file tree
Hide file tree
Showing 8 changed files with 553 additions and 288 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Note: This project has no relation to Stack Overflow or Stack Exchange; it is si

- Official Version: <kbd>[install](https://github.com/soscripted/sox/raw/v2.0.0/sox.user.js)</kbd>. <kbd>[view source](https://github.com/soscripted/sox/blob/v2.0.0/sox.user.js)</kbd>
- 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>
- Experimental Version: <kbd>[install](https://github.com/soscripted/sox/raw/experimental/sox.user.js)</kbd>. <kbd>[view source](https://github.com/soscripted/sox/blob/experimental/sox.user.js)</kbd>

3. Go to any site in the Stack Exchange Network (eg. [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:

Expand Down
96 changes: 60 additions & 36 deletions sox.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var SOX_SETTINGS = 'SOXSETTINGS';
var commonInfo = JSON.parse(GM_getResourceText('common'));

var Stack = (typeof StackExchange === "undefined" ? undefined : StackExchange);
var Stack = (typeof StackExchange === "undefined" ? window.eval('StackExchange') : StackExchange);
var Chat = (typeof CHAT === "undefined" ? undefined : CHAT);

sox.info = {
Expand All @@ -14,15 +14,23 @@

sox.ready = function(func) {
$(function() {
return Stack ? Stack.ready(func) : func();
if (Stack) {
if (Stack.ready) {
Stack.ready(func());
} else {
func();
}
} else {
func();
}
});
};

sox.settings = {
available: GM_getValue(SOX_SETTINGS, -1) != -1,
load: function() {
var settings = GM_getValue(SOX_SETTINGS);
return settings == undefined ? undefined : JSON.parse(settings);
var settings = GM_getValue(SOX_SETTINGS);
return settings === undefined ? undefined : JSON.parse(settings);
},
save: function(settings) {
GM_setValue(SOX_SETTINGS, JSON.stringify(settings));
Expand All @@ -35,6 +43,7 @@
}
},
get accessToken() {
console.log('SOX Access Token: ' + (GM_getValue('SOX-accessToken', false) === false ? 'NOT SET' : 'SET'));
return GM_getValue('SOX-accessToken', false);
},
writeToConsole: function() {
Expand All @@ -55,49 +64,67 @@
}
},
getFromAPI: function(type, id, sitename, callback, sortby) {
$.getJSON('https://api.stackexchange.com/2.2/' + type + '/' + id + '?order=desc&sort=' + (sortby || 'creation') + '&site=' + sitename, callback);
console.log('Getting From API with URL: https://api.stackexchange.com/2.2/' + type + '/' + id + '?order=desc&sort=' + (sortby || 'creation') + '&site=' + sitename + '&key=' + sox.info.apikey + '&access_token=' + sox.settings.accessToken);
$.ajax({
type: 'get',
url: 'https://api.stackexchange.com/2.2/' + type + '/' + id + '?order=desc&sort=' + (sortby || 'creation') + '&site=' + sitename + '&key=' + sox.info.apikey + '&access_token=' + sox.settings.accessToken,
success: function(d) {
if(d.backoff) {
console.log('SOX Error: BACKOFF: ' + d.backoff);
} else {
callback(d);
}
},
error: function(a, b, c) {
console.log('SOX Error: ' + b + ' ' + c);
}
});
},
observe: function(elements, callback, toObserve) {
console.log('observe: ' + elements);
new MutationObserver(function(mutations, observer) {
for (var i = 0; i < mutations.length; i++) {
for (var j = 0; j < mutations[i].addedNodes.length; j++) {
var $o = $(mutations[i].addedNodes[j]);
if ($o && $o.is((Array.isArray(elements) ? elements.join(',') : elements))) {
callback(mutations[i].addedNodes[j]);
console.log('fire: ' + elements);
}
}
}
}).observe(toObserve || document.body, {
childList: true,
subtree: true
subtree: true,
attributes: true,
characterData: true
});
},
newElement: function(type, elementDetails) {
var extras = {},
allowed = ['text', 'checkbox', 'radio', 'textarea', 'span'];
if(allowed.indexOf(type) != -1) {
if(type == 'text') {
type = 'input';
extras['type'] = 'input';
} else if (type == 'checkbox') {
type = 'input';
extras['type'] = 'checkbox';
} else if (type == 'radio') {
type = 'input';
extras['type'] = 'radio';
} else if (type == 'textarea') {
if(!elementDetails.text) {
elementDetails.text = elementDetails.value;
}
}
var extras = {},
allowed = ['text', 'checkbox', 'radio', 'textarea', 'span'];
if (allowed.indexOf(type) != -1) {
if (type == 'text') {
type = 'input';
extras.type = 'input';
} else if (type == 'checkbox') {
type = 'input';
extras.type = 'checkbox';
} else if (type == 'radio') {
type = 'input';
extras.type = 'radio';
} else if (type == 'textarea') {
if (!elementDetails.text) {
elementDetails.text = elementDetails.value;
}
}

$.each(elementDetails, function(k, v) {
extras[k] = v;
});
return $('<' + type + '/>', extras);
} else {
return false;
}
$.each(elementDetails, function(k, v) {
extras[k] = v;
});
return $('<' + type + '/>', extras);
} else {
return false;
}
}
};

Expand Down Expand Up @@ -140,14 +167,12 @@
}
},
metaApiParameter: function(siteName) {
if (Chat || Stack && this.apiParameter(siteName)) {
if (Chat || this.apiParameter(siteName)) {
return 'meta.' + this.apiParameter(siteName);
}
},
get currentApiParameter() {
if (Chat || Stack) {
return this.apiParameter(this.name);
}
return this.apiParameter(this.name);
},
get icon() {
return "favicon-" + $(".current-site a:not([href*='meta']) .site-icon").attr('class').split('favicon-')[1];
Expand Down Expand Up @@ -186,7 +211,7 @@
matchPath = matchSplit.slice(-(matchSplit.length - 3)).join('/');

matchScheme = matchScheme.replace(/\*/g, ".*");
matchHost = matchHost.replace(/\./g, "\\.").replace(/\*\\\./g, ".*.?").replace(/\\\.\*/g, ".*").replace(/\*$/g, ".*");;
matchHost = matchHost.replace(/\./g, "\\.").replace(/\*\\\./g, ".*.?").replace(/\\\.\*/g, ".*").replace(/\*$/g, ".*");
matchPath = '^\/' + matchPath.replace(/\//g, "\\/").replace(/\*/g, ".*");

if (currentSiteScheme.match(new RegExp(matchScheme)) && currentSiteHost.match(new RegExp(matchHost)) && currentSitePath.match(new RegExp(matchPath))) {
Expand Down Expand Up @@ -222,7 +247,6 @@
return Stack ? Stack.options.user.isRegistered : undefined;
},
hasPrivilege: function(privilege) {
var privilege = {};
if (this.loggedIn) {
var rep = (sox.site.type == 'beta' ? commonInfo.privileges.beta[privilege] : commonInfo.privileges.graduated[privilege]);
return this.rep > rep;
Expand Down
16 changes: 2 additions & 14 deletions sox.css
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
transform: rotate(30deg);
font-size: xx-large;
color: red;
margin-top: 20px;
}

/*quickCommentShortcutsMain: */
Expand Down Expand Up @@ -328,24 +329,11 @@ hr.or:after {
.DDG-credit {
font-size: 0.8em;
}
#enhancedEditor-aceEditor>#editor {
position: absolute;
top: 10%;
right: 0;
bottom: 0;
left: 0;
}
.enhancedEditor-aceLanguages {
float: right;
}
.enhancedEditor-addCode {
float: right;
margin-right: 5px;
}
.enhancedEditor-toolbar {
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
padding-right: 147px;
display: block;
}
.enhancedEditor-toolbar > span {
cursor: pointer;
Expand Down
7 changes: 6 additions & 1 deletion sox.dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@
}

// display sox version number in the dialog
$soxSettingsDialogVersion.text(version != 'unknown' ? ' v' + version.toLowerCase() : '');
if(version != 'unknown' && version !== null) {
$soxSettingsDialogVersion.text(' v' + version.toLowerCase());
} else {
$soxSettingsDialogVersion.text('');
}

// wire up event handlers
$soxSettingsClose.on('click', function() {
$soxSettingsDialog.hide();
});

$soxSettingsReset.on('click', function() {
sox.settings.reset();
location.reload(); // reload page to reflect changed settings
Expand Down
15 changes: 9 additions & 6 deletions sox.enhanced_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
});

$('.edit-post').click(function() {
$that = $(this);
var $that = $(this);
setTimeout(function() {
sox.enhancedEditor.init($that.parents('table').find('.inline-editor textarea.processed').attr('id'));
}, 5000);
Expand Down Expand Up @@ -83,7 +83,7 @@
$('#DDG-credit a').attr('href', 'http://google.com');
$('#enhancedEditor-insertLinkDialog').show(500);
setTimeout(function () {
query = $(s).getSelection();
var query = $(s).getSelection();

$.getJSON("http://api.duckduckgo.com/?q=" + query.text + "&format=json&t=stackExchangeEditorPro&callback=?", function (json) {
$('#DDG-header').append("<a href='" + json.AbstractURL + "'>" + json.Heading + "</a>");
Expand Down Expand Up @@ -131,9 +131,9 @@
$(s).prev().after("<div class='enhancedEditor-toolbar findReplace'><input id='find' type='text' placeholder='Find'><input id='modifier' type='text' placeholder='Modifier'><input id='replace' type='text' placeholder='Replace with'><input id='replaceGo' type='button' value='Go'></div>");
}
$(document).on('click', '.findReplace #replaceGo', function() {
regex = new RegExp($('.findReplace #find').val(), $('.findReplace #modifier').val());
oldval = $(s).val();
newval = oldval.replace(regex, $('.findReplace #replace').val());
var regex = new RegExp($('.findReplace #find').val(), $('.findReplace #modifier').val());
var oldval = $(s).val();
var newval = oldval.replace(regex, $('.findReplace #replace').val());
$(s).val(newval);
sox.enhancedEditor.refreshPreview();
});
Expand Down Expand Up @@ -241,7 +241,10 @@
},

refreshPreview: function() {
SOHelper.StackExchange().MarkdownEditor.refreshAllPreviews();
var Stack = (typeof StackExchange === "undefined" ? window.eval('StackExchange') : StackExchange);
if(Stack.MarkdownEditor) {
Stack.MarkdownEditor.refreshAllPreviews();
}
}
};
})(window.sox = window.sox || {}, jQuery);
2 changes: 1 addition & 1 deletion sox.features.info.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"exclude": ""
}, {
"name": "metaChatBlogStackExchangeButton",
"desc": "Show meta, chat and blog buttons on hover of a site under the StackExchange button",
"desc": "Show meta and chat buttons on hover of a site under the StackExchange button",
"meta": "http://meta.stackexchange.com/questions/256183/show-the-meta-chat-and-blog-in-the-top-bar-for-other-sites-on-hover",
"match": "",
"exclude": ""
Expand Down
Loading

0 comments on commit 29d87e3

Please sign in to comment.