Skip to content

Instantly share code, notes, and snippets.

@mjgargani
Last active January 29, 2020 13:04
Show Gist options
  • Select an option

  • Save mjgargani/32be589caa1bf98434597be7718e3a4c to your computer and use it in GitHub Desktop.

Select an option

Save mjgargani/32be589caa1bf98434597be7718e3a4c to your computer and use it in GitHub Desktop.
Bloqueador de posts patrocinados no novo template do fb (2020). A implementação vai de cada um.
const interval = 250; // Em ´ms´ (valor muito baixo vai gerar lag na navegação)
let SB = null;
// seletor Xpath
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function iniciarSB() {
console.log('SponsorBlock iniciado', new Date().toLocaleString());
if(!SB){
SB = setInterval(()=>{
try{
// Na falta de um padrão melhor, esse seletor muito provavelmente vai gerar falsos positivos.
// Mas em geral ele se sai bem.
let aux = getElementByXpath("//span[contains(., 'Patrocinado')]");
aux.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.remove();
console.log('Promoção bloqueada');
}catch(e){}
},interval);
}
}
function pararSB() {
clearInterval(SB);
SB=null;
console.log('SponsorBlock pausado', new Date().toLocaleString());
}
iniciarSB();
// Na teoria, o timer só vai funcionar durante a navegação no fb
window.addEventListener('focus', iniciarSB);
window.addEventListener('blur', pararSB);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment