Last active
August 21, 2019 22:24
-
-
Save figloalds/83b63bd9ab0bbe5a30f4670750fde7b1 to your computer and use it in GitHub Desktop.
This file contains 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
if(!HATE_IS_DEFINED) { | |
const commentFilter = [ | |
'top fan', 'badge', 'contributor', 'peasant', 'flex', | |
'esbanja', 'selo', 'super fã', ' ostent', | |
'💎', '⊂_', | |
]; | |
class Hate { | |
constructor() { | |
const POST_ROOT_SELECTOR = '._5jmm._5pat'; | |
const LIVE_INDICATOR_SELECTOR = 'div[data-testid=live-indicator]'; | |
const WATCH_PARTY_INDICATOR1 = '._7vkb._7w5s'; | |
const WATCH_PARTY_INDICATOR2 = '._6sm7._6ruq'; | |
const POST_TEXT_SELECTOR = 'div[data-testid=post_message]'; | |
const STORY_SUBTITLE_SELECTOR = '.fsm.fwn.fcg'; | |
this.addHate('badgeBitches', { | |
init: ()=> ({ | |
filter: commentFilter | |
}), | |
update: (ctx) => { | |
// Only comments from Super fans and Great Contributors will be | |
// subjected to filtering | |
const qsa2 = document.querySelectorAll('._7w_c'); | |
qsa2.forEach(elt => { | |
// From these comments I'll extract the "comment" part of the comment | |
// and the "Bitch name" | |
const commentRoot = elt.closest('._4eek').closest('li'); | |
if(elt.style.display === 'none' && commentRoot.querySelector('._5v47.fss')) { | |
return; | |
} | |
const commentElt = commentRoot.querySelector('._3l3x span'); | |
const bitchNameElt = commentRoot.querySelector('._6qw4'); | |
if (commentElt) { | |
const comment = commentElt.textContent.toLowerCase(); | |
// Here we will determine if the bitch is bragging or not | |
// Using the filter above. | |
if (ctx.filter.find(a => comment.indexOf(a) > -1)) { | |
// bitch is bragging | |
commentRoot.remove(); | |
let bitchWhoCommented = (bitchNameElt && bitchNameElt.textContent) || '<couldn\'t get bitch\'s name>'; | |
console.log(`Bitch comment removed:\n${bitchWhoCommented}: ${comment}\n----------------------------------`); | |
} else { | |
// bitch doesn't seem to be bragging, | |
// Just remove the badge | |
console.log('Badge removed', (bitchNameElt && bitchNameElt.textContent)); | |
elt.remove(); | |
if(!commentRoot.querySelector('._5v47.fss')) { | |
elt.remove(); | |
} else { | |
elt.style.display = 'none'; | |
} | |
} | |
} | |
}); | |
} | |
}); | |
console.log("Init Done"); | |
} | |
hateHandler(obj) { | |
return { | |
...obj, | |
active: true | |
}; | |
}; | |
hateHandlers = []; | |
hateTimeoutHandle; | |
addHate (name, obj) { | |
try { | |
if(!obj.init || !obj.update) { | |
console.log(`Init obj for ${name} needs 'init' and 'update' functions`, err); | |
} | |
const handler = this.hateHandler(obj); | |
this.hateHandlers.push( | |
handler | |
); | |
window[`_hate_${name}`] = handler; | |
handler.context = handler.init(); | |
console.log(`Hate added ${name}`); | |
return handler; | |
} catch(err) { | |
console.log(`Error initializing HATRED handle: ${name}`, err); | |
} | |
} | |
hateTick(self) { | |
window['console']['warn'] = () => {}; | |
window['console']['error'] = () => {}; | |
self.hateTimeoutHandle = setTimeout(()=> { | |
self.hateHandlers.forEach((handler)=> { | |
try { | |
handler.update(handler.context); | |
} catch (err) { | |
console.log(`Error executing: ${name} (${handler.errCnt++} errors)`, err); | |
if(handler.errCnt > 12) { | |
handler.active = false; | |
} | |
} | |
}); | |
self.hateHandlers = self.hateHandlers.filter(h=> h.active); | |
self.hateTimeoutHandle = setTimeout(()=> self.hateTick(self), 2000); | |
}) | |
}; | |
startHate() { | |
this.hateTick(this); | |
} | |
} | |
new Hate().startHate(); | |
} | |
var HATE_IS_DEFINED = 1; | |
// Made with 😡 by Felype Rennan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment