Last active
January 29, 2020 13:04
-
-
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.
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
| 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