Support 2019 new UI Twitter only.
当前为
// ==UserScript==
// @name Twitter - Hide Retweet
// @version 1.0.2
// @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;
// 偵測是否僅切換地址
let pushState = history.pushState;
history.pushState = function() {
pushState.apply(history, arguments);
waitLoaded();
};
// 偵測上一頁、下一頁
window.addEventListener("popstate", waitLoaded);
// 觀察文件是否產生變化
waitLoaded(); //等待文件讀取
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; //前綴
function waitLoaded() {
setTimeout(() => {
const h1 = $("section").find("H1");
const title = $("title");
if (h1.length !== 2 || title.length === 0) waitLoaded();
else {
// 獲取目標
const target1 = [...h1[0].parentElement.childNodes].filter(child => child.tagName !== "H1")[0].childNodes[0].childNodes[0];
const target2 = title[0];
// 先執行一次
hideRetweet();
// 建立觀察者,文件有變化就執行下列函式
const observer = new MutationObserver(hideRetweet);
// 設定觀察選項
const config = { attributes: true, childList: true, characterData: true };
// 開始觀察
observer.observe(target1, config); //時間軸
observer.observe(target2, config); //標籤頁
}
}, 500);
}
function hideRetweet() {
// 已轉推的圖
const icon = $('path[d="M23.615 15.477c-.47-.47-1.23-.47-1.697 0l-1.326 1.326V7.4c0-2.178-1.772-3.95-3.95-3.95h-5.2c-.663 0-1.2.538-1.2 1.2s.537 1.2 1.2 1.2h5.2c.854 0 1.55.695 1.55 1.55v9.403l-1.326-1.326c-.47-.47-1.23-.47-1.697 0s-.47 1.23 0 1.697l3.374 3.375c.234.233.542.35.85.35s.613-.116.848-.35l3.375-3.376c.467-.47.467-1.23-.002-1.697zM12.562 18.5h-5.2c-.854 0-1.55-.695-1.55-1.55V7.547l1.326 1.326c.234.235.542.352.848.352s.614-.117.85-.352c.468-.47.468-1.23 0-1.697L5.46 3.8c-.47-.468-1.23-.468-1.697 0L.388 7.177c-.47.47-.47 1.23 0 1.697s1.23.47 1.697 0L3.41 7.547v9.403c0 2.178 1.773 3.95 3.95 3.95h5.2c.664 0 1.2-.538 1.2-1.2s-.535-1.2-1.198-1.2z"]');
icon.each(i => $(icon[i]).parent().parent().parent().parent().parent().parent().parent().parent().parent().hide());
}
})();