Last active
June 26, 2021 01:07
-
-
Save Ruffo324/391e61d8656a66a6cb1c926e809cb7f9 to your computer and use it in GitHub Desktop.
Add ✅ to all Discussions without any award on GitLab merge-request pages..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creation date: 26.06.2021. Tested with GitLab version: 14.0.0 | |
var timer = ms => new Promise(res => setTimeout(res, ms)) | |
var emojiButtons = [...document.querySelectorAll('.note-actions > .emoji-picker button')]; | |
var runtimeStuff = { | |
stop: false, | |
discussions: { | |
withAward: 0, | |
withoutAward: 0 | |
} | |
}; | |
async function blink(elm) { | |
const speedMs = 250; | |
let prio = emojiButtons[0].style.getPropertyPriority("background"); | |
let value = emojiButtons[0].style.getPropertyValue("background"); | |
setTimeout(() => { | |
elm.style.setProperty("background", "#FF00FF", "important"); | |
setTimeout(() => { | |
elm.style.setProperty("background", value, prio); | |
} | |
, speedMs); | |
} | |
, speedMs); | |
await timer(2 * speedMs); | |
} | |
async function scrollElement(elm) { | |
await elm.scrollIntoView({ | |
behavior: "smooth", | |
block: "center", | |
inline: "center", | |
}); | |
} | |
async function doForEmojiButton(emojiButton) { | |
const waitStepsMs = 120; | |
await scrollElement(emojiButton); | |
await timer(waitStepsMs); | |
await blink(emojiButton); | |
var discussionBody = emojiButton.closest(".notes"); | |
var foundAwards = [...discussionBody.querySelectorAll(".awards")]; | |
if (foundAwards.length > 0) { | |
runtimeStuff.discussions.withAward++; | |
return; | |
} | |
runtimeStuff.discussions.withoutAward++; | |
emojiButton.click(); | |
await timer(waitStepsMs); | |
var checkEmoji = [...document.querySelectorAll('.gl-new-dropdown-inner gl-emoji[data-name="white_check_mark"]')][0]; | |
await scrollElement(checkEmoji); | |
await timer(waitStepsMs); | |
checkEmoji.click(); | |
await timer(waitStepsMs); | |
} | |
async function work() { | |
runtimeStuff.stop = false; | |
for (var emojiButton of emojiButtons) { | |
await doForEmojiButton(emojiButton); | |
// await logStuff(); | |
if (runtimeStuff.stop) | |
return; | |
} | |
} | |
async function logStuff() { | |
console.debug(runtimeStuff); | |
} | |
function Stop() { | |
runtimeStuff.stop = true; | |
} | |
document.body.click(); // CLose existing emoji picker windows! | |
work(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment