Merge branch 'master' into patch-2

This commit is contained in:
Glorfindel83 2019-01-15 19:25:27 +01:00 committed by GitHub
commit 97db76181d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,7 +5,7 @@
// @author Glorfindel // @author Glorfindel
// @updateURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/saviour-of-lost-souls/saviour-of-lost-souls.user.js // @updateURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/saviour-of-lost-souls/saviour-of-lost-souls.user.js
// @downloadURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/saviour-of-lost-souls/saviour-of-lost-souls.user.js // @downloadURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/saviour-of-lost-souls/saviour-of-lost-souls.user.js
// @version 0.2 // @version 0.3
// @match *://meta.stackexchange.com/questions/* // @match *://meta.stackexchange.com/questions/*
// @match *://meta.stackoverflow.com/questions/* // @match *://meta.stackoverflow.com/questions/*
// @exclude *://meta.stackexchange.com/questions/ask // @exclude *://meta.stackexchange.com/questions/ask
@ -13,22 +13,20 @@
// @grant none // @grant none
// ==/UserScript== // ==/UserScript==
(function () { (function ($) {
"use strict"; "use strict";
let question = $('#question'); let question = $('#question');
// Check if author is likely to be a lost soul // Check if author is likely to be a lost soul
let owner = $('div.post-signature.owner'); let owner = $('div.post-signature.owner');
if (owner.length == 0) if (owner.length == 0)
// happens with Community Wiki posts // happens with Community Wiki posts
return; return;
let reputation = owner.find('span.reputation-score')[0].innerText; let reputation = owner.find('span.reputation-score')[0].innerText;
if (document.location.host == 'meta.stackexchange.com') { if (reputation === "1") {
// Simple check: reputation = 1 // Do nothing: 1 rep qualifies for a lost soul
if (reputation != "1")
return;
} else { } else {
// Other meta sites require some reputation to post a question, so we need other rules: // Child meta sites require some reputation to post a question, so we need other rules:
let isNewContributor = owner.find('span.js-new-contributor-label').length > 0; let isNewContributor = owner.find('span.js-new-contributor-label').length > 0;
let hasLowReputation = reputation <= 101; // association bonus let hasLowReputation = reputation <= 101; // association bonus
let negativeQuestionScore = parseInt(question.find('div.js-vote-count').text()) < 0; let negativeQuestionScore = parseInt(question.find('div.js-vote-count').text()) < 0;
@ -43,7 +41,7 @@
return; return;
} }
let isModerator = $("a.js-mod-inbox-button").length > 0; let isModerator = $("a.js-mod-inbox-button").length > 0;
// Add post menu button // Add post menu button
let menu = question.find('div.post-menu'); let menu = question.find('div.post-menu');
menu.append($('<span class="lsep">|</span>')); menu.append($('<span class="lsep">|</span>'));
@ -52,7 +50,7 @@
button.click(function() { button.click(function() {
if (!confirm('Are you sure you want to down-/close-/delete vote and post a welcoming comment?')) if (!confirm('Are you sure you want to down-/close-/delete vote and post a welcoming comment?'))
return; return;
// Downvoted? // Downvoted?
let downvoted = question.find('a.vote-down-on').length > 0; let downvoted = question.find('a.vote-down-on').length > 0;
@ -60,12 +58,12 @@
let status = $('div.question-status h2 b'); let status = $('div.question-status h2 b');
let statusText = status.length > 0 ? status[0].innerText : ''; let statusText = status.length > 0 ? status[0].innerText : '';
let closed = statusText == 'marked' || statusText == 'put on hold' || statusText == 'closed'; let closed = statusText == 'marked' || statusText == 'put on hold' || statusText == 'closed';
// Prepare votes/comments // Prepare votes/comments
let postID = parseInt(question.attr('data-questionid')); let postID = parseInt(question.attr('data-questionid'));
console.log('Lost soul #' + postID); console.log('Lost soul #' + postID);
let fkey = window.localStorage["se:fkey"].split(",")[0]; let fkey = window.localStorage["se:fkey"].split(",")[0];
// Is there any comment not by the author? // Is there any comment not by the author?
let comments = question.find('ul.comments-list'); let comments = question.find('ul.comments-list');
var nonOwnerComment = false; var nonOwnerComment = false;
@ -105,10 +103,10 @@
} }
} }
}); });
// You can't flag without 15 rep // You can't flag without 15 rep
if (myReputation < 15) if (myReputation < 15)
return; return;
if (myReputation >= 100 && !downvoted) { if (myReputation >= 100 && !downvoted) {
// Downvote // Downvote
@ -125,7 +123,7 @@
} }
}); });
} }
if (!closed) { if (!closed) {
// Flag/vote to close (doesn't matter for the API call) // Flag/vote to close (doesn't matter for the API call)
$.post({ $.post({
@ -156,7 +154,8 @@
} }
}); });
} }
// TODO: reload page after all calls are finished // Reload page; this is less elegant than waiting for all POST calls but it works.
}); window.setTimeout(() => window.location.reload(false), 800);
})(); });
})(window.jQuery);