Greasy Fork is available in English.
Automatic closure of Twitter webpage's media warning.
当前为
// ==UserScript==
// @name Close Twitter Media Warning
// @name:ja Close Twitter Media Warning
// @name:zh-cn 关闭 Twitter 媒体警告
// @name:zh-tw 關閉 Twitter 媒體警告
// @description Automatic closure of Twitter webpage's media warning.
// @description:ja Twitter ウェブページのメディア警告を自動的に閉じる
// @description:zh-cn 关闭 Twitter 网页上的媒体警告
// @description:zh-tw 關閉 Twitter 網頁上的媒體警告
// @namespace none
// @version 0.1.1
// @author ShanksSU
// @match https://twitter.com/*
// @match https://twitter.com/*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com
// @grant none
// @compatible Chrome
// @license MIT
// ==/UserScript==
const ButtonAutoClicker = (function () {
var targetSelectors = [
'.css-175oi2r[role="button"][tabindex="0"]',
'.css-1rynq56[role="button"][tabindex="0"]'
];
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
checkButtons(mutation.target);
});
});
function checkButtons(targetNode) {
targetSelectors.forEach(function(selector) {
var buttons = targetNode.querySelectorAll(selector);
if (buttons) {
buttons.forEach(function(button) {
if (button.textContent.trim() === "Show" && isVisible(button) && !isClicked(button)) {
button.click();
// console.log("Button clicked.");
}
});
}
});
}
function isVisible(element) {
return !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
}
var clickedButtons = new Set();
function isClicked(button) {
if (clickedButtons.has(button)) {
return true;
}
clickedButtons.add(button);
return false;
}
function init() {
observer.observe(document.body, {
childList: true,
subtree: true
});
}
return {
init: init
};
})();
ButtonAutoClicker.init();