diff --git a/index.user.js b/index.user.js index a4adb14..1fabba6 100644 --- a/index.user.js +++ b/index.user.js @@ -16,4 +16,4 @@ // @grant none // ==/UserScript== /*! For license information please see index.user.js.LICENSE.txt */ -(()=>{"use strict";var e={531:function(e,t){var r=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function p(e){try{l(n.next(e))}catch(e){i(e)}}function s(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(p,s)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.asyncQuerySelectorAll=t.asyncQuerySelector=void 0;const n=(e,t)=>new Promise((r=>{const n=e();if(n instanceof Element||n instanceof NodeList&&n.length)return void r(n);let o=null;const i=new MutationObserver((()=>{const t=e();(t instanceof Element||t instanceof NodeList&&t.length)&&(i.disconnect(),o&&clearTimeout(o),r(t))}));o=setTimeout((()=>{i.disconnect(),r(null)}),t),i.observe(document.body,{attributes:!0,childList:!0,subtree:!0})}));t.asyncQuerySelector=(e,...t)=>r(void 0,[e,...t],void 0,(function*(e,t=document,r=500){return yield n((()=>t.querySelector(e)),r)})),t.asyncQuerySelectorAll=(e,...t)=>r(void 0,[e,...t],void 0,(function*(e,t=document,r=500){var o;return null!==(o=yield n((()=>t.querySelectorAll(e)),r))&&void 0!==o?o:document.createDocumentFragment().childNodes}))}},t={};const r=e=>{const t=Object.getOwnPropertyNames(e).filter((e=>e.startsWith("__reactProps$")));return t.length?e[t[0]]:null};class n{profileElement;constructor(e){this.profileElement=e}get props(){const e=r(this.profileElement);if(!function(e){const t=e;return(null!==t&&"object"==typeof t||"function"==typeof t)&&Array.isArray(t.children)&&(null!==t.children[0]&&"object"==typeof t.children[0]||"function"==typeof t.children[0])&&(null!==t.children[0].props&&"object"==typeof t.children[0].props||"function"==typeof t.children[0].props)&&Array.isArray(t.children[0].props.children)&&(null!==t.children[0].props.children[1]&&"object"==typeof t.children[0].props.children[1]||"function"==typeof t.children[0].props.children[1])&&(null!==t.children[0].props.children[1].props&&"object"==typeof t.children[0].props.children[1].props||"function"==typeof t.children[0].props.children[1].props)&&(null!==t.children[0].props.children[1].props.user&&"object"==typeof t.children[0].props.children[1].props.user||"function"==typeof t.children[0].props.children[1].props.user)&&(void 0===t.children[0].props.children[1].props.user.possibly_sensitive||null===t.children[0].props.children[1].props.user.possibly_sensitive||!1===t.children[0].props.children[1].props.user.possibly_sensitive||!0===t.children[0].props.children[1].props.user.possibly_sensitive)&&"string"==typeof t.children[0].props.children[1].props.user.screen_name&&(""===t.children[0].props.children[1].props.user.profile_interstitial_type||"sensitive_media"===t.children[0].props.children[1].props.user.profile_interstitial_type||"fake_account"===t.children[0].props.children[1].props.user.profile_interstitial_type||"offensive_profile_content"===t.children[0].props.children[1].props.user.profile_interstitial_type||"timeout"===t.children[0].props.children[1].props.user.profile_interstitial_type)&&Array.isArray(t.children[0].props.children[1].props.user.withheld_in_countries)&&t.children[0].props.children[1].props.user.withheld_in_countries.every((e=>"string"==typeof e))}(e))throw new Error("Failed to get React props of profile");return e.children[0].props.children[1].props.user}}var o=function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}(531);class i{tweetElement;constructor(e){this.tweetElement=e}getMenuBar(){const e=this.tweetElement.querySelector("div[role='group'][id]");if(!e)throw new Error("Failed to get menu bar of tweet");return e}get element(){return this.tweetElement}get props(){const e=r(this.getMenuBar());if(!function(e){const t=e;return(null!==t&&"object"==typeof t||"function"==typeof t)&&Array.isArray(t.children)&&(null!==t.children[1]&&"object"==typeof t.children[1]||"function"==typeof t.children[1])&&(null!==t.children[1].props&&"object"==typeof t.children[1].props||"function"==typeof t.children[1].props)&&(null!==t.children[1].props.retweetWithCommentLink&&"object"==typeof t.children[1].props.retweetWithCommentLink||"function"==typeof t.children[1].props.retweetWithCommentLink)&&(null!==t.children[1].props.retweetWithCommentLink.state&&"object"==typeof t.children[1].props.retweetWithCommentLink.state||"function"==typeof t.children[1].props.retweetWithCommentLink.state)&&(null!==t.children[1].props.retweetWithCommentLink.state.quotedStatus&&"object"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus||"function"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus)&&(void 0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive||null===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive||!1===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive||!0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive)&&(void 0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive_editable||null===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive_editable||!1===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive_editable||!0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive_editable)&&"string"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus.permalink&&(null!==t.children[1].props.retweetWithCommentLink.state.quotedStatus.user&&"object"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus.user||"function"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus.user)&&(void 0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.possibly_sensitive||null===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.possibly_sensitive||!1===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.possibly_sensitive||!0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.possibly_sensitive)&&"string"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.screen_name&&(""===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.profile_interstitial_type||"sensitive_media"===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.profile_interstitial_type||"fake_account"===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.profile_interstitial_type||"offensive_profile_content"===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.profile_interstitial_type||"timeout"===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.profile_interstitial_type)&&Array.isArray(t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.withheld_in_countries)&&t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.withheld_in_countries.every((e=>"string"==typeof e))}(e))throw new Error("Failed to get React props of tweet");return e.children[1].props.retweetWithCommentLink.state.quotedStatus}get metadata(){const e=this.props.user.screen_name,t=r(this.element);if(!t)throw new Error("Failed to get React props of tweet");let n=null;const o=function(e){const t=e;return(null!==t&&"object"==typeof t||"function"==typeof t)&&Array.isArray(t.children)&&Array.isArray(t.children[0])&&(null!==t.children[0][1]&&"object"==typeof t.children[0][1]||"function"==typeof t.children[0][1])&&(null!==t.children[0][1].props&&"object"==typeof t.children[0][1].props||"function"==typeof t.children[0][1].props)&&Array.isArray(t.children[0][1].props.children)&&(null!==t.children[0][1].props.children[0]&&"object"==typeof t.children[0][1].props.children[0]||"function"==typeof t.children[0][1].props.children[0])&&(null!==t.children[0][1].props.children[0].props&&"object"==typeof t.children[0][1].props.children[0].props||"function"==typeof t.children[0][1].props.children[0].props)&&Array.isArray(t.children[0][1].props.children[0].props.children)&&(null!==t.children[0][1].props.children[0].props.children[2]&&"object"==typeof t.children[0][1].props.children[0].props.children[2]||"function"==typeof t.children[0][1].props.children[0].props.children[2])&&(null!==t.children[0][1].props.children[0].props.children[2].props&&"object"==typeof t.children[0][1].props.children[0].props.children[2].props||"function"==typeof t.children[0][1].props.children[0].props.children[2].props)&&Array.isArray(t.children[0][1].props.children[0].props.children[2].props.children)&&(null!==t.children[0][1].props.children[0].props.children[2].props.children[7]&&"object"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7]||"function"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7])&&(null!==t.children[0][1].props.children[0].props.children[2].props.children[7].props&&"object"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7].props||"function"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7].props)&&(null!==t.children[0][1].props.children[0].props.children[2].props.children[7].props.loggedInUser&&"object"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7].props.loggedInUser||"function"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7].props.loggedInUser)&&"string"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7].props.loggedInUser.screen_name}(t);return function(e){const t=e;return(null!==t&&"object"==typeof t||"function"==typeof t)&&Array.isArray(t.children)&&Array.isArray(t.children[0])&&(null!==t.children[0][1]&&"object"==typeof t.children[0][1]||"function"==typeof t.children[0][1])&&(null!==t.children[0][1].props&&"object"==typeof t.children[0][1].props||"function"==typeof t.children[0][1].props)&&Array.isArray(t.children[0][1].props.children)&&(null!==t.children[0][1].props.children[0]&&"object"==typeof t.children[0][1].props.children[0]||"function"==typeof t.children[0][1].props.children[0])&&(null!==t.children[0][1].props.children[0].props&&"object"==typeof t.children[0][1].props.children[0].props||"function"==typeof t.children[0][1].props.children[0].props)&&Array.isArray(t.children[0][1].props.children[0].props.children)&&(null!==t.children[0][1].props.children[0].props.children[1]&&"object"==typeof t.children[0][1].props.children[0].props.children[1]||"function"==typeof t.children[0][1].props.children[0].props.children[1])&&(null!==t.children[0][1].props.children[0].props.children[1].props&&"object"==typeof t.children[0][1].props.children[0].props.children[1].props||"function"==typeof t.children[0][1].props.children[0].props.children[1].props)&&Array.isArray(t.children[0][1].props.children[0].props.children[1].props.children)&&Array.isArray(t.children[0][1].props.children[0].props.children[1].props.children[1])&&(null!==t.children[0][1].props.children[0].props.children[1].props.children[1][2]&&"object"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2]||"function"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2])&&(null!==t.children[0][1].props.children[0].props.children[1].props.children[1][2].props&&"object"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2].props||"function"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2].props)&&(null!==t.children[0][1].props.children[0].props.children[1].props.children[1][2].props.loggedInUser&&"object"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2].props.loggedInUser||"function"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2].props.loggedInUser)&&"string"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2].props.loggedInUser.screen_name}(t)&&(n=t.children[0][1].props.children[0].props.children[1].props.children[1][2].props.loggedInUser.screen_name),o&&(n=t.children[0][1].props.children[0].props.children[2].props.children[7].props.loggedInUser.screen_name),{isFocalMode:o,isPostedByCurrentUser:e===n}}async clickRetweetButton(e){const t=await(0,o.asyncQuerySelector)("[data-testid='unretweet'], [data-testid='retweet']",this.tweetElement,e);if(!t)throw new Error("Failed to get retweet button of tweet");t.click()}static async clickQuoteButton(e){const t=await(0,o.asyncQuerySelector)(["[data-testid='Dropdown'] [href='/compose/post']","[data-testid='sheetDialog'] [href='/compose/post']"].join(","),document,e);if(!t)throw new Error("Failed to get quote button of tweet");t.click()}static async getTweetTextBox(e){const t="pro.twitter.com"===location.hostname?"[role='dialog'] [data-text='true'], [role='dialog'] textarea[data-testid='tweetTextarea_0']":"[role='dialog'] [data-text='true'], textarea[data-testid='tweetTextarea_0']",r=await(0,o.asyncQuerySelector)(t,document,e);if(!r)throw new Error("Failed to get text box marker of tweet");const n="TEXTAREA"===r.tagName?r:r.parentElement;if(!n)throw new Error("Failed to get text box of tweet");return n}async quoteTweet(e,t=1e3){try{await this.clickRetweetButton(t),await i.clickQuoteButton(t);const r=await i.getTweetTextBox(t);r.innerHTML=e,r.dispatchEvent(new Event("input",{bubbles:!0}))}catch{const t=this.props.permalink;open(`https://twitter.com/intent/tweet?text=${encodeURIComponent(`${e}\nhttps://twitter.com${t}`)}`,"_blank")}}}const p={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};var s,l=new Uint8Array(16);function c(){if(!s&&!(s="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return s(l)}for(var d=[],h=0;h<256;++h)d.push((h+256).toString(16).slice(1));const a=function(e,t,r){if(p.randomUUID&&!t&&!e)return p.randomUUID();var n=(e=e||{}).random||(e.rng||c)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=n[o];return t}return function(e,t=0){return(d[e[t+0]]+d[e[t+1]]+d[e[t+2]]+d[e[t+3]]+"-"+d[e[t+4]]+d[e[t+5]]+"-"+d[e[t+6]]+d[e[t+7]]+"-"+d[e[t+8]]+d[e[t+9]]+"-"+d[e[t+10]]+d[e[t+11]]+d[e[t+12]]+d[e[t+13]]+d[e[t+14]]+d[e[t+15]]).toLowerCase()}(n)};(new class{OBSERVER_OPTIONS={childList:!0,subtree:!0};onNewTweetCallback=null;onNewProfileCallback=null;constructor(e){const t=`data-twi-ext-checked-${a()}`,r={timeoutMs:1e4,...e},p=new MutationObserver((()=>{if(this.onNewTweetCallback){const e=document.querySelectorAll(`[data-testid="tweet"]:not([${t}])`);for(const r of e)r.setAttribute(t,""),this.onNewTweetCallback(new i(r))}if(this.onNewProfileCallback){const e=document.querySelector(`:not([data-testid="tweet"]) [data-testid="UserName"]:not([${t}])`);e&&(e.setAttribute(t,""),this.onNewProfileCallback(new n(e)))}}));(0,o.asyncQuerySelector)("main",document,r.timeoutMs).then((e=>{if(!e)throw new Error("twi-ext: Failed to get main element");p.observe(e,this.OBSERVER_OPTIONS)})),(0,o.asyncQuerySelector)("#layers",document,r.timeoutMs).then((e=>{if(!e)throw new Error("twi-ext: Failed to get #layers element");p.observe(e,this.OBSERVER_OPTIONS)}))}onNewTweet(e){this.onNewTweetCallback=e}onNewProfile(e){this.onNewProfileCallback=e}}).onNewTweet((e=>{(e=>{const t=e.element.querySelector("[role='group'] a[href$='analytics']");t?.parentElement&&(t.href="",t.parentElement.style.display="none");const r=document.querySelector("a[aria-describedby] time");if(r?.parentElement?.parentElement?.parentElement){const e=r.parentElement.parentElement.parentElement.querySelectorAll("div ~ *");for(const t of e)t.style.display="none"}})(e)}))})(); \ No newline at end of file +(()=>{"use strict";var e={531:function(e,t){var r=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function p(e){try{l(n.next(e))}catch(e){i(e)}}function s(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(p,s)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.asyncQuerySelectorAll=t.asyncQuerySelector=void 0;const n=(e,t)=>new Promise((r=>{const n=e();if(n instanceof Element||n instanceof NodeList&&n.length)return void r(n);let o=null;const i=new MutationObserver((()=>{const t=e();(t instanceof Element||t instanceof NodeList&&t.length)&&(i.disconnect(),o&&clearTimeout(o),r(t))}));o=setTimeout((()=>{i.disconnect(),r(null)}),t),i.observe(document.body,{attributes:!0,childList:!0,subtree:!0})}));t.asyncQuerySelector=(e,...t)=>r(void 0,[e,...t],void 0,(function*(e,t=document,r=500){return yield n((()=>t.querySelector(e)),r)})),t.asyncQuerySelectorAll=(e,...t)=>r(void 0,[e,...t],void 0,(function*(e,t=document,r=500){var o;return null!==(o=yield n((()=>t.querySelectorAll(e)),r))&&void 0!==o?o:document.createDocumentFragment().childNodes}))}},t={};const r=e=>{const t=Object.getOwnPropertyNames(e).filter((e=>e.startsWith("__reactProps$")));return t.length?e[t[0]]:null};class n{profileElement;constructor(e){this.profileElement=e}get props(){const e=r(this.profileElement);if(!function(e){const t=e;return(null!==t&&"object"==typeof t||"function"==typeof t)&&Array.isArray(t.children)&&(null!==t.children[0]&&"object"==typeof t.children[0]||"function"==typeof t.children[0])&&(null!==t.children[0].props&&"object"==typeof t.children[0].props||"function"==typeof t.children[0].props)&&Array.isArray(t.children[0].props.children)&&(null!==t.children[0].props.children[1]&&"object"==typeof t.children[0].props.children[1]||"function"==typeof t.children[0].props.children[1])&&(null!==t.children[0].props.children[1].props&&"object"==typeof t.children[0].props.children[1].props||"function"==typeof t.children[0].props.children[1].props)&&(null!==t.children[0].props.children[1].props.user&&"object"==typeof t.children[0].props.children[1].props.user||"function"==typeof t.children[0].props.children[1].props.user)&&(void 0===t.children[0].props.children[1].props.user.possibly_sensitive||null===t.children[0].props.children[1].props.user.possibly_sensitive||!1===t.children[0].props.children[1].props.user.possibly_sensitive||!0===t.children[0].props.children[1].props.user.possibly_sensitive)&&"string"==typeof t.children[0].props.children[1].props.user.screen_name&&(""===t.children[0].props.children[1].props.user.profile_interstitial_type||"sensitive_media"===t.children[0].props.children[1].props.user.profile_interstitial_type||"fake_account"===t.children[0].props.children[1].props.user.profile_interstitial_type||"offensive_profile_content"===t.children[0].props.children[1].props.user.profile_interstitial_type||"timeout"===t.children[0].props.children[1].props.user.profile_interstitial_type)&&Array.isArray(t.children[0].props.children[1].props.user.withheld_in_countries)&&t.children[0].props.children[1].props.user.withheld_in_countries.every((e=>"string"==typeof e))}(e))throw new Error("Failed to get React props of profile");return e.children[0].props.children[1].props.user}}var o=function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}(531);class i{tweetElement;constructor(e){this.tweetElement=e}getMenuBar(){const e=this.tweetElement.querySelector("div[role='group'][id]");if(!e)throw new Error("Failed to get menu bar of tweet");return e}get element(){return this.tweetElement}get props(){const e=r(this.getMenuBar());if(!function(e){const t=e;return(null!==t&&"object"==typeof t||"function"==typeof t)&&Array.isArray(t.children)&&(null!==t.children[1]&&"object"==typeof t.children[1]||"function"==typeof t.children[1])&&(null!==t.children[1].props&&"object"==typeof t.children[1].props||"function"==typeof t.children[1].props)&&(null!==t.children[1].props.retweetWithCommentLink&&"object"==typeof t.children[1].props.retweetWithCommentLink||"function"==typeof t.children[1].props.retweetWithCommentLink)&&(null!==t.children[1].props.retweetWithCommentLink.state&&"object"==typeof t.children[1].props.retweetWithCommentLink.state||"function"==typeof t.children[1].props.retweetWithCommentLink.state)&&(null!==t.children[1].props.retweetWithCommentLink.state.quotedStatus&&"object"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus||"function"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus)&&(void 0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive||null===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive||!1===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive||!0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive)&&(void 0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive_editable||null===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive_editable||!1===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive_editable||!0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.possibly_sensitive_editable)&&"string"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus.permalink&&(null!==t.children[1].props.retweetWithCommentLink.state.quotedStatus.user&&"object"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus.user||"function"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus.user)&&(void 0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.possibly_sensitive||null===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.possibly_sensitive||!1===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.possibly_sensitive||!0===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.possibly_sensitive)&&"string"==typeof t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.screen_name&&(""===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.profile_interstitial_type||"sensitive_media"===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.profile_interstitial_type||"fake_account"===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.profile_interstitial_type||"offensive_profile_content"===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.profile_interstitial_type||"timeout"===t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.profile_interstitial_type)&&Array.isArray(t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.withheld_in_countries)&&t.children[1].props.retweetWithCommentLink.state.quotedStatus.user.withheld_in_countries.every((e=>"string"==typeof e))}(e))throw new Error("Failed to get React props of tweet");return e.children[1].props.retweetWithCommentLink.state.quotedStatus}get metadata(){const e=this.props.user.screen_name,t=r(this.element);if(!t)throw new Error("Failed to get React props of tweet");let n=null;const o=function(e){const t=e;return(null!==t&&"object"==typeof t||"function"==typeof t)&&Array.isArray(t.children)&&Array.isArray(t.children[0])&&(null!==t.children[0][1]&&"object"==typeof t.children[0][1]||"function"==typeof t.children[0][1])&&(null!==t.children[0][1].props&&"object"==typeof t.children[0][1].props||"function"==typeof t.children[0][1].props)&&Array.isArray(t.children[0][1].props.children)&&(null!==t.children[0][1].props.children[0]&&"object"==typeof t.children[0][1].props.children[0]||"function"==typeof t.children[0][1].props.children[0])&&(null!==t.children[0][1].props.children[0].props&&"object"==typeof t.children[0][1].props.children[0].props||"function"==typeof t.children[0][1].props.children[0].props)&&Array.isArray(t.children[0][1].props.children[0].props.children)&&(null!==t.children[0][1].props.children[0].props.children[2]&&"object"==typeof t.children[0][1].props.children[0].props.children[2]||"function"==typeof t.children[0][1].props.children[0].props.children[2])&&(null!==t.children[0][1].props.children[0].props.children[2].props&&"object"==typeof t.children[0][1].props.children[0].props.children[2].props||"function"==typeof t.children[0][1].props.children[0].props.children[2].props)&&Array.isArray(t.children[0][1].props.children[0].props.children[2].props.children)&&(null!==t.children[0][1].props.children[0].props.children[2].props.children[7]&&"object"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7]||"function"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7])&&(null!==t.children[0][1].props.children[0].props.children[2].props.children[7].props&&"object"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7].props||"function"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7].props)&&(null!==t.children[0][1].props.children[0].props.children[2].props.children[7].props.loggedInUser&&"object"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7].props.loggedInUser||"function"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7].props.loggedInUser)&&"string"==typeof t.children[0][1].props.children[0].props.children[2].props.children[7].props.loggedInUser.screen_name}(t);return function(e){const t=e;return(null!==t&&"object"==typeof t||"function"==typeof t)&&Array.isArray(t.children)&&Array.isArray(t.children[0])&&(null!==t.children[0][1]&&"object"==typeof t.children[0][1]||"function"==typeof t.children[0][1])&&(null!==t.children[0][1].props&&"object"==typeof t.children[0][1].props||"function"==typeof t.children[0][1].props)&&Array.isArray(t.children[0][1].props.children)&&(null!==t.children[0][1].props.children[0]&&"object"==typeof t.children[0][1].props.children[0]||"function"==typeof t.children[0][1].props.children[0])&&(null!==t.children[0][1].props.children[0].props&&"object"==typeof t.children[0][1].props.children[0].props||"function"==typeof t.children[0][1].props.children[0].props)&&Array.isArray(t.children[0][1].props.children[0].props.children)&&(null!==t.children[0][1].props.children[0].props.children[1]&&"object"==typeof t.children[0][1].props.children[0].props.children[1]||"function"==typeof t.children[0][1].props.children[0].props.children[1])&&(null!==t.children[0][1].props.children[0].props.children[1].props&&"object"==typeof t.children[0][1].props.children[0].props.children[1].props||"function"==typeof t.children[0][1].props.children[0].props.children[1].props)&&Array.isArray(t.children[0][1].props.children[0].props.children[1].props.children)&&Array.isArray(t.children[0][1].props.children[0].props.children[1].props.children[1])&&(null!==t.children[0][1].props.children[0].props.children[1].props.children[1][2]&&"object"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2]||"function"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2])&&(null!==t.children[0][1].props.children[0].props.children[1].props.children[1][2].props&&"object"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2].props||"function"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2].props)&&(null!==t.children[0][1].props.children[0].props.children[1].props.children[1][2].props.loggedInUser&&"object"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2].props.loggedInUser||"function"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2].props.loggedInUser)&&"string"==typeof t.children[0][1].props.children[0].props.children[1].props.children[1][2].props.loggedInUser.screen_name}(t)&&(n=t.children[0][1].props.children[0].props.children[1].props.children[1][2].props.loggedInUser.screen_name),o&&(n=t.children[0][1].props.children[0].props.children[2].props.children[7].props.loggedInUser.screen_name),{isFocalMode:o,isPostedByCurrentUser:e===n}}async clickRetweetButton(e){const t=await(0,o.asyncQuerySelector)("[data-testid='unretweet'], [data-testid='retweet']",this.tweetElement,e);if(!t)throw new Error("Failed to get retweet button of tweet");t.click()}static async clickQuoteButton(e){const t=await(0,o.asyncQuerySelector)(["[data-testid='Dropdown'] [href='/compose/post']","[data-testid='sheetDialog'] [href='/compose/post']"].join(","),document,e);if(!t)throw new Error("Failed to get quote button of tweet");t.click()}static async getTweetTextBox(e){const t="pro.twitter.com"===location.hostname?"[role='dialog'] [data-text='true'], [role='dialog'] textarea[data-testid='tweetTextarea_0']":"[role='dialog'] [data-text='true'], textarea[data-testid='tweetTextarea_0']",r=await(0,o.asyncQuerySelector)(t,document,e);if(!r)throw new Error("Failed to get text box marker of tweet");const n="TEXTAREA"===r.tagName?r:r.parentElement;if(!n)throw new Error("Failed to get text box of tweet");return n}async quoteTweet(e,t=1e3){try{await this.clickRetweetButton(t),await i.clickQuoteButton(t);const r=await i.getTweetTextBox(t);r.innerHTML=e,r.dispatchEvent(new Event("input",{bubbles:!0}))}catch{const t=this.props.permalink;open(`https://twitter.com/intent/tweet?text=${encodeURIComponent(`${e}\nhttps://twitter.com${t}`)}`,"_blank")}}}const p={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};var s,l=new Uint8Array(16);function c(){if(!s&&!(s="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return s(l)}for(var d=[],h=0;h<256;++h)d.push((h+256).toString(16).slice(1));const a=function(e,t,r){if(p.randomUUID&&!t&&!e)return p.randomUUID();var n=(e=e||{}).random||(e.rng||c)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=n[o];return t}return function(e,t=0){return(d[e[t+0]]+d[e[t+1]]+d[e[t+2]]+d[e[t+3]]+"-"+d[e[t+4]]+d[e[t+5]]+"-"+d[e[t+6]]+d[e[t+7]]+"-"+d[e[t+8]]+d[e[t+9]]+"-"+d[e[t+10]]+d[e[t+11]]+d[e[t+12]]+d[e[t+13]]+d[e[t+14]]+d[e[t+15]]).toLowerCase()}(n)};(new class{OBSERVER_OPTIONS={childList:!0,subtree:!0};onNewTweetCallback=null;onNewProfileCallback=null;constructor(e){const t=`data-twi-ext-checked-${a()}`,r={timeoutMs:1e4,...e},p=new MutationObserver((()=>{if(this.onNewTweetCallback){const e=document.querySelectorAll(`[data-testid="tweet"]:not([${t}])`);for(const r of e)r.setAttribute(t,""),this.onNewTweetCallback(new i(r))}if(this.onNewProfileCallback){const e=document.querySelector(`:not([data-testid="tweet"]) [data-testid="UserName"]:not([${t}])`);e&&(e.setAttribute(t,""),this.onNewProfileCallback(new n(e)))}}));(0,o.asyncQuerySelector)("main",document,r.timeoutMs).then((e=>{if(!e)throw new Error("twi-ext: Failed to get main element");p.observe(e,this.OBSERVER_OPTIONS)})),(0,o.asyncQuerySelector)("#layers",document,r.timeoutMs).then((e=>{if(!e)throw new Error("twi-ext: Failed to get #layers element");p.observe(e,this.OBSERVER_OPTIONS)}))}onNewTweet(e){this.onNewTweetCallback=e}onNewProfile(e){this.onNewProfileCallback=e}}).onNewTweet((()=>{(()=>{const e=document.querySelectorAll("[role='group'] a[href$='analytics']");for(const t of e)t.parentElement&&(t.href="",t.parentElement.style.display="none");const t=document.querySelector("a[aria-describedby] time");if(t?.parentElement?.parentElement?.parentElement){const e=t.parentElement.parentElement.parentElement.querySelectorAll("div ~ *");for(const t of e)t.style.display="none"}})()}))})(); \ No newline at end of file diff --git a/src/ts/index.ts b/src/ts/index.ts index f20b2f1..7393e15 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -1,16 +1,17 @@ -import { Timeline, type Tweet } from "twi-ext"; +import { Timeline } from "twi-ext"; // eslint-disable-next-line max-statements -const onNewTweet = (tweet: Tweet): void => { - const tweetElement = tweet.element; - const viewCountWithIcon = tweetElement.querySelector("[role='group'] a[href$='analytics']"); - if (viewCountWithIcon?.parentElement) { - /* - * Measures against incompatibility with "Minimal Theme for Twitter" or other extensions. - * See [#7](https://github.com/Robot-Inventor/hide-view-count/issues/7) - */ - viewCountWithIcon.href = ""; - viewCountWithIcon.parentElement.style.display = "none"; +const onNewTweet = (): void => { + const viewCountWithIcons = document.querySelectorAll("[role='group'] a[href$='analytics']"); + for (const viewCountWithIcon of viewCountWithIcons) { + if (viewCountWithIcon.parentElement) { + /* + * Measures against incompatibility with "Minimal Theme for Twitter" or other extensions. + * See [#7](https://github.com/Robot-Inventor/hide-view-count/issues/7) + */ + viewCountWithIcon.href = ""; + viewCountWithIcon.parentElement.style.display = "none"; + } } const time = document.querySelector(`a[aria-describedby] time`); @@ -24,6 +25,6 @@ const onNewTweet = (tweet: Tweet): void => { }; const timeline = new Timeline(); -timeline.onNewTweet((tweet) => { - onNewTweet(tweet); +timeline.onNewTweet(() => { + onNewTweet(); });