Skip to content

Instantly share code, notes, and snippets.

@robfrawley
Last active July 28, 2023 15:05
Show Gist options
  • Save robfrawley/b4b70049dc1d02c5bb72f5c1603d1e2f to your computer and use it in GitHub Desktop.
Save robfrawley/b4b70049dc1d02c5bb72f5c1603d1e2f to your computer and use it in GitHub Desktop.
Tool Army Community Tools
//
//
// LAST RUN: 2023-07-23
// LIKES
//
//
const handleExcept = (exception) => {
console.log('Caught an exception: ', exception);
};
const querySelects = (selector) => {
return Array.from(document.querySelectorAll(selector));
};
const rmDomElement = (element) => {
return element.parentNode.removeChild(element);
};
const padLen = (val, size = 3, char = ' ') => {
return String(typeof val == 'object' ? val.length : val).padStart(size, char);
};
const socialClicks = () => {
const sliceRandom = (arr, max, min) => {
return arr.slice(0, arr.length > max ? getRandomInt(max, min) : arr.length);
};
const clickElement = (element) => {
return element.click();
};
const postElementsLocated = querySelects('div.improvised_like_link[like-type=""]:not(.like-disable)');
const postElementsToClick = sliceRandom(postElementsLocated, 30, 5);
console.log('[socialClicks] Clicked "' + padLen(postElementsToClick.length) + '" of "' + padLen(postElementsLocated.length) + '" post social buttons ...');
try {
postElementsToClick.forEach(clickElement);
} catch(e) {
handleExcept(e);
}
return postElementsToClick.length;
};
const postRemovals = (percent = 0.4, minimum = 20) => {
let postingElements = querySelects('div.card-parent-div');
let postingDelCount = Math.max(Math.floor(postingElements.length * percent), 0);
if (postingDelCount > postingElements.length) {
postingDelCount = postingElements.length;
}
if ((postingElements.length - postingDelCount) < minimum) {
postingDelCount = Math.max(postingElements.length - minimum, 0);
}
postingElements.slice(0, postingDelCount).forEach(rmDomElement);
console.log('[postsRemoval] Removed "' + padLen(
postingDelCount
) + '" of "' + padLen(
postingElements
) + '" posts ...');
let commentElements = querySelects('div.grid-item.listMessages');
let commentDelCount = Math.max(Math.floor(commentElements.length * percent), 0);
if (commentDelCount > commentElements.length) {
commentDelCount = commentElements.length;
}
if ((commentElements.length - commentDelCount) < minimum) {
commentDelCount = Math.max(commentElements.length - minimum, 0);
}
commentElements.slice(0, commentDelCount).forEach(rmDomElement);
console.log('[postsRemoval] Removed "' + padLen(
commentDelCount
) + '" of "' + padLen(
commentElements
) + '" comments ...');
};
const scrollToBott = async () => {
let scrollToPosition = document.body.scrollHeight;
try {
console.log('[scrollToBott] Jump to "' + padLen(scrollToPosition, 12) + '" scroll position ...');
window.scrollTo(0, scrollToPosition);
} catch(e) {
handleExcept(e);
}
};
const scrollUpABit = async () => {
let scrollAtPosition = Math.floor(document.documentElement.scrollTop || document.body.scrollTop);
let scrollToPosition = scrollAtPosition - 100;
try {
//console.log('[scrollUpABit] Jump to "' + padLen(scrollToPosition, 12) + '" scroll position (from "' + padLen(scrollAtPosition, 12) + '" scroll position) ...');
window.scrollTo(0, scrollToPosition);
} catch(e) {
handleExcept(e);
}
};
const scrollClicks = async () => {
postRemovals();
scrollToBott();
socialClicks();
};
//------------------------------------------------------
const intervalMilliseconds = 2000;
const scrollClicksInterval = setInterval(
scrollClicks, Math.max(Math.floor(intervalMilliseconds * 1.00), 1000)
);
const scrollUpABitInterval = setInterval(
scrollUpABit, Math.max(Math.floor(intervalMilliseconds * 0.80), 1000)
);
//------------------------------------------------------
try { clearInterval(scrollClicksInterval); } catch(e) { console.log('ERROR:scrollClicksInterval', e); }
try { clearInterval(scrollUpABitInterval); } catch(e) { console.log('ERROR:scrollUpABitInterval', e); }
//
//
// LAST RUN: 2023-07-23
// COMMENTS
//
//
const padLen = (val, size = 3, char = '0') => {
return String(typeof val == 'object' ? val.length : val).padStart(size, char);
};
const querySelects = (selector) => {
return Array.from(document.querySelectorAll(selector));
};
const shuffleArray = (array) => {
try {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
} catch(e) {
handleExcept(e);
}
};
const handleExcept = (exception) => {
try {
console.log('Caught an exception: ', exception);
console.log('CLEARING INTERVAL! ...');
clearInterval(submitDefComInterval);
} catch(e) {
console.log('ERROR:', e);
}
};
const removePostElement = (e, i) => {
try {
let element = jQuery(e);
let comment = jQuery(element.parent().parent());
let posting = jQuery(comment.prev());
console.log('[removed-' + padLen(i, 4) + ']', comment);
comment.remove();
posting.remove();
} catch(e) {
handleExcept(e);
}
};
const subDefaultCommentElement = (e, i) => {
try {
let outter = jQuery(e);
let inputs = jQuery(outter.children('div[data-maxlength]').children('div'));
let button = jQuery(outter.children('button'));
let eMusic = ['🎵', '🎵', '🎶', '🎧', '🎸', '🎤', '🥁'];
let eTools = ['🔧', '🔧', '🔨', '🔩'];
let eFires = ['🔥', '🔥', '💣', '💥', '🎉'];
let emojis = shuffleArray(eMusic)[0] + ' + ' + shuffleArray(eTools)[0] + ' = ' + shuffleArray(eFires)[0];
inputs.html(emojis);
inputs.focus();
button.click();
console.log('[clicked-' + padLen(i, 4) + ']', outter);
setTimeout(removePostElement, 4000, outter, i);
} catch(e) {
handleExcept(e);
}
};
const submitDefCom = (size = 10) => {
try {
let elementList = querySelects('div.comment-form-outer > form').slice(1, size + 1);
elementList.forEach((e, i) => {
let milliseconds = Math.max(1600 * i, 100);
console.log('[submitDefCom] Dispatching commenter action "' + padLen(
i + 1, 2
) + '" of "' + padLen(
size > elementList.length ? elementList.length : size, 2
) + '" in "' + padLen(
milliseconds, 5
) + '" milliseconds ..."')
setTimeout(subDefaultCommentElement, milliseconds, e, i + 1);
});
setTimeout(scrollToBott, 21000);
setTimeout(scrollUpABit, 21500);
setTimeout(scrollUpABit, 22000);
setTimeout(scrollUpABit, 22500);
setTimeout(scrollUpABit, 23000);
setTimeout(scrollUpABit, 23500);
} catch (e) {
handleExcept(e);
}
};
const scrollToBott = () => {
try {
let scrollToPosition = document.body.scrollHeight;
console.log('[scrollToBott] Jump to "' + padLen(
scrollToPosition, 4
) + '" scroll position ...');
window.scrollTo(0, scrollToPosition);
} catch(e) {
handleExcept(e);
}
};
const scrollUpABit = () => {
try {
let scrollAtPosition = Math.floor(document.documentElement.scrollTop || document.body.scrollTop);
let scrollToPosition = scrollAtPosition - 40;
console.log('[scrollUpABit] Jump to "' + padLen(
scrollToPosition, 4
) + '" scroll position from "' + padLen(
scrollAtPosition, 4
) + '" scroll position ...');
window.scrollTo(0, scrollToPosition);
} catch(e) {
handleExcept(e);
}
};
//------------------------------------------------------
const intervalMilliseconds = 25000;
submitDefCom();
const submitDefComInterval = setInterval(
submitDefCom, intervalMilliseconds
);
//------------------------------------------------------
try { clearInterval(submitDefComInterval); } catch(e) { console.log('FAILUED: submitDefComInterval'); };
//------------------------------------------------------
const intervalMilliseconds = 22500;
const submitDefComInterval = setInterval(
submitDefCom, Math.max(Math.floor(intervalMilliseconds * 1.00))
);
const scrollToBottInterval = setInterval(
scrollToBott, Math.max(Math.floor(intervalMilliseconds * 4.00), 1000)
);
const scrollUpABitInterval = setInterval(
scrollUpABit, Math.max(Math.floor(intervalMilliseconds * 0.33), 1000)
);
//------------------------------------------------------
try { clearInterval(submitDefComInterval); } catch(e) { console.log('FAILUED: submitDefComInterval'); };
try { clearInterval(scrollToBottInterval); } catch(e) { console.log('FAILUED: scrollToBottInterval'); };
try { clearInterval(scrollUpABitInterval); } catch(e) { console.log('FAILUED: scrollUpABitInterval'); };
const handleExcept = (exception) => {
console.log('Caught an exception: ', exception);
};
const querySelects = (selector) => {
return Array.from(document.querySelectorAll(selector));
};
const rmDomElement = (element) => {
return element.parentNode.removeChild(element);
};
const padLen = (val, size = 3, char = ' ') => {
return String(typeof val == 'object' ? val.length : val).padStart(size, char);
};
const scrollToBotT = async (scrollToTop = true) => {
const scrollToPosition = document.body.scrollHeight;
try {
console.log('[scrollToBotT] Jump to "' + padLen(scrollToPosition, 12) + '" scroll position ...');
window.scrollTo(0, scrollToPosition);
} catch(e) {
handleExcept(e);
}
for (i = 1; i <= 4; i++) {
setTimeout(scrollUpABit, 200 + (200 * i));
}
if (scrollToTop) {
setTimeout(() => {
window.scrollTo(0, 0);
}, 1200);
}
};
const scrollUpABit = async () => {
const scrollAtPosition = Math.floor(document.documentElement.scrollTop || document.body.scrollTop);
const scrollToPosition = scrollAtPosition - 100;
try {
console.log('[scrollUpABit] Jump to "' + padLen(scrollToPosition, 12) + '" scroll position (from "' + padLen(scrollAtPosition, 12) + '" scroll position) ...');
window.scrollTo(0, scrollToPosition);
} catch(e) {
handleExcept(e);
}
};
const basicScrollAction = async ($, $$, scrollToTop = true) => {
console.log('actionScrollPostsAction: Scrolling to top and then bottom ...');
if (scrollToTop) {
window.scrollTo(0, 0);
}
setTimeout(scrollToBotT, 500, scrollToTop);
};
const actionClicksShareAction = ($, $$) => {
const t = $$('li.twitterShare > a').length;
const shareLink = $($$('li.twitterShare > a').slice(0, 1)[0]);
setTimeout(($, $$) => {
const removeHead = shareLink.parent().parent().parent().parent().parent().parent();
const removeFoot = shareLink.parent().parent().parent().parent().parent().parent().next();
console.log('removeElement:', $(removeHead), $(removeFoot))
removeFoot.remove();
removeHead.remove();
}, 2500, $, $$);
console.log('---')
console.log(`${$$('li.twitterShare > a').length}/${t}`);
const modalList = $$('.modal-dialog button.close.close-button-mymodel');
shareLink.click();
console.log('clickLink:', shareLink)
setTimeout(($) => {
modalList.slice(0, 1).forEach((e) => {
console.log('closeModal:', $(e))
e.click();
});
}, 2000, $);
};
const actionScrollPostsAction = async ($, $$) => {
const items = $$('li.twitterShare > a');
if (items.length <= 4) {
basicScrollAction($, $$);
}
};
const actionTerminatorHandler = ($, $$) => {
if ($$('li.twitterShare > a').length === 0) {
console.log('INTERVAL CHECK: TERMINATING ...');
mainActionsStop();
} else {
console.log('INTERVAL CHECK: CONTINUING ...');
}
};
// MAIN FUNCTION
let waits = 4000;
let tasks = {
sharePosts: {
interval: { handle: undefined, length: waits * 1, },
callable: actionClicksShareAction,
},
scrollPage: {
interval: { handle: undefined, length: waits * 2, },
callable: actionScrollPostsAction,
},
terminator: {
interval: { handle: undefined, length: waits * 50, },
callable: actionTerminatorHandler,
},
};
const initializeJQuery = () => {
const jq = document.createElement('script');
jq.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js';
jq.addEventListener('load', (event) => {
console.log('## Enabling jQuery no-conflict mode ...');
window.jQuery.noConflict();
});
document.getElementsByTagName('head')[0].appendChild(jq);
console.log('## Injected jQuery into document ...');
}
const initializeAction = () => {
for (const property in tasks) {
try {
tasks[property].interval.handle = setInterval(tasks[property].callable, tasks[property].interval.length, $, $$);
console.log('## Starting task interval:', property, tasks[property]);
} catch(e) {
console.log('!! Failed to start task interval:', property, e);
}
}
};
const mainActionsStop = () => {
for (const property in tasks) {
if (tasks[property].interval.handle === undefined) {
continue;
}
try {
clearInterval(tasks[property].interval.handle);
tasks[property].interval.handle = undefined;
console.log('## Stopping task interval:', property, tasks[property]);
} catch(e) {
console.log('!! Failed to clear task interval:', property, e);
}
}
};
const mainActionsInit = () => {
initializeJQuery();
initializeAction();
};
mainActionsInit();
mainActionsStop();
//
//
// LAST RUN: 2023-07-23
// JQUERY INJECTOR
//
//
const initializeJQuery = () => {
const jq = document.createElement('script');
jq.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js';
jq.addEventListener('load', (event) => {
console.log('## Enabling jQuery no-conflict mode ...');
window.jQuery.noConflict();
});
document.getElementsByTagName('head')[0].appendChild(jq);
console.log('## Injected jQuery into document ...');
}
initializeJQuery();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment