Last active
January 3, 2020 16:48
-
-
Save neihousaigaai/d60bf4ecb4b9835a4be9b656000b72c0 to your computer and use it in GitHub Desktop.
userjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Facebook comment filter | |
// @description As name | |
// @license MIT; http://opensource.org/licenses/MIT | |
// @include /^https?://(www\.)?facebook.com(/.*)?$/ | |
// @version 1.0.0 | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
// clone from https://github.com/Sharparam/UserScripts/blob/master/fb_comment_cleaner.user.js | |
var patterns = [ | |
/^Cực k[ìỳ] thuyết phục$/, | |
/^[\.,]+$/, /(chấm|\.) ?hóng/, /chấm+/, /xin 1 slot/, /^(xin )?ké$/, /^cùng (thắc mắc|câu hỏi)$/, /^quan tâm$/, | |
/k.*è.*[o0] ?(bóng|nhau|lên)? ?(free|miễn phí)?/, | |
/lên k.*è.*[o0]/, | |
/may tuần trước được bạn giới thiệu theo kèo/, | |
/trước giờ chơi bóng thua nhiều, may theo .+ về bờ luôn/, | |
/chơi thua tha cá độ bóng đá mà chưa về bờ thì mình biết/, | |
/fb .+ tham khảo kèo/, | |
/fb .+ lên kèo bóng rất là chuẩn/, | |
/kèo lên rất chuẩn/, | |
/KÈO CHẤT - KHÔNG CẦN NÓI NHIỀU/, | |
/kèo trên fb/, | |
/cá độ/, | |
/Hiếm thấy có ông nào Dự Đoán kết quả bóng đá chuẩn như ông này/ | |
]; | |
function isValidComment(text) { | |
for (var ptn_id = 0; ptn_id < patterns.length; ptn_id++) { | |
var pattern = patterns[ptn_id]; | |
if (text.match(new RegExp(pattern, 'gim'))) { | |
console.log("-> " + pattern + "\n" + text); | |
return false; | |
} | |
} | |
return true; | |
} | |
function cleanComments() { | |
/* | |
var comments = document.querySelectorAll('li > div > div[data-testid^="UFI2Comment/root_depth"]'); | |
// console.log(comments); | |
for (var cIdx = 0; cIdx < comments.length; cIdx++) { | |
var comment = comments[cIdx]; | |
var body = comment.querySelector('div[data-testid="UFI2Comment/body"] span > span > span'); | |
// console.log(comment.innerHTML); | |
console.log(body); | |
if (body === null) { | |
continue; | |
} | |
var isValid = true; | |
var contents = body.textContent; | |
// code | |
} | |
*/ | |
for (var root_depth_id = 0; root_depth_id <= 1; root_depth_id++) { | |
var subcomments = document.querySelectorAll('li > div > div[data-testid^="UFI2Comment/root_depth_' + root_depth_id.toString() + '"]'); | |
// console.log(subcomments); | |
for (var scIdx = 0; scIdx < subcomments.length; scIdx++) { | |
var comment = subcomments[scIdx]; | |
// console.log(comment + "\n" + comment.parent); | |
// var li_comment_box = comment.parent; | |
// console.log(comment.innerHTML); | |
// console.log(comment.querySelector("div div").innerHTML); | |
var body = comment.querySelector('div[data-testid="UFI2Comment/body"] div span > span'); | |
if (body === null) { | |
continue; | |
} | |
var contents = body.childNodes; // body.textContent; | |
// console.log("content = " + contents); // test: https://www.facebook.com/groups/sguet/?ref=bookmarks | |
var comment_box = comment.querySelector('div[data-testid="UFI2Comment/body"] div span > span > span'); | |
if (contents === null || comment_box === null) { | |
continue; | |
} | |
var text_content = body.innerHTML; | |
var isValid = isValidComment(text_content) && isValidComment(comment_box.innerHTML); | |
// console.log(text_content + " " + isValidComment(text_content)); | |
if (isValid) { | |
var is_full_tag = true; | |
for (var i = 0; i < contents.length; i++) { | |
var element = contents[i]; | |
var name = element.tagName; | |
var cls = element.className; | |
var text = element.textContent ? element.textContent.trim() : (element.innerText ? element.innerText.trim() : null); | |
// console.log(element + " " + element["data-hovercard"]); | |
if (name !== 'A' && cls !== 'profileLink' && !(name === "SPAN" && cls === "whitespace")) { | |
is_full_tag = false; | |
} | |
} | |
console.log(is_full_tag); | |
} | |
if (!isValid || is_full_tag) { | |
/* | |
if (root_depth_id == 0) { | |
li_comment_box.remove(); | |
} else { | |
comment.remove(); | |
} | |
*/ | |
comment.remove(); | |
// console.log("removed " + contents); | |
} | |
} | |
} | |
} | |
window.onload = function() { | |
// Create a button the user can use to clean the comments | |
var html = '<button style="position: fixed; top: 10px; left: 10px; z-index: 700;">Clean comments</button>'; | |
var frag = document.createDocumentFragment(); | |
var temp = document.createElement('div'); | |
temp.innerHTML = html; | |
var btn = temp.firstChild; | |
btn.onclick = function() { cleanComments(); }; | |
document.body.appendChild(btn); | |
cleanComments(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment