FB自動留言程式
簡易的 JavaScript 版本搜集
FB-AutoComment-JS-001
原作者
https://www.threads.com/@wa820520
功能
將同樣內容,隨機自動貼在該頁面的各個文章的留言中
使用方式
先開啟要留言的FB頁面,例如:某個喜歡的新聞網站粉專
開啟瀏覽器的開發者模式,切換到 Console 指令區
修改參數以下程式碼的參數 testdrive , commentContent,然後貼上後執行
/*
* FB自動留言程式 (FB-AutoComment-JS-001)
* credit: https://www.threads.com/@wa820520
* 使用說明: 1. 使用電腦瀏覽器,開啟開發者模式,啟用手機版頁面
* 2. 進入要自動留言的頁面, eg: oo新聞粉專
* 3. 如果需要做第一次測試,可修改以下參數: testdrive - true: 測試用,僅發一次 , false: 正式用, 頁面上所有文章, 會依照 commentProbability 機率留言
* 4. 如果需要變化內容,可修改 commentContent , decorator
*/
let testdrive=true;
let commentContent =
"#美國昌浪費大家11億\n";
let scrollBottomCount = 5;
let commentProbability = 0.3;
if( testdrive )
{
scrollBottomCount = 1;
commentProbability = 1;
}
function getCommentContent() {
const decoratorHeight = Math.floor(Math.random() * 4)
const decorator = "💰💰💰💰💰💰\n".repeat(decoratorHeight)
return decorator + commentContent + decorator;
}
function randomSleep(minMs = 10000, maxMs = 15000) {
const randomMs = Math.floor(Math.random() * (maxMs - minMs + 1)) + minMs;
return new Promise((resolve) => setTimeout(resolve, randomMs));
}
async function leaveComment() {
await randomSleep(10000, 15000);
document.querySelector("textarea").value = getCommentContent();
document
.querySelector("textarea")
.parentElement.parentElement.querySelector(
'[aria-label="發佈留言"]'
)
.click();
console.info("comment left");
await randomSleep(10000, 15000);
document.querySelector('div[aria-label="返回"]').click();
console.info("click back");
}
async function scrollBottom(times = 5) {
for (const i of [...Array(times).keys()]) {
window.scrollTo(0, document.body.scrollHeight);
console.info(`scroll bottom ${i + 1}`);
await randomSleep(8000, 12000);
}
}
async function leaveComments() {
await scrollBottom(scrollBottomCount);
const pages = document.querySelectorAll(
'div[role="button"][aria-label$="comments"]'
);
pages_num = pages.length;
for (const [i, page] of pages.entries()) {
if (Math.random() > (1 - commentProbability)) {
await randomSleep(3000, 8000);
page.click();
await leaveComment();
console.info(`page ${i + 1} of ${pages_num} leave comment`);
} else {
await randomSleep(3000, 8000);
console.info(`page ${i + 1} of ${pages_num} skipped`);
}
if( testdrive )
break;
}
}
leaveComments();
console.info("==========start execution==========");
Last updated