Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
shu8 committed Jun 28, 2018
1 parent 9ccf8df commit 47c7432
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion sox.features.info.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
"exclude": "SE1.0"
}, {
"name": "disableVoteButtons",
"desc": "Disable vote buttons on posts you cannot vote on",
"desc": "Disable vote buttons on your own posts and deleted posts, which you cannot vote on",
"meta": "",
"match": "*://*/questions*",
"exclude": "SE1.0"
Expand Down
68 changes: 40 additions & 28 deletions sox.features.js
Original file line number Diff line number Diff line change
Expand Up @@ -2443,8 +2443,8 @@
},

disableVoteButtons: function() {
// Description: disables vote buttons on posts you cannot vote on
// https://github.com/soscripted/sox/issues/309
// Description: disables vote buttons on your own or deleted posts, which you cannot vote on
// https://github.com/soscripted/sox/issues/309, https://github.com/soscripted/sox/issues/335

//Grays out votes, vote count for deleted posts
if ($('.deleted-answer').length) {
Expand All @@ -2469,25 +2469,6 @@
'pointer-events': 'none' //disables the anchor tag (jQuery off() doesn't work)
})
.parent().attr('title', 'You cannot vote on your own posts.'); //.parent() is to add the title to the .vote div

//Grays out votes on posts which haven't been edited in the last 5 minutes
$('.answer, .question').not('.owner').each(function() {
if (!$(this).find('.vote-up-on, .vote-down-on').length) return; //if they haven't voted, no point checking
var $timeSpan = $(this).find('.user-action-time:first span:last'),
lastEditedTime = new Date($timeSpan.attr('title')),
timeDifference = new Date() - lastEditedTime;
if (timeDifference / 1000 / 60 > 5) { //divide by 1000 to get seconds, divide by 60 to get minutes
$(this).find('.votecell .vote a[class*="vote"]')
.not('[id*="vote-accept"]')
.removeClass('sox-better-css')
.css({
'cursor': 'default',
'opacity': '0.5',
'pointer-events': 'none' //disables the anchor tag (jQuery off() doesn't work)
});
$(this).find('.vote').attr('title', 'SOX: You cannot change your vote on posts that were last edited more than 5 minutes ago.');
}
});
},

replyToOwnChatMessages: function() {
Expand Down Expand Up @@ -2842,17 +2823,48 @@

let r = new FileReader();
r.onload = function(image) {
$.ajax({ //TODO: use stack imgur API?
url: 'https://api.imgur.com/3/image',
headers: {
'Authorization': 'Client-ID e54d6bf725000d6'
},
/*NOTE: the image can either be uploaded to SE's imgur account using the undocumented API,
or using the normal imgur API. If the SE approach ever stops working, use the following instead:
$.ajax({
+ url: 'https://api.imgur.com/3/image',
+ headers: {
+ 'Authorization': 'Client-ID e54d6bf725000d6' //this is @shu8's for SOX
+ },
+ type: 'POST',
+ data: {
+ 'image': image.target.result.split(',')[1] //remove the 'data:...''
+ },
+ success: function(data) {
+ let link = data.data.link;
+ $(e.target).insertText('![image](' + link + ')', $(e.target).getSelection().start); //rangyinputs!
+ },
+ error: function(data) {
+ sox.error(data);
+ alert("Sorry, there was an error uploading the image to Imgur.");
+ }
+ });
*/
$.ajax({
url: 'https://meta.stackexchange.com/upload/image?https=true',
type: 'POST',
data: {
'image': image.target.result.split(',')[1] //remove the 'data:...''
'fkey': $('#fkey').val(),
'source': 'computer',
'filename': 'image.png',
'upload-url': image.target.result.split(',')[1] //remove the 'data:...''
},
success: function(data) {
let link = data.data.link;
/*NOTE: data === `<html>
<head>
<script>
window.parent.closeDialog("https://i.stack.imgur.com/blah.png");
</script>
</head>
<body></body>
</html>`
*/
//NOTE: the following extracts the link from the response. it's messy, could probably be better!
let link = JSON.stringify($($(data)[1]).html()).match(/(http.*?)"/)[1].replace("\\", "");
$(e.target).insertText('![image](' + link + ')', $(e.target).getSelection().start); //rangyinputs!
},
error: function(data) {
Expand Down
2 changes: 1 addition & 1 deletion sox.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Stack Overflow Extras (SOX)
// @namespace https://github.com/soscripted/sox
// @version 2.2.4 DEV
// @version 2.2.5 DEV
// @description Extra optional features for Stack Overflow and Stack Exchange sites
// @contributor ᴉʞuǝ (stackoverflow.com/users/1454538/)
// @contributor ᔕᖺᘎᕊ (stackexchange.com/users/4337810/)
Expand Down

0 comments on commit 47c7432

Please sign in to comment.