Click outside tweet to close it

Adds a trigger to the outside of the tweet to be able to quickly close them. Allowing for a far more comfortable experience.

// ==UserScript==
// @name     Click outside tweet to close it
// @description Adds a trigger to the outside of the tweet to be able to quickly close them. Allowing for a far more comfortable experience.
// @version  1.2
// @include  https://twitter.com/*
// @grant    none
// @namespace https://greasyfork.dpdns.org/users/577280
// ==/UserScript==

function attemptBack(){
    const btn = document.querySelector('[aria-label="Back"]');
    const close = document.querySelector('[aria-label="Close"]');
  	//Don't close when in image view as it's already handled by Twitter.
  
   if(btn !== null && close === null && window.location.toString().includes('/status/'))
        btn.click()
}

let leftShit, rightShit;
document.querySelector("#react-root").addEventListener("click", e => {
    leftShit = leftShit || document.querySelector(".r-1rnoaur");
    rightShit = rightShit || document.querySelector(".r-2llsf");
    //Jeez I fucking despise these cryptic names. Thank god for aria lables.
    const role = e.target.getAttribute("role")
    if(role === "banner" || role === "main" || e.target == rightShit || e.target == leftShit)
        attemptBack();
});
长期地址
遇到问题?请前往 GitHub 提 Issues,或加Q群1031348184

赞助商

Fishcpy

广告

Rainyun

注册一下就行

Rainyun

一年攒够 12 元