Skip to content

Instantly share code, notes, and snippets.

@lovetingyuan
Last active July 11, 2024 18:09
Show Gist options
  • Save lovetingyuan/9a9c1527dbc7fb94c2fea00973fe0bfd to your computer and use it in GitHub Desktop.
Save lovetingyuan/9a9c1527dbc7fb94c2fea00973fe0bfd to your computer and use it in GitHub Desktop.
Remove twitter ad in browser with tampermonkey
// 让广告隐藏
const style = document.createElement('style')
style.textContent = `
div[data-testid="cellInnerDiv"]:has(path[d="M19.498 3h-15c-1.381 0-2.5 1.12-2.5 2.5v13c0 1.38 1.119 2.5 2.5 2.5h15c1.381 0 2.5-1.12 2.5-2.5v-13c0-1.38-1.119-2.5-2.5-2.5zm-3.502 12h-2v-3.59l-5.293 5.3-1.414-1.42L12.581 10H8.996V8h7v7z"]) {
display: none!important;
}
`
document.head.appendChild(style)
// 支持视频直接跳转
document.addEventListener('click', (event) => {
if (event.target.tagName === 'SPAN' && event.target.textContent === '复制视频地址') {
const article = event.target.closest('article')
const a = [...article.querySelectorAll('a[href]')].find(a => /\/status\/\d+$/.test(a.href))
const r = encodeURIComponent(`https://x.com/i/status/${a.href.split('/').pop()}`)
window.open('https://twitter-video-url.tingyuan.workers.dev/api/twitter-video-url?videourl=' + r, '_blank')
}
}, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment