Skip to main content

Destructuring Assignment

Nov 19, 2022CodeCatch
Loading...

More JavaScript Posts

Mee6 Spam Calculator

Mar 10, 2022LeifMessinger

0 likes • 1 view

//Use at https://mee6.xyz/leaderboard/732262089447702588
//Higher the spammy stat, the more spammy that person is.
//This is because mee doesn't give experience to people who post more comments in a minute.
function statBlock(title, value){
let elm = document.createElement("div");
elm.className = "leaderboardPlayerStatBlock";
let titleElm = document.createElement("div");
titleElm.className = "leaderboardPlayerStatName";
titleElm.textContent = title;
let valueElm = document.createElement("div");
valueElm.className = "leaderboardPlayerStatValue";
valueElm.textContent = value;
elm.appendChild(titleElm);
elm.appendChild(valueElm);
elm.remove = function(){
this.parentElement.removeChild(this);
}
return elm;
}
for(let player of Array.from(document.getElementsByClassName("leaderboardPlayer"))){
if(player.spamminess) player.spamminess.remove();
let messages = null;
let experience = null;
const statBlockArray = Array.from(player.querySelectorAll(".leaderboardPlayerStatBlock"));
for(let statBlock of statBlockArray){
const statName = statBlock.querySelector(".leaderboardPlayerStatName").textContent;
const text = statBlock.querySelector(".leaderboardPlayerStatValue").textContent;
const number = ((text.includes("k"))? (text.replace("k","") * 1000.0) : +(text));
if(statName.includes("MESSAGES")){
messages = number;
}else if(statName.includes("EXPERIENCE")){
experience = number;
}
}
const stats = player.querySelector(".leaderboardPlayerStats");
const messagesElement = stats.firstChild;
const spamminess = ((messages/experience)*2000.0).toFixed(2);
player.spamminess = stats.insertBefore(statBlock("SPAMMINESS", spamminess), messagesElement);
}

linear search

Nov 19, 2022CodeCatch

0 likes • 0 views

const linearSearch = (arr, item) => {
for (const i in arr) {
if (arr[i] === item) return +i;
}
return -1;
};
linearSearch([2, 9, 9], 9); // 1
linearSearch([2, 9, 9], 7); // -1

JS Test

Mar 9, 2021LeifMessinger

0 likes • 1 view

alert("bruh")

getURLParameters

Nov 19, 2022CodeCatch

0 likes • 1 view

const getURLParameters = url =>
(url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce(
(a, v) => (
(a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a
),
{}
);

count substrings

Nov 19, 2022CodeCatch

0 likes • 0 views

const countSubstrings = (str, searchValue) => {
let count = 0,
i = 0;
while (true) {
const r = str.indexOf(searchValue, i);
if (r !== -1) [count, i] = [count + 1, r + 1];
else return count;
}
};
countSubstrings('tiktok tok tok tik tok tik', 'tik'); // 3
countSubstrings('tutut tut tut', 'tut'); // 4

Reddit Regex Comment Upvoter

May 17, 2021LeifMessinger

0 likes • 2 views

//Upvotes comments according to a regex pattern. I tried it out on https://www.reddit.com/r/VALORANT/comments/ne74n4/please_admire_this_clip_precise_gunplay_btw/
//Known bugs:
//If a comment was already upvoted, it gets downvoted
//For some reason, it has around a 50-70% success rate. The case insensitive bit works, but I think some of the query selector stuff gets changed. Still, 50% is good
let comments = document.getElementsByClassName("_3tw__eCCe7j-epNCKGXUKk"); //Comment class
let commentsToUpvote = [];
const regexToMatch = /wtf/gi;
for(let comment of comments){
let text = comment.querySelector("._1qeIAgB0cPwnLhDF9XSiJM"); //Comment content class
if(text == undefined){
continue;
}
text = text.textContent;
if(regexToMatch.test(text)){
console.log(text);
commentsToUpvote.push(comment);
}
}
function upvote(comment){
console.log(comment.querySelector(".icon-upvote")); //Just showing you what it's doing
comment.querySelector(".icon-upvote").click();
}
function slowRecurse(){
let comment = commentsToUpvote.pop(); //It's gonna go bottom to top but whatever
if(comment != undefined){
upvote(comment);
setTimeout(slowRecurse,500);
}
}
slowRecurse();