-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.user.js
19 lines (19 loc) · 10.2 KB
/
index.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// ==UserScript==
// @name Hide View Count
// @namespace https://github.com/Robot-Inventor/hide-view-count
// @version 2.2.3
// @description This extension hides the number of impressions on Twitter and prevents the creation of an approval desire monster. It won't allow the View Count to be displayed for even a second!
// @author Robot-Inventor (ろぼいん / @keita_roboin)
// @match https://twitter.com/*
// @match https://mobile.twitter.com/*
// @match https://pro.twitter.com/*
// @match https://x.com/*
// @match https://mobile.x.com/*
// @match https://pro.x.com/*
// @icon https://raw.githubusercontent.com/Robot-Inventor/hide-view-count/main/public/image/icon512.png
// @downloadURL https://raw.githubusercontent.com/Robot-Inventor/hide-view-count/main/index.user.js
// @updateURL https://raw.githubusercontent.com/Robot-Inventor/hide-view-count/main/index.user.js
// @grant none
// ==/UserScript==
(()=>{"use strict";var e={},t={};function r(i){var l=t[i];if(void 0!==l)return l.exports;var o=t[i]={exports:{}};return e[i](o,o.exports,r),o.exports}r.rv=function(){return"1.2.5"},r.ruid="[email protected]";let i=(()=>{let e=e=>Array.isArray(e.children)&&"object"==typeof e.children[1]&&null!==e.children[1]&&t(e.children[1])&&Array.isArray(e.children.slice(2)),t=e=>"object"==typeof e.props&&null!==e.props&&r(e.props),r=e=>"object"==typeof e.retweetWithCommentLink&&null!==e.retweetWithCommentLink&&i(e.retweetWithCommentLink),i=e=>"object"==typeof e.state&&null!==e.state&&l(e.state),l=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);return t=>"object"==typeof t&&null!==t&&e(t)})(),l=(()=>{let e=e=>Array.isArray(e.children)&&Array.isArray(e.children[0])&&"object"==typeof e.children[0][1]&&null!==e.children[0][1]&&t(e.children[0][1])&&Array.isArray(e.children[0].slice(2))&&Array.isArray(e.children.slice(1)),t=e=>"object"==typeof e.props&&null!==e.props&&r(e.props),r=e=>Array.isArray(e.children)&&"object"==typeof e.children[0]&&null!==e.children[0]&&i(e.children[0])&&Array.isArray(e.children.slice(1)),i=e=>"object"==typeof e.props&&null!==e.props&&l(e.props),l=e=>Array.isArray(e.children)&&"object"==typeof e.children[1]&&null!==e.children[1]&&o(e.children[1])&&Array.isArray(e.children.slice(2)),o=e=>"object"==typeof e.props&&null!==e.props&&n(e.props),n=e=>Array.isArray(e.children)&&Array.isArray(e.children[1])&&"object"==typeof e.children[1][2]&&null!==e.children[1][2]&&s(e.children[1][2])&&Array.isArray(e.children[1].slice(3))&&Array.isArray(e.children.slice(2)),s=e=>"object"==typeof e.props&&null!==e.props&&a(e.props),a=e=>"object"==typeof e.loggedInUser&&null!==e.loggedInUser&&c(e.loggedInUser),c=e=>"string"==typeof e.screen_name;return t=>"object"==typeof t&&null!==t&&e(t)})(),o=(()=>{let e=e=>Array.isArray(e.children)&&Array.isArray(e.children[0])&&"object"==typeof e.children[0][1]&&null!==e.children[0][1]&&t(e.children[0][1])&&Array.isArray(e.children[0].slice(2))&&Array.isArray(e.children.slice(1)),t=e=>"object"==typeof e.props&&null!==e.props&&r(e.props),r=e=>Array.isArray(e.children)&&"object"==typeof e.children[0]&&null!==e.children[0]&&i(e.children[0])&&Array.isArray(e.children.slice(1)),i=e=>"object"==typeof e.props&&null!==e.props&&l(e.props),l=e=>Array.isArray(e.children)&&"object"==typeof e.children[2]&&null!==e.children[2]&&o(e.children[2])&&Array.isArray(e.children.slice(3)),o=e=>"object"==typeof e.props&&null!==e.props&&n(e.props),n=e=>Array.isArray(e.children)&&"object"==typeof e.children[7]&&null!==e.children[7]&&s(e.children[7])&&Array.isArray(e.children.slice(8)),s=e=>"object"==typeof e.props&&null!==e.props&&a(e.props),a=e=>"object"==typeof e.loggedInUser&&null!==e.loggedInUser&&c(e.loggedInUser),c=e=>"string"==typeof e.screen_name;return t=>"object"==typeof t&&null!==t&&e(t)})(),n=(()=>{let e=e=>Array.isArray(e.children)&&2===e.children.length&&"object"==typeof e.children[0]&&null!==e.children[0]&&t(e.children[0])&&!0,t=e=>"object"==typeof e.props&&null!==e.props&&r(e.props),r=e=>Array.isArray(e.children)&&2===e.children.length&&"object"==typeof e.children[1]&&null!==e.children[1]&&i(e.children[1]),i=e=>"object"==typeof e.props&&null!==e.props&&l(e.props),l=e=>"object"==typeof e.user&&null!==e.user&&o(e.user),o=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);return t=>"object"==typeof t&&null!==t&&e(t)})(),s=e=>Array.isArray(e)&&e.length>0,a=e=>{let t=Object.getOwnPropertyNames(e).filter(e=>e.startsWith("__reactProps$"));return s(t)?e[t[0]]:null};class c{profileElement;constructor(e){this.profileElement=e}get props(){let e=a(this.profileElement);if(!n(e))throw Error("Failed to get React props of profile");return e.children[0].props.children[1].props.user}}let p=["pro.twitter.com","pro.x.com"],d=(e,t)=>new Promise(r=>{let i=e();if(i instanceof Element||i instanceof NodeList&&i.length){r(i);return}let l=null,o=new MutationObserver(()=>{let t=e();(t instanceof Element||t instanceof NodeList&&t.length)&&(o.disconnect(),l&&clearTimeout(l),r(t))});l=setTimeout(()=>{o.disconnect(),r(null)},t),o.observe(document.body,{attributes:!0,childList:!0,subtree:!0})}),y=async(e,t=document,r=500)=>await d(()=>t.querySelector(e),r),u=async(e,t=document,r=500)=>await d(()=>t.querySelectorAll(e),r)??document.createDocumentFragment().childNodes,h=e=>"TEXTAREA"===e.tagName,f=e=>h(e)?e:e.parentElement,w=async(e,t)=>{let r=p.includes(location.hostname),i=[...await u(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(!s(i))throw Error("[twi-ext] Failed to get text box marker of tweet");for(let e=0;e<i.length;e++){let t=i[e];if(0!==e&&t){let e=f(t);e&&e.remove()}}let l=f(i[0]);if(!l)throw Error("[twi-ext] Failed to get text box of tweet");l.innerHTML=e,l.dispatchEvent(new Event("input",{bubbles:!0}))},b=e=>{open(`https://x.com/intent/tweet?text=${encodeURIComponent(e)}`,"_blank")};class m{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=a(this.getMenuBar());if(!i(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=a(this.element);if(!t)throw Error("[twi-ext] Failed to get React props of tweet");let r=null,i=o(t);return l(t)&&(r=t.children[0][1].props.children[0].props.children[1].props.children[1][2].props.loggedInUser.screen_name),i&&(r=t.children[0][1].props.children[0].props.children[2].props.children[7].props.loggedInUser.screen_name),{isFocalMode:i,isPostedByCurrentUser:e===r}}async clickRetweetButton(e){let t=await y("[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 y("[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,l=`${e}
https://x.com${i}`;if(r){b(l);return}try{await this.clickRetweetButton(t),await m.clickQuoteButton(t),await w(e,t)}catch{b(l)}}}var A=function(){var e=document.querySelectorAll("[role='group'] a[href$='analytics']"),t=!0,r=!1,i=void 0;try{for(var l,o,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){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?void 0:null===(o=c.parentElement)||void 0===o?void 0:null===(l=o.parentElement)||void 0===l?void 0:l.parentElement){var p=c.parentElement.parentElement.parentElement.querySelectorAll("div ~ *"),d=!0,y=!1,u=void 0;try{for(var h,f=p[Symbol.iterator]();!(d=(h=f.next()).done);d=!0)h.value.style.display="none"}catch(e){y=!0,u=e}finally{try{d||null==f.return||f.return()}finally{if(y)throw u}}}};new class{OBSERVER_OPTIONS={childList:!0,subtree:!0};onNewTweetCallback=null;onNewProfileCallback=null;constructor(e){let 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 m(e));if(this.onNewProfileCallback){let e=document.querySelector(`:not([data-testid="tweet"]) [data-testid="UserName"]:not([${t}])`);e&&(e.setAttribute(t,""),this.onNewProfileCallback(new c(e)))}});y("main",document,r.timeoutMs).then(e=>{if(!e)throw Error("[twi-ext] Failed to get main element");i.observe(e,this.OBSERVER_OPTIONS)}),y("#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(){A()})})();