From f90472a0c91bb086c8685b38044cdb9cac034645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?iBug=20=E2=99=A6?= <7273074+iBug@users.noreply.github.com> Date: Tue, 15 Jan 2019 12:23:05 +0800 Subject: [PATCH 1/3] Various fixes Removed trailing whitespaces (highlighted by Tampermonkey) Removed "$ may be undefined" warning by declaring "$" as a parameter, and pass `window.jQuery` in for it Removed the 1 rep requirement on MSE, use the new contributor indicator check instead (see https://chat.meta.stackexchange.com/transcript/message/7493363#7493363) --- .../saviour-of-lost-souls.user.js | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/saviour-of-lost-souls/saviour-of-lost-souls.user.js b/saviour-of-lost-souls/saviour-of-lost-souls.user.js index be0b4d2..fd0bd83 100644 --- a/saviour-of-lost-souls/saviour-of-lost-souls.user.js +++ b/saviour-of-lost-souls/saviour-of-lost-souls.user.js @@ -5,7 +5,7 @@ // @author Glorfindel // @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 -// @version 0.2 +// @version 0.3 // @match *://meta.stackexchange.com/questions/* // @match *://meta.stackoverflow.com/questions/* // @exclude *://meta.stackexchange.com/questions/ask @@ -13,20 +13,18 @@ // @grant none // ==/UserScript== -(function () { +(function ($) { "use strict"; let question = $('#question'); - + // Check if author is likely to be a lost soul let owner = $('div.post-signature.owner'); if (owner.length == 0) // happens with Community Wiki posts return; let reputation = owner.find('span.reputation-score')[0].innerText; - if (document.location.host == 'meta.stackexchange.com') { - // Simple check: reputation = 1 - if (reputation != "1") - return; + if (reputation === "1") { + // Do nothing: 1 rep qualifies for a lost soul } else { // Other 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; @@ -43,7 +41,7 @@ return; } let isModerator = $("a.js-mod-inbox-button").length > 0; - + // Add post menu button let menu = question.find('div.post-menu'); menu.append($('|')); @@ -52,7 +50,7 @@ button.click(function() { if (!confirm('Are you sure you want to down-/close-/delete vote and post a welcoming comment?')) return; - + // Downvoted? let downvoted = question.find('a.vote-down-on').length > 0; @@ -60,12 +58,12 @@ let status = $('div.question-status h2 b'); let statusText = status.length > 0 ? status[0].innerText : ''; let closed = statusText == 'marked' || statusText == 'put on hold' || statusText == 'closed'; - + // Prepare votes/comments let postID = parseInt(question.attr('data-questionid')); console.log('Lost soul #' + postID); let fkey = window.localStorage["se:fkey"].split(",")[0]; - + // Is there any comment not by the author? let comments = question.find('ul.comments-list'); var nonOwnerComment = false; @@ -94,10 +92,10 @@ } }); } - + // You can't flag without 15 rep if (myReputation < 15) - return; + return; if (myReputation >= 100 && !downvoted) { // Downvote @@ -114,7 +112,7 @@ } }); } - + if (!closed) { // Flag/vote to close (doesn't matter for the API call) $.post({ @@ -145,7 +143,7 @@ } }); } - + // TODO: reload page after all calls are finished - }); -})(); \ No newline at end of file + }); +})(window.jQuery); From 59b10d3f4dd49a6a5880f7b3e48bac5b09179290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?iBug=20=E2=99=A6?= <7273074+iBug@users.noreply.github.com> Date: Tue, 15 Jan 2019 12:31:35 +0800 Subject: [PATCH 2/3] Also reload the page after all calls --- saviour-of-lost-souls/saviour-of-lost-souls.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saviour-of-lost-souls/saviour-of-lost-souls.user.js b/saviour-of-lost-souls/saviour-of-lost-souls.user.js index fd0bd83..1101123 100644 --- a/saviour-of-lost-souls/saviour-of-lost-souls.user.js +++ b/saviour-of-lost-souls/saviour-of-lost-souls.user.js @@ -144,6 +144,6 @@ }); } - // TODO: reload page after all calls are finished + window.location.reload(false); }); })(window.jQuery); From b30bc429670dc6c71cf28e955ac4d59c01e07c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?iBug=20=E2=99=A6?= <7273074+iBug@users.noreply.github.com> Date: Tue, 15 Jan 2019 14:33:01 +0800 Subject: [PATCH 3/3] reload later --- saviour-of-lost-souls/saviour-of-lost-souls.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saviour-of-lost-souls/saviour-of-lost-souls.user.js b/saviour-of-lost-souls/saviour-of-lost-souls.user.js index 1101123..d71155f 100644 --- a/saviour-of-lost-souls/saviour-of-lost-souls.user.js +++ b/saviour-of-lost-souls/saviour-of-lost-souls.user.js @@ -144,6 +144,6 @@ }); } - window.location.reload(false); + window.setTimeout(() => window.location.reload(false), 800); }); })(window.jQuery);