Skip to content

Instantly share code, notes, and snippets.

View Octagon-simon's full-sized avatar
Turning red flags into red tests that pass.

Simon Ugorji (Octagon) Octagon-simon

Turning red flags into red tests that pass.
View GitHub Profile
let highlight = (word) => {
//get web page contents
let str = document.body.innerHTML.toString();
//search and replace
str = str.replaceAll( new RegExp(word, 'gi'), `<span style='background-color:red;color:#fff'>${word}</span>` );
//rebuild the webpage
document.body.innerHTML = str;
}
//invoke function
highlight("Simon");
const search = (search, replace) => {
//the string
const str = "I love to eat banana and mango";
//replace all occurrences of the searched term
return str.replaceAll( new RegExp(search, 'gi'), replace );
}
//invoke the function
console.log( search('BANANA', '🍌') );
console.log( search('MANGO', '🥭') );
//the string
const str = "My name is simon ugorji";
//using match method on it with the modifier
console.log(str.match(new RegExp('Simon', 'i')));
//the string
const str = "My name is simon ugorji";
//using match method on it
console.log(str.match(new RegExp('simon')));
//the string
const str = "My name is simon ugorji";
//using match method on it
console.log(str.match(/simon/));
//the string
const str = "My name is simon ugorji";
//using match method on it
console.log(str.match('simon'));
//attach event listener
document.querySelector('#inp_search').addEventListener('input', function(){
//store the search query
let value = this.value.trim();
//check if value is not empty
if(value){
//store matching record IDs
let matchingIDs = [];
//loop index
let ind = 1;
//get url
const pageUrl = window.location.href;
//get sitekey
const siteKey = document.querySelector('[data-sitekey]').getAttribute('data-sitekey');
//invoke the solve captcha function
solveCaptcha(siteKey, pageUrl);
function solveCaptcha(siteKey, pageUrl){
//make printing text easier
let log = (text) => {console.log(text)};
let logErr = (text) => {console.error(text)};
//your api key
const apiKey = "YOUR_API_KEY";
//make a GET request to 2captcha
fetch(`https://2captcha.com/in.php?key=${apiKey}&method=userrecaptcha
&googlekey=${siteKey}&pageurl=${pageUrl}&json=1`)
function solveCaptcha(siteKey, pageUrl){
const apiKey = "YOUR_API_KEY";
//make a GET request to 2captcha
fetch(`https://2captcha.com/in.php?key=${apiKey}
&method=userrecaptcha&googlekey=${siteKey}&pageurl=${pageUrl}&json=1`)
.then(response => response.json())
.then(data => {
//check if there's an error
if(!data.status){
//print out error