Support 2019 new UI Twitter only.
当前为
// ==UserScript==
// @name Twitter - Hide Retweet
// @version 1.0.1
// @description Support 2019 new UI Twitter only.
// @author Hayao-Gai
// @namespace https://github.com/HayaoGai
// @icon https://i.imgur.com/M9oO8K9.png
// @include https://twitter.com/*
// @require http://code.jquery.com/jquery-3.4.1.slim.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
const $ = window.jQuery;
// 觀察文件是否產生變化
waitLoaded(); //等待文件讀取
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; //前綴
function waitLoaded() {
const section = document.getElementsByTagName("section");
setTimeout(() => {
if (section.length !== 2) waitLoaded();
else {
const target = section[0].children[1].children[0].children[0]; //取出會產生變化的節點
hideRetweet();
const observer = new MutationObserver(e => { //建立觀察者,文件有變化就執行下列函式
hideRetweet();
});
const config = { attributes: true, childList: true, characterData: true }; //設定觀察選項
observer.observe(target, config); //開始觀察
}
}, 500);
}
function hideRetweet() {
// 已轉推
const strClass = ".css-1dbjc4n.r-obd0qt.r-1iusvr4.r-16y2uox.r-5f2r5o.r-1gmbmnb.r-bcqeeo";
$(strClass).each((i, retweet) => {
console.log("retweet", retweet);
// 父物件
$(retweet).parents().each((j, parent) => {
let check = false; //確認推文是否已隱藏
// 最上層
$(parent).each((k, hide) => {
if ($(hide).hasClass("")) {
$(hide).hide();
check = true;
return false;
}
});
if (check) return false;
});
});
}
})();