diff --git a/index.user.js b/index.user.js index 3c9c75b..7ccbd19 100644 --- a/index.user.js +++ b/index.user.js @@ -15,6 +15,6 @@ // @updateURL https://raw.githubusercontent.com/Robot-Inventor/hide-view-count/main/index.user.js // @grant none // ==/UserScript== -/*! For license information please see index.user.js.LICENSE.txt */ -(()=>{"use strict";let e,t,r,i,o,n,l,s,a,c,p,u,d;var f={},y={};function w(e){var t=y[e];if(void 0!==t)return t.exports;var r=y[e]={exports:{}};return f[e](r,r.exports,w),r.exports}w.rv=()=>"1.6.7",w.ruid="bundler=rspack@1.6.7";let h=(e=e=>"object"==typeof e.props&&null!==e.props&&t(e.props),t=e=>"object"==typeof e.retweetWithCommentLink&&null!==e.retweetWithCommentLink&&r(e.retweetWithCommentLink),r=e=>"object"==typeof e.state&&null!==e.state&&i(e.state),i=e=>"object"==typeof e.quotedStatus&&null!==e.quotedStatus&&o(e.quotedStatus),o=e=>(null===e.possibly_sensitive||void 0===e.possibly_sensitive||"boolean"==typeof e.possibly_sensitive)&&(null===e.possibly_sensitive_editable||void 0===e.possibly_sensitive_editable||"boolean"==typeof e.possibly_sensitive_editable)&&"string"==typeof e.permalink&&"object"==typeof e.user&&null!==e.user&&n(e.user),n=e=>(null===e.possibly_sensitive||void 0===e.possibly_sensitive||"boolean"==typeof e.possibly_sensitive)&&"string"==typeof e.screen_name&&(""===e.profile_interstitial_type||"sensitive_media"===e.profile_interstitial_type||"fake_account"===e.profile_interstitial_type||"offensive_profile_content"===e.profile_interstitial_type||"timeout"===e.profile_interstitial_type)&&Array.isArray(e.withheld_in_countries)&&e.withheld_in_countries.every(e=>"string"==typeof e),t=>"object"==typeof t&&null!==t&&Array.isArray(t.children)&&"object"==typeof t.children[1]&&null!==t.children[1]&&e(t.children[1])&&Array.isArray(t.children.slice(2))),m=(l=e=>"object"==typeof e.props&&null!==e.props&&s(e.props),s=e=>"boolean"==typeof e.isFocalTweet,e=>"object"==typeof e&&null!==e&&"object"==typeof e.children&&null!==e.children&&l(e.children)),_=(a=e=>"object"==typeof e.props&&null!==e.props&&c(e.props),c=e=>Array.isArray(e.children)&&2===e.children.length&&"object"==typeof e.children[1]&&null!==e.children[1]&&p(e.children[1]),p=e=>"object"==typeof e.props&&null!==e.props&&u(e.props),u=e=>"object"==typeof e.user&&null!==e.user&&d(e.user),d=e=>(null===e.possibly_sensitive||void 0===e.possibly_sensitive||"boolean"==typeof e.possibly_sensitive)&&"string"==typeof e.screen_name&&(""===e.profile_interstitial_type||"sensitive_media"===e.profile_interstitial_type||"fake_account"===e.profile_interstitial_type||"offensive_profile_content"===e.profile_interstitial_type||"timeout"===e.profile_interstitial_type)&&Array.isArray(e.withheld_in_countries)&&e.withheld_in_countries.every(e=>"string"==typeof e),e=>"object"==typeof e&&null!==e&&Array.isArray(e.children)&&2===e.children.length&&"object"==typeof e.children[0]&&null!==e.children[0]&&a(e.children[0])&&!0),b=e=>Array.isArray(e)&&e.length>0,v=e=>{let t=Object.getOwnPropertyNames(e).filter(e=>e.startsWith("__reactProps$"));return b(t)?e[t[0]]:null};class g{profileElement;constructor(e){this.profileElement=e}get props(){let e=v(this.profileElement);if(!_(e))throw Error("Failed to get React props of profile");return e.children[0].props.children[1].props.user}}let E=["pro.twitter.com","pro.x.com"],x=(e,t)=>new Promise(r=>{let i=e();if(i instanceof Element||i instanceof NodeList&&i.length)return void r(i);let o=null,n=new MutationObserver(()=>{let t=e();(t instanceof Element||t instanceof NodeList&&t.length)&&(n.disconnect(),o&&clearTimeout(o),r(t))});o=setTimeout(()=>{n.disconnect(),r(null)},t),n.observe(document.body,{attributes:!0,childList:!0,subtree:!0})}),A=async(e,t=document,r=500)=>await x(()=>t.querySelector(e),r),T=async(e,t=document,r=500)=>await x(()=>t.querySelectorAll(e),r)??document.createDocumentFragment().childNodes,k=e=>"TEXTAREA"===e.tagName?e:e.parentElement,S=async(e,t)=>{let r=E.includes(location.hostname),i=[...await T(r?"[role='dialog'] [data-text='true'], [role='dialog'] textarea[data-testid='tweetTextarea_0']":"[role='dialog'] [data-text='true'], textarea[data-testid='tweetTextarea_0']",document,t)];if(!b(i))throw Error("[twi-ext] Failed to get text box marker of tweet");for(let e=0;e{open(`https://x.com/intent/tweet?text=${encodeURIComponent(e)}`,"_blank")};class j{tweetElement;constructor(e){this.tweetElement=e}getMenuBar(){let e=this.tweetElement.querySelector("div[role='group'][id]");if(!e)throw Error("[twi-ext] Failed to get menu bar of tweet");return e}get element(){return this.tweetElement}get props(){let e=v(this.getMenuBar());if(!h(e))throw Error("[twi-ext] Failed to get React props of tweet");return e.children[1].props.retweetWithCommentLink.state.quotedStatus}get metadata(){let e=this.props.user.screen_name,t=this.getMenuBar().parentElement?.parentElement;if(!t)throw Error("[twi-ext] Failed to get grandparent of menu bar of tweet");let r=v(t);if(!m(r))throw Error("[twi-ext] Failed to determine whether it is in focal mode. There may have been a change in X's specifications.");let i=(()=>{let e,t,r,i=[...document.querySelectorAll("body > script:not([src])")].find(e=>e.textContent.trim().startsWith("window.__INITIAL_STATE__"));if(!i)throw Error("[twi-ext] Failed to find initial state.");let[o]=i.textContent.trim().replace(/^window\.__INITIAL_STATE__=/u,"").split(";window.__META_DATA__");if(!o)throw Error("[twi-ext] Failed to extract initial state.");let n=(e=e=>"object"==typeof e.remote&&null!==e.remote&&t(e.remote),t=e=>"object"==typeof e.settings&&null!==e.settings&&r(e.settings),r=e=>"string"==typeof e.screen_name,t=>{var r;return"object"==typeof(r=t=JSON.parse(t))&&null!==r&&"object"==typeof r.settings&&null!==r.settings&&e(r.settings)?t:null})(o);if(!n)throw Error("[twi-ext] Failed to parse initial state.");return n})().settings.remote.settings.screen_name;return{isFocalMode:r.children.props.isFocalTweet,isPostedByCurrentUser:e===i}}async clickRetweetButton(e){let t=await A("[data-testid='unretweet'], [data-testid='retweet']",this.tweetElement,e);if(!t)throw Error("[twi-ext] Failed to get retweet button of tweet");t.click()}static async clickQuoteButton(e){let t=await A("[data-testid='Dropdown'] [href='/compose/post'],[data-testid='sheetDialog'] [href='/compose/post']",document,e);if(!t)throw Error("[twi-ext] Failed to get quote button of tweet");t.click()}async quoteTweet(e,t=1e3,r=!1){let i=this.props.permalink,o=`${e} -https://x.com${i}`;if(r)return void N(o);try{await this.clickRetweetButton(t),await j.clickQuoteButton(t),await S(e,t)}catch{N(o)}}}var F=function(){var e=document.querySelectorAll("[role='group'] a[href$='analytics']"),t=!0,r=!1,i=void 0;try{for(var o,n,l,s=e[Symbol.iterator]();!(t=(l=s.next()).done);t=!0){var a=l.value;a.parentElement&&(a.href="",a.parentElement.style.display="none")}}catch(e){r=!0,i=e}finally{try{t||null==s.return||s.return()}finally{if(r)throw i}}var c=document.querySelector("a[aria-describedby] time");if(null==c||null==(n=c.parentElement)||null==(o=n.parentElement)?void 0:o.parentElement){var p=c.parentElement.parentElement.parentElement.querySelectorAll("div ~ *"),u=!0,d=!1,f=void 0;try{for(var y,w=p[Symbol.iterator]();!(u=(y=w.next()).done);u=!0)y.value.style.display="none"}catch(e){d=!0,f=e}finally{try{u||null==w.return||w.return()}finally{if(d)throw f}}}};new class{OBSERVER_OPTIONS={childList:!0,subtree:!0};onNewTweetCallback=null;onNewProfileCallback=null;constructor(e){const t=`data-twi-ext-checked-${crypto.randomUUID()}`,r={timeoutMs:1e4,...e},i=new MutationObserver(()=>{if(this.onNewTweetCallback)for(let e of document.querySelectorAll(`[data-testid="tweet"]:not([${t}])`))e.setAttribute(t,""),this.onNewTweetCallback(new j(e));if(this.onNewProfileCallback){let e=document.querySelector(`:not([data-testid="tweet"]) [data-testid="UserName"]:not([${t}])`);e&&(e.setAttribute(t,""),this.onNewProfileCallback(new g(e)))}});A("main",document,r.timeoutMs).then(e=>{if(!e)throw Error("[twi-ext] Failed to get main element");i.observe(e,this.OBSERVER_OPTIONS)}),A("#layers",document,r.timeoutMs).then(e=>{if(!e)throw Error("[twi-ext] Failed to get #layers element");i.observe(e,this.OBSERVER_OPTIONS)})}onNewTweet(e){this.onNewTweetCallback=e}onNewProfile(e){this.onNewProfileCallback=e}}().onNewTweet(function(){F()})})(); \ No newline at end of file +/*! LICENSE: index.user.js.LICENSE.txt */ +(()=>{"use strict";let e,t,i,r,o,l,n,s,a,c,u,d,p,h,f,m=(e=e=>"object"==typeof e.props&&null!==e.props&&t(e.props),t=e=>"object"==typeof e.retweetWithCommentLink&&null!==e.retweetWithCommentLink&&i(e.retweetWithCommentLink),i=e=>"object"==typeof e.state&&null!==e.state&&r(e.state),r=e=>"object"==typeof e.quotedStatus&&null!==e.quotedStatus&&o(e.quotedStatus),o=e=>(null===e.possibly_sensitive||void 0===e.possibly_sensitive||"boolean"==typeof e.possibly_sensitive)&&(null===e.possibly_sensitive_editable||void 0===e.possibly_sensitive_editable||"boolean"==typeof e.possibly_sensitive_editable)&&"string"==typeof e.permalink&&"object"==typeof e.user&&null!==e.user&&l(e.user)&&(void 0===e.mediaVisibilityResults||"object"==typeof e.mediaVisibilityResults&&null!==e.mediaVisibilityResults&&!1===Array.isArray(e.mediaVisibilityResults)&&n(e.mediaVisibilityResults)),l=e=>(null===e.possibly_sensitive||void 0===e.possibly_sensitive||"boolean"==typeof e.possibly_sensitive)&&"string"==typeof e.screen_name&&(""===e.profile_interstitial_type||"sensitive_media"===e.profile_interstitial_type||"fake_account"===e.profile_interstitial_type||"offensive_profile_content"===e.profile_interstitial_type||"timeout"===e.profile_interstitial_type)&&(void 0===e.withheld_in_countries||Array.isArray(e.withheld_in_countries)&&e.withheld_in_countries.every(e=>"string"==typeof e))&&(void 0===e.has_graduated_access||"boolean"==typeof e.has_graduated_access),n=e=>void 0===e.blurred_image_interstitial||"object"==typeof e.blurred_image_interstitial&&null!==e.blurred_image_interstitial&&s(e.blurred_image_interstitial),s=e=>"number"==typeof e.opacity,t=>"object"==typeof t&&null!==t&&Array.isArray(t.children)&&"object"==typeof t.children[1]&&null!==t.children[1]&&e(t.children[1])&&Array.isArray(t.children.slice(2))),y=(a=e=>"object"==typeof e.props&&null!==e.props&&c(e.props),c=e=>"boolean"==typeof e.isFocalTweet,e=>"object"==typeof e&&null!==e&&Array.isArray(e.children)&&2===e.children.length&&"object"==typeof e.children[0]&&null!==e.children[0]&&a(e.children[0])&&!0),w=(u=e=>"object"==typeof e.props&&null!==e.props&&d(e.props),d=e=>Array.isArray(e.children)&&2===e.children.length&&"object"==typeof e.children[1]&&null!==e.children[1]&&p(e.children[1]),p=e=>"object"==typeof e.props&&null!==e.props&&h(e.props),h=e=>"object"==typeof e.user&&null!==e.user&&f(e.user),f=e=>(null===e.possibly_sensitive||void 0===e.possibly_sensitive||"boolean"==typeof e.possibly_sensitive)&&"string"==typeof e.screen_name&&(""===e.profile_interstitial_type||"sensitive_media"===e.profile_interstitial_type||"fake_account"===e.profile_interstitial_type||"offensive_profile_content"===e.profile_interstitial_type||"timeout"===e.profile_interstitial_type)&&(void 0===e.withheld_in_countries||Array.isArray(e.withheld_in_countries)&&e.withheld_in_countries.every(e=>"string"==typeof e))&&(void 0===e.has_graduated_access||"boolean"==typeof e.has_graduated_access),e=>"object"==typeof e&&null!==e&&Array.isArray(e.children)&&2===e.children.length&&"object"==typeof e.children[0]&&null!==e.children[0]&&u(e.children[0])&&!0),b=e=>{let t=Object.getOwnPropertyNames(e).find(e=>e.startsWith("__reactProps$"));return t?e[t]:null};class _{profileElement;constructor(e){this.profileElement=e}get props(){let e=(e=>{let t,i=(t=Object.getOwnPropertyNames(e).find(e=>e.startsWith("__reactFiber$")))?e[t]:null;if(!i)return null;let r=i.pendingProps??i.memoizedProps;return w(r)?r.children[0].props.children[1].props.user:null})(this.profileElement);if(e)return e;let t=b(this.profileElement);if(!w(t))throw Error("Failed to get React props of profile");return t.children[0].props.children[1].props.user}}let E=["pro.twitter.com","pro.x.com"],g=(e,t)=>new Promise(i=>{let r=e();if(r instanceof Element||r instanceof NodeList&&r.length)return void i(r);let o=null,l=new MutationObserver(()=>{let t=e();(t instanceof Element||t instanceof NodeList&&t.length)&&(l.disconnect(),o&&clearTimeout(o),i(t))});o=setTimeout(()=>{l.disconnect(),i(null)},t),l.observe(document.body,{attributes:!0,childList:!0,subtree:!0})}),v=async(e,t=document,i=500)=>await g(()=>t.querySelector(e),i),A=async(e,t=document,i=500)=>await g(()=>t.querySelectorAll(e),i)??document.createDocumentFragment().childNodes,N=e=>"TEXTAREA"===e.tagName?e:e.parentElement,P=async(e,t)=>{let i=E.includes(location.hostname),r=[...await A(i?"[role='dialog'] [data-text='true'], [role='dialog'] textarea[data-testid='tweetTextarea_0']":"[role='dialog'] [data-text='true'], textarea[data-testid='tweetTextarea_0']",document,t)];if(!(Array.isArray(r)&&r.length>0))throw Error("[twi-ext] Failed to get text box marker of tweet");for(let e=0;e{open(`https://x.com/intent/tweet?text=${encodeURIComponent(e)}`,"_blank")};class k{tweetElement;constructor(e){this.tweetElement=e}getMenuBar(){let e=this.tweetElement.querySelector("div[role='group'][id]");if(!e)throw Error("[twi-ext] Failed to get menu bar of tweet");return e}get element(){return this.tweetElement}get props(){let e=b(this.getMenuBar());if(!m(e))throw Error("[twi-ext] Failed to get React props of tweet");return e.children[1].props.retweetWithCommentLink.state.quotedStatus}get metadata(){let e=this.props.user.screen_name,t=this.getMenuBar().parentElement?.parentElement;if(!t)throw Error("[twi-ext] Failed to get grandparent of menu bar of tweet");let i=b(t);if(!y(i))throw Error("[twi-ext] Failed to determine whether it is in focal mode. There may have been a change in X's specifications.");let r=(()=>{let e,t,i,r=[...document.querySelectorAll("body > script:not([src])")].find(e=>e.textContent.trim().startsWith("window.__INITIAL_STATE__"));if(!r)throw Error("[twi-ext] Failed to find initial state.");let[o]=r.textContent.trim().replace(/^window\.__INITIAL_STATE__=/u,"").split(";window.__META_DATA__");if(!o)throw Error("[twi-ext] Failed to extract initial state.");let l=(e=e=>"object"==typeof e.remote&&null!==e.remote&&t(e.remote),t=e=>"object"==typeof e.settings&&null!==e.settings&&i(e.settings),i=e=>"string"==typeof e.screen_name,t=>{var i;return"object"==typeof(i=t=JSON.parse(t))&&null!==i&&"object"==typeof i.settings&&null!==i.settings&&e(i.settings)?t:null})(o);if(!l)throw Error("[twi-ext] Failed to parse initial state.");return l})().settings.remote.settings.screen_name;return{isFocalMode:i.children[0].props.isFocalTweet,isPostedByCurrentUser:e===r}}async clickRetweetButton(e){let t=await v("[data-testid='unretweet'], [data-testid='retweet']",this.tweetElement,e);if(!t)throw Error("[twi-ext] Failed to get retweet button of tweet");t.click()}static async clickQuoteButton(e){let t=await v("[data-testid='Dropdown'] [href='/compose/post'],[data-testid='sheetDialog'] [href='/compose/post']",document,e);if(!t)throw Error("[twi-ext] Failed to get quote button of tweet");t.click()}async quoteTweet(e,t=1e3,i=!1){let r=this.props.permalink,o=`${e} +https://x.com${r}`;if(i)return void T(o);try{await this.clickRetweetButton(t),await k.clickQuoteButton(t),await P(e,t)}catch{T(o)}}}class x{OBSERVER_OPTIONS={childList:!0,subtree:!0};static PROFILE_PROPS_MAX_ATTEMPTS=30;static PROFILE_SELECTOR=':not([data-testid="tweet"]) [data-testid="UserName"]';checkedDataAttribute;profileNameObservers=new WeakMap;onNewTweetCallback=null;onNewProfileCallback=null;constructor(e){this.checkedDataAttribute=`data-twi-ext-checked-${crypto.randomUUID()}`;const t={timeoutMs:1e4,...e},i=new MutationObserver(()=>{if(this.onNewTweetCallback)for(let e of document.querySelectorAll(`[data-testid="tweet"]:not([${this.checkedDataAttribute}])`))e.setAttribute(this.checkedDataAttribute,""),this.onNewTweetCallback(new k(e));if(this.onNewProfileCallback){let e=document.querySelector(`${x.PROFILE_SELECTOR}:not([${this.checkedDataAttribute}])`);e&&this.handleProfile(e)}});v("main",document,t.timeoutMs).then(e=>{if(!e)throw Error("[twi-ext] Failed to get main element");i.observe(e,this.OBSERVER_OPTIONS)}),v("#layers",document,t.timeoutMs).then(e=>{if(!e)throw Error("[twi-ext] Failed to get #layers element");i.observe(e,this.OBSERVER_OPTIONS)}),window.addEventListener("pageshow",()=>{if(!this.onNewProfileCallback)return;let e=document.querySelector(x.PROFILE_SELECTOR);e&&this.handleProfile(e,{forceRefresh:!0})})}onNewTweet(e){this.onNewTweetCallback=e}onNewProfile(e){this.onNewProfileCallback=e}observeProfileName(e){let t=x.getNameContainerFromProfile(e);if(!t||!this.onNewProfileCallback||this.profileNameObservers.has(t))return;let i=t.innerText.trim(),r=new MutationObserver(()=>{let e=t.innerText.trim(),i=this.profileNameObservers.get(t);if(i&&e!==i.lastName&&this.onNewProfileCallback){i.lastName=e;let r=x.normalizeScreenName(e);requestAnimationFrame(()=>{this.emitProfileWithFreshProps(t,r)})}});this.profileNameObservers.set(t,{lastName:i,observer:r}),r.observe(t,{characterData:!0,childList:!0,subtree:!0})}static normalizeScreenName(e){return e.trim().replace(/^@/u,"").toLowerCase()}static getNameContainerFromProfile(e){return e.querySelector(`${x.PROFILE_SELECTOR} [tabindex] [dir]`)??null}handleProfile(e,t){if(!this.onNewProfileCallback||!t?.forceRefresh&&e.hasAttribute(this.checkedDataAttribute))return;e.setAttribute(this.checkedDataAttribute,""),this.observeProfileName(e);let i=x.getNameContainerFromProfile(e);if(i){let e=this.profileNameObservers.get(i);e&&(e.lastName=i.innerText.trim())}let r=i?x.normalizeScreenName(i.innerText):null;this.emitProfileWithFreshProps(e,r)}emitProfileWithFreshProps(e,t,i=0){if(!this.onNewProfileCallback)return;let r=e.closest('[data-testid="UserName"]');if(!r)return;let o=new _(r),l=x.normalizeScreenName(o.props.screen_name),n=t??l;l!==n&&i{this.emitProfileWithFreshProps(e,n,i+1)}):this.onNewProfileCallback(o)}}var S=function(){var e=document.querySelectorAll("[role='group'] a[href$='analytics']"),t=!0,i=!1,r=void 0;try{for(var o,l,n,s=e[Symbol.iterator]();!(t=(n=s.next()).done);t=!0){var a=n.value;a.parentElement&&(a.href="",a.parentElement.style.display="none")}}catch(e){i=!0,r=e}finally{try{t||null==s.return||s.return()}finally{if(i)throw r}}var c=document.querySelector("a[aria-describedby] time");if(null==c||null==(l=c.parentElement)||null==(o=l.parentElement)?void 0:o.parentElement){var u=c.parentElement.parentElement.parentElement.querySelectorAll("div ~ *"),d=!0,p=!1,h=void 0;try{for(var f,m=u[Symbol.iterator]();!(d=(f=m.next()).done);d=!0)f.value.style.display="none"}catch(e){p=!0,h=e}finally{try{d||null==m.return||m.return()}finally{if(p)throw h}}}};new x().onNewTweet(function(){S()})})(); \ No newline at end of file