Skip to main content

getSelectedText

0 likes • Nov 18, 2022 • 0 views
JavaScript
Loading...

More JavaScript Posts

getURLParameters

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

Redux Setup

CHS
0 likes • Mar 11, 2021 • 0 views
JavaScript
import { configureStore } from "@reduxjs/toolkit";
import { combineReducers } from "redux";
import profile from "./profile";
import auth from "./auth";
import alert from "./alert";
const reducer = combineReducers({
profile,
auth,
alert,
});
const store = configureStore({ reducer });
export default store;

Mongoose Model

CHS
0 likes • Mar 11, 2021 • 0 views
JavaScript
const mongoose = require('mongoose')
const UserSchema = new mongoose.Schema({
username: {
type: String,
required: true
},
email: {
type: String,
unique: true,
required: true
},
password: {
type: String,
required: true
},
date: {
type: Date,
default: Date.now
}
})
module.exports = User = mongoose.model('user', UserSchema)

QM Helper

0 likes • Mar 22, 2022 • 1 view
JavaScript
//QM Helper by Leif Messinger
//Groups numbers by number of bits and shows their binary representations.
//To be used on x.com
const minterms = prompt("Enter your minterms separated by commas").split(",").map(x => parseInt(x.trim()));
const maxNumBits = minterms.reduce(function(a, b) {
return Math.max(a, Math.log2(b));
});
const bitGroups = [];
for(let i = 0; i < maxNumBits; ++i){
bitGroups.push([]);
}
for(const minterm of minterms){
let outputString = (minterm+" ");
//Count the bits
let count = 0;
for (var i = maxNumBits; i >= 0; --i) {
if((minterm >> i) & 1){
++count;
outputString += "1";
}else{
outputString += "0";
}
}
bitGroups[count].push(outputString);
}
document.body.textContent = "";
document.body.style.setProperty("white-space", "pre");
for(const group of bitGroups){
for(const outputString of group){
document.body.textContent += outputString + "\r\n";
}
}

Reddit Regex Comment Upvoter

0 likes • May 17, 2021 • 2 views
JavaScript
//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();

Zybooks?

0 likes • Oct 29, 2020 • 2 views
JavaScript
questions = Array.from(document.querySelectorAll(".multiple-choice-question"));
async function hackRadio(question){
if(question.querySelector(".question-chevron").getAttribute("aria-label") == "Question completed") return;
let answerChoices = question.querySelectorAll(".zb-radio-button");
async function guess(answerChoice){
answerChoice.querySelector("label").click();
}
let pause = 0;
for(let answerChoice of answerChoices){
setTimeout(()=>{guess(answerChoice)},pause); //No need to check given that it will record the correct answer anyways.
pause += 1000;
}
}
for(let question of questions){
hackRadio(question);
}
questions = Array.from(document.querySelectorAll(".short-answer-question"));
async function hackShortAnswer(question){
if(question.querySelector(".question-chevron").getAttribute("aria-label") == "Question completed") return;
question.querySelector("textarea").value = question.querySelector(".forfeit-answer").textContent;
//question.querySelector(".check-button").click(); They are smart bastards
}
for(let question of questions){
const showAnswerButton = question.querySelector(".show-answer-button");
showAnswerButton.click();
showAnswerButton.click();
hackShortAnswer(question);
}