From 875ff0e5cc21c7f5638bc74e84b0227e5759065a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=94=95=E1=96=BA=E1=98=8E=E1=95=8A?= Date: Sat, 24 Feb 2018 20:39:26 +0000 Subject: [PATCH 01/20] new dev --- LICENSE | 2 +- README.md | 2 +- editAlert.js | 727 ---------------------------------------------- editAlert.user.js | 28 -- editAlertV1 | 559 ----------------------------------- sox.user.js | 2 +- 6 files changed, 3 insertions(+), 1317 deletions(-) delete mode 100644 editAlert.js delete mode 100644 editAlert.user.js delete mode 100644 editAlertV1 diff --git a/LICENSE b/LICENSE index 78a3556..054dbec 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2017 soscripted +Copyright (c) 2018 soscripted Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index aa08396..6020572 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![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) -### SOX v2.0.25 DEV +### SOX v2.1.0 DEV 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. diff --git a/editAlert.js b/editAlert.js deleted file mode 100644 index eb149ef..0000000 --- a/editAlert.js +++ /dev/null @@ -1,727 +0,0 @@ -/*jshint loopfunc: true, esversion: 6*/ -/* -- to show in notification: - - delete button -*/ -(function(sox, $, undefined) { - console.log('running editAlert.js'); - //TODO add to SOX stylesheet when adding this feature to SOX - GM_addStyle(`.sox-watch-post { - margin-left: 5px; - } - .sox-notify-on-change { - cursor: pointer; - } - #sox-edit-notification-options { - position: absolute; - display: none; - margin-left: 5px; - } - #sox-edit-notification-options-list { - list-style-type: none; - margin-left: 15px; - } - #sox-edit-notification-options-save { - cursor: pointer; - color: green; - } - #sox-edit-notification-options-cancel { - cursor: pointer; - } - #sox-editNotificationDialogButton { - background-image: none; - padding-top: 9px; - font-size: 14px; - color: #858c93; - height: 24px !important; - min-width: 34px; - cursor: pointer; - } - - #sox-editNotificationDialogButton:hover { - color: #999; - } - - .sox-editNotificationButtonCount { - background-color: blue; - display: block; - color: #FFF; - font-weight: bold; - text-indent: 0; - border-radius: 2px; - padding: 1px 6px 1px 6px; - font-size: 11px; - line-height: 1; - width: 8px; - position: absolute; - height: 11px; - margin-left: 7px; - } - - #sox-editNotificationDialog { - top: 34px; - left: 264px; - width: 377px; - display: none; - } - - #sox-editNotificationDialogButton.glow { - -webkit-text-stroke-color: blue; - -webkit-text-stroke-width: 3px; - } - - .sox-editNotification-messageType { - color: gray; - text-transform: uppercase; - font-size: 11px; - } - `); - - function addNotification(details, callback, alreadySaved) { - console.log('adding notification with details:', details); - var text = '', - time; - if (details.newLink && details.newScore) { - if (details.score && details.newState) { //newAnswersStateChange; sitename, title, newLink, newScore, score, newState - text = (details.newAnswerCount === 1 ? 'new answer, state change' : 'new answers, state change'); // details.newState; - } else { //newAnswers; sitename, title, newLink, newScore - text = details.newAnswerCount === 1 ? 'new answer' : 'new answers'; - } - time = new Date(details.creationDate * 1000); - } else if (details.score && details.newState) { //stateChange; sitename, title, score, newState - text = 'state change'; //'This question is now ' + details.newState; - } else if (details.editComment || details.newTags) { - if (details.newTags) { - if (details.editComment) { //editRetag; sitename, title, link, editComment, score, newTags - text = 'edited, new tags'; //'This question has been edited (' + details.editComment + ') and retagged (' + details.newTags.join(', ') + ')'; - } else { //retag; sitename, title, link, newTags, score - text = 'retag'; //'This question was retagged (' + details.newTags.join(', ') + ')'; - } - } else { //edit; sitename, title, link, editComment, score - text = 'edited'; //'This question has been edited (' + details.editComment + ')'; - } - time = new Date(details.editDate * 1000); - } else if (details.commentBody && details.commentsLink && details.newCommentsCount > 0) { - text = (details.newCommentsCount === 1 ? 'new comment' : 'new comments'); // + ' (' + (details.commentBody.length > 100 ? $('
').html(details.commentBody.substr(0, 100)).text() + '...' : $('
').html(details.commentBody.substr(0, 100)).text()) + ')'; //div creation is to unescape string for eg. quotes - time = new Date(details.creationDate * 1000); - } - - if (text) { - var $li = $('
  • ').append($('', { - 'href': details.link || details.newLink || details.commentsLink, - 'class': alreadySaved ? '' : 'new' - }).append($('
    ', { - 'class': 'site-icon favicon favicon-' + (details.sitename == 'meta' ? 'stackexchangemeta' : details.sitename), - 'style': 'margin-right: 10px' - })).append('' + (details.postType === 'question' ? 'Q: ' : 'A: ') + (details.score || details.newScore ? details.score || details.newScore : '') + ' ' + details.title)).append($('', { - 'style': 'color: black; margin-left: 5px', - 'html': $('', { - 'html': text + (time ? ' | ' : ''), - 'class': 'sox-editNotification-messageType' - }) - })); - - $('#sox-editNotificationDialogList').prepend($li); - - var noOfNotifications = $('#sox-editNotificationDialogList li .new').length; - //if double figures, add padding to fix alignment: - if (noOfNotifications) $('.sox-editNotificationButtonCount').css('padding-right', noOfNotifications > 9 ? '9px' : '6px').text(noOfNotifications).show(); - callback({ - 'addedNotification': true - }); - - var nots = JSON.parse(GM_getValue('sox-editNotification-notifications', '[]')); - if (!alreadySaved) { - alreadySaved = nots.filter(function(d) { - return d.postId == details.originalPostId; - }).length; - } - if (!alreadySaved) { - nots.push(details); - GM_setValue('sox-editNotification-notifications', JSON.stringify(nots)); - } - return; - } - callback({ - 'addedNotification': false - }); - } - - //GM_deleteValue('sox-editNotification-postsToWatch'); - //GM_deleteValue('sox-editNotification-commentsToWatch'); - //GM_deleteValue('sox-editNotification-notifications'); - var postsToWatch = JSON.parse(GM_getValue('sox-editNotification-postsToWatch', '[]')), - commentsToWatch = JSON.parse(GM_getValue('sox-editNotification-commentsToWatch', '[]')), - notifications = JSON.parse(GM_getValue('sox-editNotification-notifications', '[]')), - apiQuestionFilter = '!SCam31W85iAdF11znRBpj2qWFPRJV_*8fTZTOPnclcMRL3Dxjmxr-5DJdNc07fPo', - apiAnswerFilter = '!*IXxMt)cy3)mYENixz4JCogmlz1T(H0s*KHikYPCS4H3YAaTeot5E.A9HbhuHZ', - apiRevisionFilter = '!*K)GWE1gDcf3YaWY', - commentsFilter = '!*K)GSjDWh5AAh)g(', - options = { - 'retag': 'retag', - 'edit': 'edit', - 'state change': 'stateChange', - 'new answers': 'newAnswers' - }, - $ul = $('
  • '; $('#sidebar #newsletter-ad').parent().remove(); }, - enhancedEditor: function() { - // Description: Add a bunch of features to the standard markdown editor (autocorrect, find+replace, Ace editor, and more!) - - sox.enhancedEditor.startFeature(); - - }, - downvotedPostsEditAlert: function() { // Description: Adds a notification to the inbox if a question you downvoted and watched is edited @@ -2730,7 +2723,12 @@ Toggle SBS?
    '; }, openLinksInNewTab: function(settings) { - settings = settings.linksToOpenInNewTab.replace(' ', '').split(','); + // Description: Open any links to the specified sites in a new tab by default + + settings = settings.linksToOpenInNewTab; + if (!settings) return; + + settings = settings.replace(' ', '').split(','); if (settings.length) { //https://github.com/soscripted/sox/issues/300 $('.post-text a').each(function() { var href = $(this).attr('href'); @@ -2745,6 +2743,8 @@ Toggle SBS?
    '; }, showQuestionStateInSuggestedEditReviewQueue: function() { + // Description: Show question's current state in the suggested edit review queue (duplicate, off-topic, etc.) + $(document).on('sox-new-review-post-appeared', function() { if ($('#sox-showQuestionStateInSuggestedEditReviewQueue-checked').length) return; //already checked var postId = $('.summary h2 a').attr('href').split('/')[2]; @@ -2768,6 +2768,8 @@ Toggle SBS?'; }, addTimelineAndRevisionLinks: function() { + // Description: Add timeline and revision links to the bottom of each post for quick access to them + $('.question, .answer').each(function() { $(this).find('.post-menu').append($('', { 'href': '//' + sox.site.url + '/posts/' + sox.site.href.split('/')[4] + '/revisions', @@ -2777,6 +2779,62 @@ Toggle SBS?'; 'text': 'timeline' })); }); + }, + + findAndReplace: function() { //Salvaged from old 'enhanced editor' feature + // Description: adds a 'find and replace' option to the markdown editor + + function startLoop() { + $('textarea[id^="wmd-input"].processed').each(function() { + main($(this).attr('id')); + }); + + $('.edit-post').click(function() { + var $that = $(this); + sox.helpers.observe('#wmd-redo-button-' + $that.attr('href').split('/')[2], function() { + main($that.parents('table').find('.inline-editor textarea.processed').attr('id')); + }); + }); + } + + function main(wmd) { + var s = '#' + wmd; //s is the selector we pass onto each function so the action is applied to the correct textarea (and not, for example the 'add answer' textarea *and* the 'edit' textarea!) + if ($(s).parents('.wmd-container').find('#findReplace').length) return; + + $('.wmd-button-bar').css('margin-top', '0'); //https://github.com/soscripted/sox/issues/203 + + $(s).before("
    Find & Replace
    "); + + $(document).on('click', '#findReplace', function(e) { + if ($('.findReplaceInputs').length) { + $('.findReplaceInputs').remove(); + } else { + $(this).parent().append("
    "); + } + $(document).on('click', '.findReplaceToolbar #replaceGo', function() { + var regex = new RegExp($('.findReplaceToolbar #find').val(), $('.findReplaceToolbar #modifier').val()); + var oldval = $(this).parent().parent().parent().find('textarea').val(); + var newval = oldval.replace(regex, $('.findReplaceToolbar #replace').val()); + $(this).parent().parent().parent().find('textarea').val(newval); + + var Stack = (typeof StackExchange === "undefined" ? window.eval('StackExchange') : StackExchange); + if (Stack.MarkdownEditor) Stack.MarkdownEditor.refreshAllPreviews(); + }); + e.preventDefault(); + e.stopPropagation(); + }); + + $(s).keydown(function(e) { + if (e.which == 70 && e.ctrlKey) { //ctrl+f (find+replace) + $('#findReplace').trigger('click'); + e.stopPropagation(); + e.preventDefault(); + return false; + } + }); + } + $(document).on('sox-edit-window', startLoop); + startLoop(); } }; })(window.sox = window.sox || {}, jQuery); \ No newline at end of file diff --git a/sox.user.js b/sox.user.js index e2d2049..b77f005 100644 --- a/sox.user.js +++ b/sox.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Stack Overflow Extras (SOX) // @namespace https://github.com/soscripted/sox -// @version 2.1.10 DEV +// @version 2.1.11 DEV // @description Extra optional features for Stack Overflow and Stack Exchange sites // @contributor ᴉʞuǝ (stackoverflow.com/users/1454538/) // @contributor ᔕᖺᘎᕊ (stackexchange.com/users/4337810/) From c66ec2b8503950d6b99206f212b628722ab3e941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=94=95=E1=96=BA=E1=98=8E=E1=95=8A?= Date: Thu, 17 May 2018 19:25:50 +0100 Subject: [PATCH 15/20] #308, other small fixes --- sox.common.js | 6 +++--- sox.dialog.js | 17 ++++++++++------- sox.features.info.json | 2 +- sox.features.js | 2 +- sox.user.js | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/sox.common.js b/sox.common.js index 38acea1..a7b2f0a 100644 --- a/sox.common.js +++ b/sox.common.js @@ -271,9 +271,9 @@ matchWithPattern: function(pattern, urlToMatchWith) { //commented version @ https://jsfiddle.net/shub01/t90kx2dv/ if (pattern == 'SE1.0') { //SE.com && Area51.SE.com special checking if (urlToMatchWith) { - if (urlToMatchWith.match(/https?:\/\/stackexchange\.com\/?/) || sox.location.matchWithPattern('*://area51.stackexchange.com/*')) return true; + if (urlToMatchWith.match(/https?:\/\/stackexchange\.com\/?/) || (sox.location.matchWithPattern('*://area51.stackexchange.com/*') && sox.site.href.indexOf('.meta.') === -1)) return true; } else { - if (location.href.match(/https?:\/\/stackexchange\.com\/?/) || sox.location.matchWithPattern('*://area51.stackexchange.com/*')) return true; + if (location.href.match(/https?:\/\/stackexchange\.com\/?/) || (sox.location.matchWithPattern('*://area51.stackexchange.com/*') && sox.site.href.indexOf('.meta.') === -1)) return true; } return false; } @@ -324,7 +324,7 @@ if (sox.site.type == sox.site.types.chat) { return Chat.RoomUsers.current().name; } else { - var $uname = sox.NEW_TOPBAR ? $('.top-bar div.gravatar-wrapper-24') : $('body > div.topbar > div > div.topbar-links > a > div.gravatar-wrapper-24'); + var $uname = $('.top-bar div.gravatar-wrapper-24'); //used to be $('body > div.topbar > div > div.topbar-links > a > div.gravatar-wrapper-24'); return ($uname.length ? $uname.attr('title') : false); } }, diff --git a/sox.dialog.js b/sox.dialog.js index a930032..4ce7827 100644 --- a/sox.dialog.js +++ b/sox.dialog.js @@ -306,14 +306,17 @@ // add dialog to corral and sox button to topbar $soxSettingsButton.append($icon); - if (sox.NEW_TOPBAR) { - $('.top-bar .-container .-secondary .-item:eq(1)').after($('
  • ').addClass('-item').append($soxSettingsButton)); //https://github.com/soscripted/sox/issues/310 - $soxSettingsDialog.addClass('new-topbar'); - $soxSettingsDialog.css('top', $('.top-bar').height()); - } else { - $soxSettingsButton.appendTo('div.network-items'); - $soxSettingsDialog.css('left', $('#soxSettingsButton').position().left); + $('.top-bar .-container .-secondary .-item:eq(1)').after($('
  • ').addClass('-item').append($soxSettingsButton)); //https://github.com/soscripted/sox/issues/310 + if (sox.site.href.indexOf('area51.meta') !== -1) { //area 51 discussions is different + $soxSettingsButton.parent().css({ + 'top': '7px', + 'left': '9px' + }); } + $soxSettingsDialog.addClass('new-topbar'); + $soxSettingsDialog.css('top', $('.top-bar').height()); + + //'$('#soxSettingsButton').position().left' from @IStoleThePies: https://github.com/soscripted/sox/issues/120#issuecomment-267857625: //only add dialog if button was added successfully diff --git a/sox.features.info.json b/sox.features.info.json index 0b4ff92..63afc41 100644 --- a/sox.features.info.json +++ b/sox.features.info.json @@ -249,7 +249,7 @@ "desc": "Add a notification to your inbox when a question you downvote is edited", "meta": "http://meta.stackexchange.com/q/165962/260841", "match": "", - "exclude": "" + "exclude": "SE1.0" }], "Flags": [{ "name": "flagOutcomeTime", diff --git a/sox.features.js b/sox.features.js index 5c60004..0139c9f 100644 --- a/sox.features.js +++ b/sox.features.js @@ -970,7 +970,7 @@ //All sites have either a chat link or meta link $(this).find('.rep-score').stop(true).delay(135).fadeOut(20); - $(this).prepend('
  • '; startLoop(); } }; -})(window.sox = window.sox || {}, jQuery); \ No newline at end of file +})(window.sox = window.sox || {}, jQuery); From 944e36849c21686dc5413453e37ff1267936d5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=94=95=E1=96=BA=E1=98=8E=E1=95=8A?= Date: Fri, 15 Jun 2018 20:32:26 +0100 Subject: [PATCH 19/20] v2.1.4 DEV before push to master also adds #326 --- README.md | 5 +++++ sox.user.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 56bc4bf..bb04367 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,11 @@ A full list of all the features is available on the SOX wiki page [here](https:/ Please post bugs and feature requests as issues on [Github](https://github.com/soscripted/sox), where we can track them easily and push updates quickly. Please **do not** post them as answers on Stack Apps -- they are much harder to manage! +## Contribute + +Pull requests to add new features or improve the existing ones, etc. are welcome! Please head to the [Contributing](https://github.com/soscripted/sox/wiki/Contributing) wiki page to get started. + + ## Changes Please see the change log [at Stack Apps](http://stackapps.com/a/6358). diff --git a/sox.user.js b/sox.user.js index b2c27fe..a5a504b 100644 --- a/sox.user.js +++ b/sox.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Stack Overflow Extras (SOX) // @namespace https://github.com/soscripted/sox -// @version 2.1.13 DEV +// @version 2.1.14 DEV // @description Extra optional features for Stack Overflow and Stack Exchange sites // @contributor ᴉʞuǝ (stackoverflow.com/users/1454538/) // @contributor ᔕᖺᘎᕊ (stackexchange.com/users/4337810/) From 850bcb698289fb15820fbf0d3120b4737d32f9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=94=95=E1=96=BA=E1=98=8E=E1=95=8A?= Date: Fri, 15 Jun 2018 20:34:35 +0100 Subject: [PATCH 20/20] v2.2.0 --- sox.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sox.user.js b/sox.user.js index a5a504b..8cf8b10 100644 --- a/sox.user.js +++ b/sox.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Stack Overflow Extras (SOX) // @namespace https://github.com/soscripted/sox -// @version 2.1.14 DEV +// @version 2.2.0 // @description Extra optional features for Stack Overflow and Stack Exchange sites // @contributor ᴉʞuǝ (stackoverflow.com/users/1454538/) // @contributor ᔕᖺᘎᕊ (stackexchange.com/users/4337810/)