Greasy Fork is available in English.

Show date normally on Twitter

Like this, 70/12/31(Th) 23:59:59.

// ==UserScript==
// @name                 Show date normally on Twitter
// @name:ja              Twitter で日時を通常の表記に
// @name:ko              트위터에서 날짜와 시간을 일반 표기법으로 변경
// @name:zh-CN           在推特上显示正常的日期和时间
// @name:zh-TW           在推特上顯示正常的日期和時間
// @namespace            https://greasyfork.org/en/scripts/462064-show-date-normally-on-twitter
// @version              1.20.6
// @description          Like this, 70/12/31(Th) 23:59:59.
// @description:ja       こんな感じです。70/12/31(Th) 23:59:59。
// @description:ko       이런 느낌입니다. 70/12/31(Th) 23:59:59。
// @description:zh-CN    看起来是这样的。70/12/31(Th) 23:59:59。
// @description:zh-TW    看起來是這樣的。70/12/31(Th) 23:59:59。
// @author               AeamaN
// @contributionURL      bitcoin:1DC6uWJWzzwU3iRJDXhUquv6QAYaRvtfFJ
// @match                https://twitter.com/*
// @match                https://mobile.twitter.com/*
// @match                https://twitter3e4tixl4xyajtrzo62zg5vztmjuricljdp2c5kshju4avyoid.onion/*
// @match                https://mobile.twitter3e4tixl4xyajtrzo62zg5vztmjuricljdp2c5kshju4avyoid.onion/*
// @match                https://x.com/*
// @match                https://mobile.x.com/*
// @require              https://update.greasyfork.org/scripts/487338/1327535/PNG%20BB.js
// @grant                GM_getValue
// @grant                GM_registerMenuCommand
// @grant                GM_setValue
// @run-at               document-body
// ==/UserScript==

// And more. See Default valuse below.
// It's based on "https://qiita.com/libraplanet/items/0bdd7ef1a13e7af8f48f".
//
// 他にも機能があります。以下の Default valuse を確認して下さい。
// "https://qiita.com/libraplanet/items/0bdd7ef1a13e7af8f48f" を参考にしています。

(function () { /* START */


'use strict';

// //////////// Settings //////////// //
// No GUI Settings
// Default values are used
const NO_GUI = false;
// ////////////////////////////////// //

// ///////// Default valuse ///////// //
// Date formats
//  1. Do it
//  0. Do nothing
const FMT = 1;

// YE(70), YF(1970), YEU(UTC), YFU(UTC), YM(59),
// MO(12), DA(31), WE(Th), HO(12), MI(59) and SE(59)
const FMTS = 'YE/MO/DA(WE) HO:MI:SE';

// Week label
const SUN = '😊';
const MON = '😭';
const TUE = 'Tu';
const WED = 'We';
const THU = 'Th';
const FRI = 'Fr';
const SAT = 'Sa';

// Blue bird returns
const BBR = false;

// Replace with orig images(wasted traffic occurs)
const ORIG_IMG = false;

// Slightly wider TL
const WTL = false;

// Eye Care Mode at default background
const EC_MODE = true;

// Hide promotions
const HIDE_PP = true;

// Hide Who to follow
const HIDE_WF = true;

// Hide DM drawer
const HIDE_DMD = true;

// Hide Get Verified
const HIDE_GV = true;

// Fine engagement
// 1. Live
// 2. Normal
// 0. Do nothing
const FINE_EGM = 0;

// Fix videos quality
// 1. Maximum
// 2. Minimum
// 0. Do nothing
const FIX_VQ = 1;

// Loop interval(ms)
const INTL = 800;
// ////////////////////////////////// //

const MYNAME = 'sdnt1206';

const LANG = document.documentElement.getAttribute('lang');

const SETS = {
	'fmt': FMT, 'fmts': FMTS,
	'sun': SUN, 'mon': MON, 'tue': TUE, 'wed': WED, 'thu': THU, 'fri': FRI, 'sat': SAT,
	'bbr': BBR,
	'orig_img': ORIG_IMG,
	'wtl': WTL,
	'ec_mode': EC_MODE,
	'hide_pp': HIDE_PP,
	'hide_wf': HIDE_WF,
	'hide_dmd': HIDE_DMD,
	'hide_gv': HIDE_GV,
	'fine_egm': FINE_EGM,
	'fix_vq': FIX_VQ,
	'intl': INTL
};

const SEL_BR_ID =
	'div#placeholder[aria-label="Loading…"] g path, ' +
	'svg#loading-x-anim-0 g path, svg#loading-x-anim-1 g path, ' +
	'svg#loading-x-anim-2 g path, svg#loading-x-anim-3 g path';
const SEL_BR_H = 'header[role="banner"] h1[role="heading"] g path'; // ホーム
const SEL_BR_M = 'div[data-testid="Dropdown"] a[href="/i/premium_sign_up"] g path'; // もっと見る
const SEL_BR_V = 'header[role="banner"] nav g path'; // 認証済み
const SEL_BR_L = 'div[role="dialog"] div[aria-labelledby="modal-header"] svg.r-lrvibr path'; // ログイン
const SEL_BR_T = 'div#react-root main svg.r-lrvibr path'; // トップ
const DATA_BR_X = 'M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99';
const DATA_BR_BB =
	'M23.643 4.937c-.835.37-1.732.62-2.675.733.962-.576 1.7-1.49 2.048-2.578-.9.534-1' +
	'.897.922-2.958 1.13-.85-.904-2.06-1.47-3.4-1.47-2.572 0-4.658 2.086-4.658 4.66 0' +
	' .364.042.718.12 1.06-3.873-.195-7.304-2.05-9.602-4.868-.4.69-.63 1.49-.63 2.342' +
	' 0 1.616.823 3.043 2.072 3.878-.764-.025-1.482-.234-2.11-.583v.06c0 2.257 1.605 ' +
	'4.14 3.737 4.568-.392.106-.803.162-1.227.162-.3 0-.593-.028-.877-.082.593 1.85 2' +
	'.313 3.198 4.352 3.234-1.595 1.25-3.604 1.995-5.786 1.995-.376 0-.747-.022-1.112' +
	'-.065 2.062 1.323 4.51 2.093 7.14 2.093 8.57 0 13.255-7.098 13.255-13.254 0-.2-.' +
	'005-.402-.014-.602.91-.658 1.7-1.477 2.323-2.41z';
const DATA_BR_FILL_N = 'none';
const DATA_BR_FILL_LB = '#1da1f2ff';
const DATA_BR_FILL_DB = '#1d9bf0ff';
const DATA_BR_S = 'currentColor';
const DATA_BR_SW = '2';
const REPETIT = {
	'ja': ['会話', 'Xユーザーの', ''],
	'ko': ['대화', 'X에서 ', ''],
	'zh-Hant': ['對話', 'X 上的 ', ''],
	'zh': ['对话', 'X 上的 ', ''],
	'ru': ['Переписка', ' в X: «', ': «'],
	'de': ['Konversation', ' auf X: „', ': „'],
	'it': ['Conversazione', ' su X: "', ': "'],
	'fr': ['Conversation', ' sur X : "', ' : "'],
	'pt': ['Conversa', ' no X: "', ': "'],
	'en': ['Conversation', ' on X: "', ': "'] // Add your language
};
const REPETIT_L = REPETIT[LANG] ?? ['', '', ''];

const SEL_OI_D = 'div[style*="background-image:"]';
const SEL_OI_I = 'img';
const REGEX_OI = /^(.+pbs\.twimg\.com\/[^?]+\?format=\w+)(&|&)(name=)(\w+)([")]*)$/;

const SEL_HP = 'path[d^="M19.498 3h-15c-1.381 0-2.5 1.12-2.5 2.5v13c0 1.38 1.119 2.5"]';
const SEL_HP_2 = 'main div[data-testid="sidebarColumn"] section div[data-testid="trend"] div.r-14gqq1x ' +
	'span.css-1qaijid.r-bcqeeo.r-qvutc0'; // def-ja, def-en, ble-ja, ble-en
const SEL_HP_3 = 'main div[data-testid="primaryColumn"] section article ' +
	'span.css-1jxf684.r-bcqeeo.r-qvutc0.r-poiln3';
const SEL_HP_4 =
	'main div[data-testid="primaryColumn"] section ' +
	'span.css-901oao.css-16my406.r-bcqeeo.r-qvutc0';
// Lone label def-ja, def-en, ble-ja, ble-en
const PROMO = {
	'ja': 'によるプロモーション$',
	'ko': ' 님이 프로모션함$',
	'zh-Hant': '^由 .+ 推廣$',
	'zh': '^由 .+ 推广$',
	'ru': '^Реклама от ',
	'de': '^Gesponsert von ',
	'it': '^Sponsorizzato da ',
	'fr': '^Sponsorisé par ',
	'pt': '^Promovido por ',
	'en': '^Promoted by ' // Add your language
};
const PROMO_L = PROMO[LANG] ?? PROMO['en'];
const REGEX_HP = new RegExp(PROMO_L, 'i');
const PROMO_2 = {
	'ja': 'プロモポスト',
	'ko': 'Promoted Post',
	'zh-Hant': '推廣貼文',
	'zh': 'Promoted Post',
	'ru': 'Promoted Post',
	'de': 'Gesponserter Post',
	'it': 'Promoted Post',
	'fr': 'Promoted Post',
	'pt': 'Post promovido',
	'en': 'Promoted Post' // Add your language
};
const PROMO_L_2 = PROMO_2[LANG] ?? PROMO_2['en'];

const PATT_HW =
	'^[^:]+://[^/]+/$|' +
	
	'^[^:]+://[^/]+/(' +
	'compose|' + // pop up
	'search-advanced|' + // pop up
	'home|' + // 除外?
	'search|' +
	
	'i/display|' + // pop up
	'i/flow|' + // pop up
	'i/keyboard_shortcuts|' + // pop up
	'i/verified-orgs-signup|' + // pop up、追加
	'i/verified-choose|' + // pop up、追加
	'i/premium_sign_up|' + // pop up、追加
	'i/connect_people|' +
	'i/topics|' +
	'i/spaces/start|' + // pop up、追加
	'i/verified-application|' + // pop up、追加
	'i/verified-get-verified|' + // pop up、追加
	
	'[^/]+/followers|' +
	'[^/]+/following|' +
	'[^/]+/lists|' +
	'[^/]+/status/|' + // 両方、WTFのみ除外
	'[^/]+/topics|' +
	'[^/]+/creator-subscriptions|' + // 追加
	'[^/]+/superfollows|' + // 追加
	'[^/]+/verified_followers' + // 追加
	')';
const REGEX_HW = new RegExp(PATT_HW, 'i');

const SEL_HD = 'div[data-testid="DMDrawer"]';

const SEL_HG = 'aside.css-175oi2r.r-1habvwh.r-eqz5dr.r-uaa2di.r-1mmae3n.r-3pj75a';
const SEL_HG_2 = 'main section div[data-testid="cellInnerDiv"] h1[role="heading"] span.css-1jxf684.r-bcqeeo.r-qvutc0';
// def-ja, def-en, ble-ja, ble-en
const TC_HG = {
	'gv': {
		'ja': '認証を受ける',
		'ko': '인증 받기',
		'zh-Hant': '獲得認證',
		'zh': '获得认证',
		'ru': 'Подтвердить подлинность',
		'de': 'Lass dich verifizieren',
		'it': 'Ottieni la verifica',
		'fr': 'Obtenez la certification',
		'pt': 'Obter verificação',
		'en': 'Get Verified' // Add your language
	},
	'sp': {
		'ja': 'プレミアムにサブスクライブ',
		'ko': 'Subscribe to Premium',
		'zh-Hant': '訂閱 Premium',
		'zh': 'Subscribe to Premium',
		'ru': 'Subscribe to Premium',
		'de': 'Premium abonnieren',
		'it': 'Subscribe to Premium',
		'fr': 'Subscribe to Premium',
		'pt': 'Assine o Premium',
		'en': 'Subscribe to Premium' // Add your language
	},
	'spylp': {
		'ja': '長いポストを作成するには、プレミアムにサブスクライブしてください',
		'ko': 'Premium을 구독하고 나만의 긴 게시물을 작성해 보세요',
		'zh-Hant': '訂閱 Premium 以撰寫你自己的更長貼文',
		'zh': '订阅 Premium,撰写自己的长帖',
		'ru': 'Подпишитесь на Premium, чтобы писать собственные длинные посты',
		'de': 'Abonniere Premium, wenn du deine eigenen längeren Posts schreiben möchtest',
		'it': 'Per scrivere post più lunghi, abbonati a Premium',
		'fr': 'Abonnez-vous à Premium pour écrire vos propres posts plus longs.',
		'pt': 'Assine o Premium para escrever posts mais longos',
		'en': 'Subscribe to Premium to write your own longer posts' // Add your language
	},
	'gafp': {
		'ja': 'プレミアムプラスで広告をなくす',
		'ko': 'Go ad-free with Premium+',
		'zh-Hant': 'Go ad-free with Premium+',
		'zh': 'Go ad-free with Premium+',
		'ru': 'Go ad-free with Premium+',
		'de': 'Go ad-free with Premium+',
		'it': 'Go ad-free with Premium+',
		'fr': 'Go ad-free with Premium+',
		'pt': 'Go ad-free with Premium+',
		'en': 'Go ad-free with Premium+' // Add your language
	},
	'gaf': {
		'ja': '広告をなくす',
		'ko': 'Go ad free',
		'zh-Hant': 'Go ad free',
		'zh': 'Go ad free',
		'ru': 'Go ad free',
		'de': 'Go ad free',
		'it': 'Go ad free',
		'fr': 'Go ad free',
		'pt': 'Go ad free',
		'en': 'Go ad free' // Add your language
	},
	'txp': {
		'ja': 'TweetDeckはX Proになりました',
		'ko': 'TweetDeck is now X Pro',
		'zh-Hant': 'TweetDeck is now X Pro',
		'zh': 'TweetDeck is now X Pro',
		'ru': 'TweetDeck is now X Pro',
		'de': 'TweetDeck is now X Pro',
		'it': 'TweetDeck is now X Pro',
		'fr': 'TweetDeck is now X Pro',
		'pt': 'TweetDeck is now X Pro',
		'en': 'TweetDeck is now X Pro' // Add your language
	}
};
const GV_L = TC_HG.gv[LANG] ?? TC_HG.gv['en'];
const SP_L = TC_HG.sp[LANG] ?? TC_HG.sp['en'];
const SPYLP_L = TC_HG.spylp[LANG] ?? TC_HG.spylp['en'];
const GAFP_L = TC_HG.gafp[LANG] ?? TC_HG.gafp['en'];
const GAF_L = TC_HG.gaf[LANG] ?? TC_HG.gaf['en'];
const TXP_L = TC_HG.txp[LANG] ?? TC_HG.txp['en'];

const SEL_FE_R =
	'main div[data-testid="primaryColumn"] section article ' +
	'button.css-175oi2r.r-1777fci.r-bt1l66.r-bztko3.r-lrvibr.r-1loqt21.r-1ny4l3l[data-testid*="reply"] ' +
	'div>span[data-testid="app-text-transition-container"]>span'; // 一つ上
const SEL_FE_T =
	'main div[data-testid="primaryColumn"] section article ' +
	'button.css-175oi2r.r-1777fci.r-bt1l66.r-bztko3.r-lrvibr.r-1loqt21.r-1ny4l3l[data-testid*="retweet"] ' +
	'div>span[data-testid="app-text-transition-container"]>span';
const SEL_FE_L =
	'main div[data-testid="primaryColumn"] section article ' +
	'button.css-175oi2r.r-1777fci.r-bt1l66.r-bztko3.r-lrvibr.r-1loqt21.r-1ny4l3l[data-testid*="like"] ' +
	'div>span[data-testid="app-text-transition-container"]>span';
const SEL_FE_B =
	'main div[data-testid="primaryColumn"] section article ' +
	'button.css-175oi2r.r-1777fci.r-bt1l66.r-bztko3.r-lrvibr.r-1loqt21.r-1ny4l3l[data-testid*="bookmark"] ' +
	'div>span[data-testid="app-text-transition-container"]>span';

const SEL_ADD_SPAN = 'span.us-' + MYNAME;

const SEL_FEVD =
	'main div[data-testid="primaryColumn"] section article ' +
	'div.css-175oi2r.r-1d09ksm.r-1471scf.r-18u37iz.r-1wbh5a2>' +
	'div>span>div>span[data-testid="app-text-transition-container"]>span>span:not(.us-' + MYNAME + ')';
// 表示回数は減らない、0の時は無い
const SEL_FEVD_2 =
	'button.css-175oi2r.r-1777fci.r-bt1l66.r-bztko3.r-lrvibr.r-1loqt21.r-1ny4l3l[data-testid*="retweet"] ' +
	'div>span[data-testid="app-text-transition-container"]>span'; // 一つ上

const SEL_FEVT =
	'main div[data-testid="primaryColumn"] section article ' +
	'a[href$="/analytics"][aria-label][role="link"]>div>div>span[data-testid="app-text-transition-container"]>' +
	'span>span:not(.us-' + MYNAME + ')'; // 二つ下から消える

const SEL_FEP =
	'main div[data-testid="primaryColumn"] div[aria-label] ' +
	'h2[role="heading"]~div.css-146c3p1.r-n6v787.r-1cwl3u0';
const SEL_FEP_2 =
	'script[data-testid="UserProfileSchema-test"]';

const SEL_ADD_DIV = 'div.us-' + MYNAME;

const REGEX_TXSH = /#EXT-X-STREAM-INF.*[^-]BANDWIDTH=(\d+).*\r?\n\/.+$/gm;

const SEL_RD =
	'main div[data-testid="primaryColumn"] section article time[datetime*=":"]';
const SEL_RD_2 =
	'div[aria-labelledby="modal-header"] div[data-testid^="User-Name"] time[datetime]';
const SEL_RD_3 =
	'div[aria-labelledby="modal-header"] div[aria-label] time[datetime]';
const SEL_RD_4 =
	'main section[aria-labelledby="detail-header"] article div[data-testid^="User-Name"] time[datetime]';
const SEL_RD_5 =
	'main section div[data-testid="conversation"] div[aria-label] time[datetime]'; // DM list

let time_fine_egm = Date.now();
let muts = true;
let observer = new MutationObserver(function (mutations) {
	muts = mutations;
});
let orig_xhr_open;
let sets = {};

function makeDalg() {
	let dalg = document.createElement('div');
	
	dalg.className = 'us-' + MYNAME;
	
	dalg.style.all = 'initial';
	dalg.style.backgroundColor = 'rgb(235, 235, 235)';
	dalg.style.border = '3px outset';
	dalg.style.borderRadius = '1%';
	dalg.style.display = 'none';
	dalg.style.fontFamily = 'monospace';
	dalg.style.fontSize = '12px';
	dalg.style.height = '440px';
	dalg.style.width = '480px';
	dalg.style.paddingLeft = '2px';
	dalg.style.paddingRight = '2px';
	dalg.style.position = 'fixed';
	dalg.style.right = '8px';
	dalg.style.top = '8px';
	dalg.style.zIndex = '2147483647';
	dalg.style.overflow = 'auto';
	
	const HTML =
		'<span style="all: initial; font-size: 120%; line-height: 210%">' +
		GM_info.script.name + ' ' + GM_info.script.version + ' ' + 'Settings' +
		'</span><br />\n' +
		
		'<input type="radio" name="fmt" value="1" class="top_r" />' +
		'<input type="text" name="fmts" size="28" class="top_t" />(*1)<br />\n' +
		'&nbsp;&nbsp;' +
		'<input type="text" name="sun" size="5" class="btm_t" />' +
		'<input type="text" name="mon" size="5" class="btm_t" />' +
		'<input type="text" name="tue" size="5" class="btm_t" />' +
		'<input type="text" name="wed" size="5" class="btm_t" />' +
		'<input type="text" name="thu" size="5" class="btm_t" />' +
		'<input type="text" name="fri" size="5" class="btm_t" />' +
		'<input type="text" name="sat" size="5" class="btm_t" />(*2)<br />\n' +
		'<input type="radio" name="fmt" value="0" class="btm_r" />Do nothing<br />\n' +
		
		'<input type="checkbox" name="bbr" class="top_c" />BB returns' +
		'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
		'<input type="checkbox" name="orig_img" class="mid_c" />Replace with orig images(*3)<br />\n' +
		'<input type="checkbox" name="wtl" class="mid_c" />Widen slightly TL' +
		'&nbsp;&nbsp;&nbsp;&nbsp;' +
		'<input type="checkbox" name="ec_mode" class="btm_c" />Eye Care Mode at default BG<br />\n' +
		'<input type="checkbox" name="hide_pp" class="top_c" />Hide promotions' +
		'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
		'<input type="checkbox" name="hide_wf" class="mid_c" />Hide Who to follow<br />\n' +
		'<input type="checkbox" name="hide_dmd" class="mid_c" />Hide DM drawer' +
		'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
		'<input type="checkbox" name="hide_gv" class="btm_c" />Hide Get Verified<br />\n' +
		
		'<input type="radio" name="fine_egm" value="1" class="top_r" />Fine engagement(live)' +
		'&nbsp;&nbsp;&nbsp;&nbsp;' +
		'<input type="radio" name="fine_egm" value="2" class="top_r" />Fine engagement(normal)<br />\n' +
		'<input type="radio" name="fine_egm" value="0" class="btm_r" />Do nothing<br />\n' +
		
		'<input type="radio" name="fix_vq" value="1" class="top_r" />at maximum video quality' +
		'&nbsp;&nbsp;&nbsp;&nbsp;' +
		'<input type="radio" name="fix_vq" value="2" class="top_r" />at minimum video quality<br />\n' +
		'<input type="radio" name="fix_vq" value="0" class="btm_r" />Do nothing(*4)<br />\n' +
		
		'<span style="all: initial; font-size: 100%">' +
		'Loop interval(ms)&nbsp;' +
		'</span><input type="text" name="intl" size="10" class="top_t" />(*4)<br />\n' +
		
		'<br />\n' +
		'<span style="all: initial; font-size: 100%; line-height: 140%">' +
		'(*1)Symbols YE(70), YF(1970), YEU(UTC), YFU(UTC), YM(59),<br />\n' +
		'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MO(12), DA(31), WE(Th), HO(12), MI(59) and SE(59) are available<br />\n' +
		'(*2)Sunday origin&nbsp;&nbsp;&nbsp;&nbsp;(*3)wasted traffic occurs&nbsp;&nbsp;&nbsp;&nbsp;(*4)Restart required' +
		
		'<input type="button" class="top_b" value="Cancel" />\n' +
		'<input type="button" class="top_b" value="Set default" />\n' +
		'<input type="button" class="top_b" value="Save & Close" /><br /><br />\n';
	
	dalg.innerHTML = HTML;
	
	for (let e of dalg.querySelectorAll('input.top_r, input.mid_r, input.btm_r')) {
		e.style.all = 'initial';
		e.style.appearance = 'auto';
		e.style.marginRight = '1px';
		e.style.marginTop = '1px';
	}
	for (let e of dalg.querySelectorAll('input.top_c, input.mid_c, input.btm_c')) {
		e.style.all = 'initial';
		e.style.appearance = 'auto';
		e.style.marginRight = '1px';
		e.style.marginTop = '1px';
	}
	for (let e of dalg.querySelectorAll('input.top_t')) {
		e.style.all = 'initial';
		e.style.backgroundColor = 'rgb(255, 255, 255)';
		e.style.fontFamily = 'monospace';
		e.style.fontSize = '100%';
		e.style.marginLeft = '1px';
		e.style.marginRight = '1px';
		e.style.marginTop = '8px';
		e.style.marginBottom = '0px';
		e.style.paddingLeft = '1px';
		e.style.paddingRight = '1px';
		e.style.paddingTop = '1px';
		e.style.paddingBottom = '1px';
	}
	for (let e of dalg.querySelectorAll('input.btm_t')) {
		e.style.all = 'initial';
		e.style.backgroundColor = 'rgb(255, 255, 255)';
		e.style.fontFamily = 'monospace';
		e.style.fontSize = '100%';
		e.style.marginLeft = '1px';
		e.style.marginRight = '4px';
		e.style.marginTop = '2px';
		e.style.marginBottom = '0px';
		e.style.paddingLeft = '1px';
		e.style.paddingRight = '1px';
		e.style.paddingTop = '1px';
		e.style.paddingBottom = '1px';
	}
	for (let e of dalg.querySelectorAll('input.top_b')) {
		e.style.all = 'initial';
		e.style.backgroundColor = 'rgb(190, 190, 190)';
		e.style.borderRadius = '10%';
		e.style.cursor = 'default';
		e.style.fontSize = '110%';
		e.style.marginTop = '26px';
		e.style.marginBottom = '0px';
		e.style.paddingTop = '6px';
		e.style.paddingBottom = '6px';
		e.style.textAlign = 'center';
		e.style.width = '90px';
	}
	
	return dalg;
}

function makeFunc(dalg) {
	dalg.addEventListener(
		'click',
		function (event) { event.stopPropagation(); },
		false
	);
	
	dalg.querySelector('input[value="Cancel"]').addEventListener(
		'click',
		function () { dalg.style.display = 'none'; },
		false
	);
	dalg.querySelector('input[value="Cancel"]').addEventListener(
		'mouseenter',
		function (event) { event.target.style.backgroundColor = 'rgb(170, 170, 170)'; },
		false
	);
	dalg.querySelector('input[value="Cancel"]').addEventListener(
		'mouseleave',
		function (event) { event.target.style.backgroundColor = 'rgb(190, 190, 190)'; },
		false
	);
	
	dalg.querySelector('input[value="Set default"]').addEventListener(
		'click',
		function () {
			dalg.querySelector('input[name="fmt"][value="' + FMT + '"]').checked = true;
			dalg.querySelector('input[name="fmts"]').value = FMTS;
			dalg.querySelector('input[name="sun"]').value = SUN;
			dalg.querySelector('input[name="mon"]').value = MON;
			dalg.querySelector('input[name="tue"]').value = TUE;
			dalg.querySelector('input[name="wed"]').value = WED;
			dalg.querySelector('input[name="thu"]').value = THU;
			dalg.querySelector('input[name="fri"]').value = FRI;
			dalg.querySelector('input[name="sat"]').value = SAT;
			dalg.querySelector('input[name="bbr"]').checked = BBR;
			dalg.querySelector('input[name="orig_img"]').checked = ORIG_IMG;
			dalg.querySelector('input[name="wtl"]').checked = WTL;
			dalg.querySelector('input[name="ec_mode"]').checked = EC_MODE;
			dalg.querySelector('input[name="hide_pp"]').checked = HIDE_PP;
			dalg.querySelector('input[name="hide_wf"]').checked = HIDE_WF;
			dalg.querySelector('input[name="hide_dmd"]').checked = HIDE_DMD;
			dalg.querySelector('input[name="hide_gv"]').checked = HIDE_GV;
			dalg.querySelector('input[name="fine_egm"][value="' + FINE_EGM + '"]').checked = true;
			dalg.querySelector('input[name="fix_vq"][value="' + FIX_VQ + '"]').checked = true;
			dalg.querySelector('input[name="intl"]').value = INTL;
		},
		false
	);
	dalg.querySelector('input[value="Set default"]').addEventListener(
		'mouseenter',
		function (event) {event.target.style.backgroundColor = 'rgb(170, 170, 170)';},
		false
	);
	dalg.querySelector('input[value="Set default"]').addEventListener(
		'mouseleave',
		function (event) {event.target.style.backgroundColor = 'rgb(190, 190, 190)';},
		false
	);
	
	dalg.querySelector('input[value="Save & Close"]').addEventListener(
		'click',
		function () {
			for (let e of dalg.querySelectorAll('input[name="fmt"]')) {
				if (e.checked) {
					sets.fmt = +e.value;
					break;
				}
			}
			sets.fmts = dalg.querySelector('input[name="fmts"]').value;
			sets.sun = dalg.querySelector('input[name="sun"]').value;
			sets.mon = dalg.querySelector('input[name="mon"]').value;
			sets.tue = dalg.querySelector('input[name="tue"]').value;
			sets.wed = dalg.querySelector('input[name="wed"]').value;
			sets.thu = dalg.querySelector('input[name="thu"]').value;
			sets.fri = dalg.querySelector('input[name="fri"]').value;
			sets.sat = dalg.querySelector('input[name="sat"]').value;
			sets.bbr = dalg.querySelector('input[name="bbr"]').checked;
			sets.orig_img = dalg.querySelector('input[name="orig_img"]').checked;
			sets.wtl = dalg.querySelector('input[name="wtl"]').checked;
			sets.ec_mode = dalg.querySelector('input[name="ec_mode"]').checked;
			sets.hide_pp = dalg.querySelector('input[name="hide_pp"]').checked;
			sets.hide_wf = dalg.querySelector('input[name="hide_wf"]').checked;
			sets.hide_dmd = dalg.querySelector('input[name="hide_dmd"]').checked;
			sets.hide_gv = dalg.querySelector('input[name="hide_gv"]').checked;
			for (let e of dalg.querySelectorAll('input[name="fine_egm"]')) {
				if (e.checked) {
					sets.fine_egm = +e.value;
					break;
				}
			}
			for (let e of dalg.querySelectorAll('input[name="fix_vq"]')) {
				if (e.checked) {
					sets.fix_vq = +e.value;
					break;
				}
			}
			sets.intl = +dalg.querySelector('input[name="intl"]').value;
			
			GM_setValue('fmt', sets.fmt);
			GM_setValue('fmts', sets.fmts);
			GM_setValue('sun', sets.sun);
			GM_setValue('mon', sets.mon);
			GM_setValue('tue', sets.tue);
			GM_setValue('wed', sets.wed);
			GM_setValue('thu', sets.thu);
			GM_setValue('fri', sets.fri);
			GM_setValue('sat', sets.sat);
			GM_setValue('bbr', sets.bbr);
			GM_setValue('orig_img', sets.orig_img);
			GM_setValue('wtl', sets.wtl);
			GM_setValue('ec_mode', sets.ec_mode);
			GM_setValue('hide_pp', sets.hide_pp);
			GM_setValue('hide_wf', sets.hide_wf);
			GM_setValue('hide_dmd', sets.hide_dmd);
			GM_setValue('hide_gv', sets.hide_gv);
			GM_setValue('fine_egm', sets.fine_egm);
			GM_setValue('fix_vq', sets.fix_vq);
			GM_setValue('intl', sets.intl);
			
			dalg.style.display = 'none';
		},
		false
	);
	dalg.querySelector('input[value="Save & Close"]').addEventListener(
		'mouseenter',
		function (event) { event.target.style.backgroundColor = 'rgb(170, 170, 170)'; },
		false
	);
	dalg.querySelector('input[value="Save & Close"]').addEventListener(
		'mouseleave',
		function (event) { event.target.style.backgroundColor = 'rgb(190, 190, 190)'; },
		false
	);
}

function initGUI() {
	for (let v in SETS) {
		if (GM_getValue(v) === undefined) {
			GM_setValue(v, SETS[v]);
		} else {
			sets[v] = GM_getValue(v);
		}
	}
	
	let dalg = makeDalg();
	makeFunc(dalg);
	document.body.appendChild(dalg);
	
	GM_registerMenuCommand('Settings', function () {
		if (dalg.style.display == 'none') {
			dalg.querySelector('input[name="fmt"][value="' + sets.fmt + '"]').checked = true;
			dalg.querySelector('input[name="fmts"]').value = sets.fmts;
			dalg.querySelector('input[name="sun"]').value = sets.sun;
			dalg.querySelector('input[name="mon"]').value = sets.mon;
			dalg.querySelector('input[name="tue"]').value = sets.tue;
			dalg.querySelector('input[name="wed"]').value = sets.wed;
			dalg.querySelector('input[name="thu"]').value = sets.thu;
			dalg.querySelector('input[name="fri"]').value = sets.fri;
			dalg.querySelector('input[name="sat"]').value = sets.sat;
			dalg.querySelector('input[name="bbr"]').checked = sets.bbr;
			dalg.querySelector('input[name="orig_img"]').checked = sets.orig_img;
			dalg.querySelector('input[name="wtl"]').checked = sets.wtl;
			dalg.querySelector('input[name="ec_mode"]').checked = sets.ec_mode;
			dalg.querySelector('input[name="hide_pp"]').checked = sets.hide_pp;
			dalg.querySelector('input[name="hide_wf"]').checked = sets.hide_wf;
			dalg.querySelector('input[name="hide_dmd"]').checked = sets.hide_dmd;
			dalg.querySelector('input[name="hide_gv"]').checked = sets.hide_gv;
			dalg.querySelector('input[name="fine_egm"][value="' + sets.fine_egm + '"]').checked = true;
			dalg.querySelector('input[name="fix_vq"][value="' + sets.fix_vq + '"]').checked = true;
			dalg.querySelector('input[name="intl"]').value = sets.intl;
			
			dalg.style.display = 'block';
		}
	});
}

function fmtDate(fmt, date) {
	let datetime;
	
	if (sets.fmts.indexOf('YEU') >= 0 || sets.fmts.indexOf('YFU') >= 0) {
		const WN = date.getUTCDay();
		datetime = {
			'YEU': date.getUTCFullYear().toString().slice(-2),
			'YFU': date.getUTCFullYear(),
			'MO': ('0' + (date.getUTCMonth() + 1)).slice(-2),
			'DA': ('0' + date.getUTCDate()).slice(-2),
			'WE':
				WN == 0 ? sets.sun :
				WN == 1 ? sets.mon :
				WN == 2 ? sets.tue :
				WN == 3 ? sets.wed :
				WN == 4 ? sets.thu :
				WN == 5 ? sets.fri :
				WN == 6 ? sets.sat :
					'?',
			'HO': ('0' + date.getUTCHours()).slice(-2),
			'MI': ('0' + date.getUTCMinutes()).slice(-2),
			'SE': ('0' + date.getUTCSeconds()).slice(-2)
		};
	} else if (sets.fmts.indexOf('YM') >= 0) {
		date.setUTCHours(date.getUTCHours() + 8);
		
		const WN = date.getUTCDay();
		datetime = {
			'YM': date.getUTCFullYear() - 1911,
			'MO': ('0' + (date.getUTCMonth() + 1)).slice(-2),
			'DA': ('0' + date.getUTCDate()).slice(-2),
			'WE':
				WN == 0 ? sets.sun :
				WN == 1 ? sets.mon :
				WN == 2 ? sets.tue :
				WN == 3 ? sets.wed :
				WN == 4 ? sets.thu :
				WN == 5 ? sets.fri :
				WN == 6 ? sets.sat :
					'?',
			'HO': ('0' + date.getUTCHours()).slice(-2),
			'MI': ('0' + date.getUTCMinutes()).slice(-2),
			'SE': ('0' + date.getUTCSeconds()).slice(-2)
		};
	} else {
		const WN = date.getDay();
		datetime = {
			'YE': date.getFullYear().toString().slice(-2),
			'YF': date.getFullYear(),
			'MO': ('0' + (date.getMonth() + 1)).slice(-2),
			'DA': ('0' + date.getDate()).slice(-2),
			'WE':
				WN == 0 ? sets.sun :
				WN == 1 ? sets.mon :
				WN == 2 ? sets.tue :
				WN == 3 ? sets.wed :
				WN == 4 ? sets.thu :
				WN == 5 ? sets.fri :
				WN == 6 ? sets.sat :
					'?',
			'HO': ('0' + date.getHours()).slice(-2),
			'MI': ('0' + date.getMinutes()).slice(-2),
			'SE': ('0' + date.getSeconds()).slice(-2)
		};
	}
	
	let ret = sets.fmts;
	for (let d in datetime) {
		ret = ret.replace(d, datetime[d]);
	}
	return ret;
}

function BBReturn() {
	let elms = document.querySelectorAll(
		SEL_BR_ID + ', ' + SEL_BR_H + ', ' + SEL_BR_M + ', ' + SEL_BR_V + ', ' + SEL_BR_L + ', ' + SEL_BR_T
	);
	let sm; // Temp.
	
	for (let e of elms) {
		if (e.getAttribute('d').startsWith(DATA_BR_X)) {
			if (e.closest('header[role="banner"] nav, div[data-testid="Dropdown"] a[href="/i/premium_sign_up"]')) {
				sm = muts;
				
				e.setAttribute('d', DATA_BR_BB);
				e.setAttribute('fill', DATA_BR_FILL_N);
				e.setAttribute('stroke', DATA_BR_S);
				e.setAttribute('stroke-width', DATA_BR_SW);
				
				muts = sm;
			} else if (e.closest('div#placeholder[aria-label="Loading…"]') ||
				e.closest('svg[id^="loading-x-anim-"]')
			) {
				sm = muts;
				
				e.setAttribute('d', DATA_BR_BB);
				e.setAttribute('fill', DATA_BR_FILL_LB);
				
				muts = sm;
			} else {
				sm = muts;
				
				e.setAttribute('d', DATA_BR_BB);
				e.setAttribute('fill', DATA_BR_FILL_DB);
				
				muts = sm;
			}
		}
	}
	
	const TITLE = document.title;
	
	let elm = document.querySelector('head link[rel="shortcut icon"]');
	let elm_2 = document.querySelector('head link[rel="apple-touch-icon"]');
	let elm_3 = document.querySelector('main div[data-testid="primaryColumn"] section>h1');
	
	sm = muts;
	
	if (
		elm &&
		!/favicons\/twitter\.2\.ico$/.test(elm.getAttribute('href')) &&
		!/^\([0-9]+\) /.test(document.title)
	) {
		elm.setAttribute('href', '//abs.twimg.com/favicons/twitter.2.ico');
	} else if (
		elm &&
		!/favicons\/twitter-pip\.2\.ico$/.test(elm.getAttribute('href')) &&
		/^\([0-9]+\) /.test(document.title)
	) {
		elm.setAttribute('href', '//abs.twimg.com/favicons/twitter-pip.2.ico');
	}
	if (
		elm_2 &&
		/responsive-web\/client-web[-a-z]*\/icon-ios\.77d25eba\.png$/.test(elm_2.getAttribute('href'))
	) {
		elm_2.setAttribute('href', 'data:image/png;base64,' + PNG_BB);
	}
	let rt = TITLE.replace(/ \/ X$/, ' / Twitter');
	if (elm_3 && elm_3.textContent == REPETIT_L[0]) rt = rt.replace(REPETIT_L[1], REPETIT_L[2]);
	if (TITLE != rt) document.title = rt;
	
	muts = sm;
}

function origImg() {
	let elms = document.querySelectorAll(SEL_OI_D + ', ' + SEL_OI_I);
	
	for (let e of elms) {
		let sm; // Temp.
		
		if (/div/i.test(e.tagName)) {
			let r = REGEX_OI.exec(e.style.backgroundImage);
			if (r && r[4] != 'orig') {
				sm = muts;
				e.style.backgroundImage = r[1] + r[2] + r[3] + 'orig' + r[5];
				muts = sm;
				continue;
			}
			
			continue;
		}
		
		let r = REGEX_OI.exec(e.getAttribute('src'));
		if (r && r[4] != 'orig') {
			sm = muts;
			e.setAttribute('src', r[1] + r[2] + r[3] + 'orig' + r[5]);
			muts = sm;
			continue;
		}
	}
}

function wideTL() {
	let elms = document.querySelectorAll('div.css-175oi2r.r-aqfbo4[data-testid="sidebarColumn"]');
	let sm; // Temp.
	
	if (!document.querySelector('head style.' + 'us-' + MYNAME + '-' + 'c')) {
		let style_a = document.createElement('style');
		style_a.className = 'us-' + MYNAME + '-' + 'a';
		style_a.textContent =
			'div.css-175oi2r.r-f8sm7e.r-13qz1uu.r-1ye8kvj' +
			'{max-width: 660px;}';
		
		let style_b = document.createElement('style');
		style_b.className = 'us-' + MYNAME + '-' + 'b';
		style_b.textContent =
			'div[role="dialog"] div.css-175oi2r.r-f8sm7e.r-13qz1uu.r-1ye8kvj' +
			'{max-width: 600px;}';
		
		let style_c = document.createElement('style');
		style_c.className = 'us-' + MYNAME + '-' + 'c';
		style_c.textContent =
			'section div.css-175oi2r.r-f8sm7e.r-13qz1uu.r-1ye8kvj' +
			'{max-width: 600px;}';
		
		sm = muts;
		
		document.head.appendChild(style_a);
		document.head.appendChild(style_b);
		document.head.appendChild(style_c);
		
		muts = sm;
	}
	
	for (let e of elms) {
		let d, dd, dg, dgi, spdgi, da, ds;
		
		d = e.querySelector(':scope>div>div.r-1hycxz', ':scope>div>div.r-1jocfgc');
		if (d != null) {
			dd = d.querySelector('div.r-aqfbo4.r-6gpygo.r-15ysp7h'); // null対策
			dg = d.querySelector('div[data-testid="google_sign_in_container"]');
			dgi = d.querySelector('div[data-testid="google_sign_in_container"] iframe[id^="gsi"]');
			da = d.querySelector('button[data-testid="apple_sign_in_button"]');
			ds = d.querySelector('a[href="/i/flow/signup"]');
		}
		if (dgi) spdgi = dgi.parentNode.parentNode;
		
		sm = muts;
		
		if (dd) dd.style.width = '290px';
		if (dg) dg.style.width = '260px';
		if (dgi) dgi.style.left = '-20px';
		if (spdgi) spdgi.style.setProperty('clip-path', 'inset(0 round 20px)');
		if (da) da.style.width = '260px';
		if (ds) ds.style.width = '260px';
		if (d != null) d.style.width = '290px';
		e.style.width = '290px'; // 350px
		
		muts = sm;
	}
}

function chngBGC() {
	let body = document.getElementsByTagName('body')[0];
	
	if (/\(2[0-9]{2},\s*2[0-9]{2},\s*2[0-9]{2}/i.test(body.style.backgroundColor)) {
		let tl, fb, sb;
		tl = document.querySelector('main div.r-f8sm7e.r-1ye8kvj');
		fb = document.querySelector('main div.r-1e5uvyk.r-6026j');
		sb = document.querySelector('main div.r-aqfbo4.r-15ysp7h.r-1xcajam');
		
		let sm = muts;
		
		body.style.backgroundColor = 'rgb(253, 253, 245)';
		if (tl != null) tl.style.backgroundColor = 'rgb(253, 253, 245)';
		if (fb != null) fb.style.backgroundColor = 'rgba(253, 253, 245, 0.85)';
		if (sb != null) sb.style.backgroundColor = 'rgb(253, 253, 245)';
		
		muts = sm;
	}
}

function hidePromo() {
	let elms = document.querySelectorAll(SEL_HP);
	let elms_2 = document.querySelectorAll(SEL_HP_2);
	let elms_3 = document.querySelectorAll(SEL_HP_3);
	let elms_4 = document.querySelectorAll(SEL_HP_4);
	
	let sm; // Temp.
	
	for (let e of elms) {
		let xpe = e.closest('div[data-testid="cellInnerDiv"]');
		if (!xpe) xpe = e.closest('div.css-175oi2r.r-1adg3ll.r-1ny4l3l'); // def-ja, def-en, ble-ja, ble-en
		if (!xpe) xpe = e.closest('div.css-175oi2r.r-1ny4l3l[data-testid="UserCell"]'); // def-ja, def-en, ?, ble-en
		
		sm = muts;
		
		if (xpe) xpe.style.setProperty('display', 'none'); // Right column のおすすめユーザー'
		
		muts = sm;
	}
	
	for (let e of elms_2) {
		if (!REGEX_HP.test(e.textContent)) continue;
		
		let xpe = e.closest('div.css-175oi2r.r-1adg3ll.r-1ny4l3l');
		
		sm = muts;
		
		xpe.style.setProperty('display', 'none');
		
		muts = sm;
	}
	
	for (let e of elms_3) {
		if (e.textContent != 'Ad') continue;
		
		let xpe = e.closest('div[data-testid="cellInnerDiv"]');
		
		sm = muts;
		
		xpe.style.setProperty('display', 'none');
		
		muts = sm;
	}
	
	for (let e of elms_4) {
		if (e.textContent != PROMO_2['en'] && e.textContent != PROMO_L_2) continue;
		
		let xpe = e.closest('div[data-testid="cellInnerDiv"]');
		
		sm = muts;
		
		xpe.style.setProperty('display', 'none');
		
		muts = sm;
	}
}

function hideWF() {
	let sm; // Temp.
	
	if (REGEX_HW.test(document.URL)) {
		for (let i = 1; i < 4; i++) {
			let elm = document.querySelector('head style.' + 'us-' + MYNAME + '-' + i);
			if (elm) document.head.removeChild(elm);
		}
		
		return;
	}
	
	if (!document.querySelector('head style.' + 'us-' + MYNAME + '-' + 1)) {
		sm = muts;
		
		let style = document.createElement('style');
		style.className = 'us-' + MYNAME + '-' + 1;
		style.textContent =
			'main div[data-testid="primaryColumn"] section div[data-testid="cellInnerDiv"]' +
			':has(button.css-175oi2r.r-1mmae3n.r-3pj75a.r-1ny4l3l.r-o7ynqc.r-6416eg[data-testid="UserCell"]) ' +
			'{display: none;}';
		// フォロー, def-ja, def-en, ble-ja, ble-en
		document.head.appendChild(style);
		
		muts = sm;
	}
	
	if (!document.querySelector('head style.' + 'us-' + MYNAME + '-' + 2)) {
		sm = muts;
		
		let style = document.createElement('style');
		style.className = 'us-' + MYNAME + '-' + 2;
		style.textContent =
			'main div[data-testid="primaryColumn"] section div[data-testid="cellInnerDiv"]' +
			':has(h2[aria-level="2"][role="heading"]>div>span.css-1jxf684.r-bcqeeo.r-qvutc0) {display: none;}';
		// Who to follow, def-ja, def-en, ble-ja, ble-en
		document.head.appendChild(style);
		
		muts = sm;
	}
	
	if (!document.querySelector('head style.' + 'us-' + MYNAME + '-' + 3)) {
		sm = muts;
		
		let style = document.createElement('style');
		style.className = 'us-' + MYNAME + '-' + 3;
		style.textContent =
			'main div[data-testid="primaryColumn"] section div[data-testid="cellInnerDiv"]' +
			':has(a[href*="/connect_people?user_id="]) {display: none;}'; // さらに表示
		document.head.appendChild(style);
		
		muts = sm;
	}
}

function hideDMD() {
	let elm = document.querySelector(SEL_HD);
	let sm = muts;
	
	if (elm != null) elm.style.setProperty('display', 'none');
	
	muts = sm;
}

function hideGV() {
	let elms = document.querySelectorAll(SEL_HG);
	let elms_2 = document.querySelectorAll(SEL_HG_2);
	
	for (let e of elms) {
		if (
			e.getAttribute('aria-label') == GV_L ||
			e.getAttribute('aria-label') == SP_L ||
			e.getAttribute('aria-label') == SPYLP_L ||
			e.getAttribute('aria-label') == GAFP_L
		) {
			let sm = muts;
			
			e.parentNode.parentNode.style.setProperty('display', 'none');
			
			muts = sm;
		}
	}
	
	for (let e of elms_2) {
		if (e.textContent == GAFP_L || e.textContent == GAF_L || e.textContent == TXP_L) {
			let xpe = e.closest('div[data-testid="cellInnerDiv"]');
			
			let sm = muts;
			
			xpe.style.setProperty('display', 'none');
			
			muts = sm;
		}
	}
}

function fineEgm() {
	document.
		querySelectorAll(SEL_FE_R + ', ' + SEL_FE_T + ', ' + SEL_FE_L + ', ' + SEL_FE_B).
		forEach(function (e) {
			let ce = e.querySelector('span:not(.us-' + MYNAME + ')');
			let xpe = e.closest('button');
			let n = +xpe.getAttribute('aria-label').split(' ')[0];
			let ls = '';
			if (n) ls = n.toLocaleString('en-US');
			
			let old = e.querySelector(SEL_ADD_SPAN);
			
			let sm = muts;
			
			if (ce && ce.style.display != 'none') { // 0の時も無い
				ce.style.setProperty('display', 'none');
			}
			if (!old) {
				let span = document.createElement('span');
				span.className = 'us-' + MYNAME;
				span.textContent = ls;
				if (ce) span.style = ce.style;
				
				e.appendChild(span);
			} else if (old.textContent != ls) {
				old.textContent = ls;
				if (ce) old.style = ce.style;
			}
			
			muts = sm;
		});
}

function fineEgmViewDetl() {
	let elm = document.querySelector(SEL_FEVD);
	if (!elm) return;
	
	let elm_2 = document.querySelector(SEL_FEVD_2);
	if (!elm_2) return;
	
	let pelm = elm.parentNode;
	let xpelm_2 = elm_2.closest('div.r-1kbdv8c[aria-label][role="group"]'); // fineegm()のさらに上
	let n = +/([0-9]+)[^0-9]+$/.exec(xpelm_2.getAttribute('aria-label'))[1];
	let ls = n.toLocaleString('en-US');
	
	let old = pelm.querySelector(SEL_ADD_SPAN);
	
	let sm = muts;
	
	if (!old) {
		let span = document.createElement('span');
		span.className = 'us-' + MYNAME;
		span.textContent = ls;
		span.style = elm.style;
		
		elm.style.setProperty('display', 'none');
		pelm.appendChild(span);
	} else if (old.textContent != ls) {
		old.textContent = ls;
		old.style = elm.style;
	}
	
	muts = sm;
}

function fineEgmViewTL() {
	document.querySelectorAll(SEL_FEVT).forEach(function (e) {
		let pe = e.parentNode;
		let xpe = e.closest('a');
		let n = +xpe.getAttribute('aria-label').split(' ')[0];
		let ls = n.toLocaleString('en-US');
		
		let old = pe.querySelector(SEL_ADD_SPAN);
		
		let sm = muts;
		
		if (!old) {
			let span = document.createElement('span');
			span.className = 'us-' + MYNAME;
			span.textContent = ls;
			span.style = e.style;
			
			e.style.setProperty('display', 'none');
			pe.appendChild(span);
		} else if (old.textContent != ls) {
			old.textContent = ls;
			old.style = e.style;
		}
		
		muts = sm;
	});
}

function fineEgmPost() {
	let elm = document.querySelector(SEL_FEP);
	if (!elm || elm.querySelector('span')) return;
	
	let elm_2 = document.querySelector(SEL_FEP_2);
	if (!elm_2) return;
	
	let pelm = elm.parentNode;
	let n = JSON.parse(elm_2.textContent).author.interactionStatistic[2].userInteractionCount;
	let ls = n.toLocaleString('en-US');
	
	let old = pelm.querySelector(SEL_ADD_DIV);
	
	let sm = muts;
	
	if (!old) {
		let div = document.createElement('div');
		div.className = 'us-' + MYNAME;
		div.textContent = ls + ' ' + elm.textContent.split(' ')[1];
		div.style = elm.style;
		
		elm.style.setProperty('display', 'none');
		pelm.appendChild(div);
	} else if (old.textContent.split(' ')[0] != ls) {
		old.textContent = ls + ' ' + elm.textContent.split(' ')[1];
		old.style = elm.style;
	}
	
	muts = sm;
}

function isHLSURL(url) {
	return (
		/^https?:\/\/video\.twimg\.com\/[^?]+\.m3u8?/i.test(url) ||
		/^https?:\/\/[^.]+\.video\.pscp\.tv\/[^?]+\.m3u8?/i.test(url)
	);
}

function isHLSMaster(text) {
	return (
		text &&
		text.includes('#EXT-X-STREAM-INF') &&
		!text.includes('#EXT-X-TARGETDURATION')
	);
}

function pickOne(reg, text) {
	let matches = [];
	const HEAD = text.replace(reg, function (m, p1) {
		matches.push([m, p1]);
		return '';
	});
	const L = matches.length;
	if (L < 2) return text;
	
	let select = matches[0];
	for (let i = 1; i < L; i++) { // 2番目から
		select =
			(sets.fix_vq != 2 && +select[1] < +matches[i][1]) ||
			(sets.fix_vq == 2 && +select[1] > +matches[i][1]) ? matches[i] :
				select;
	}
	
	return (HEAD + '\n' + select[0]).trim().replace(/(\r?\n)+/g, '\n') + '\n';
}

function twtXHRStateHandler({ target: xhr }) {
	if (xhr.readyState === 4) {
		const RAW_TEXT = xhr.responseText;
		if (isHLSMaster(RAW_TEXT)) {
			const REG = /#EXT-X-STREAM-INF.*[^-]BANDWIDTH=(\d+).*\r?\n\/.+$/gm;
			const MOD_TEXT = pickOne(REGEX_TXSH, RAW_TEXT);
			Object.defineProperties(xhr, {
				response: { writable: true },
				responseText: { writable: true },
			});
			xhr.response = xhr.responseText = MOD_TEXT;
		}
	}
}

function overrideXHROpen() {
	orig_xhr_open = XMLHttpRequest.prototype.open;
	XMLHttpRequest.prototype.open = function () {
		if (isHLSURL(arguments[1])) {
			this.addEventListener('readystatechange', twtXHRStateHandler);
		}
		return orig_xhr_open.apply(this, arguments);
	};
	
	console.log(MYNAME + ': XMLHttpRequest.open overriden.');
}

function replDatetime() {
	document.
		querySelectorAll(SEL_RD + ', ' + SEL_RD_2 + ', ' + SEL_RD_3 + ', ' + SEL_RD_4 + ', ' + SEL_RD_5).
		forEach(function (e) {
			let d = e.getAttribute('datetime');
			let df = fmtDate(sets.fmt, new Date(d));
			
			let pe = e.parentNode;
			
			let old = pe.querySelectorAll(SEL_ADD_SPAN);
			
			let sm = muts;
			
			if (!old.length) {
				let span = document.createElement('span');
				span.className = 'us-' + MYNAME;
				span.setAttribute('datetime', d);
				span.setAttribute('local-datetime', df);
				span.textContent = df;
				span.style = e.style;
				
				e.style.setProperty('display', 'none');
				pe.appendChild(span);
			} else if (old[0].getAttribute('local-datetime') != df) { // TZ change
				old[0].setAttribute('local-datetime', df);
				old[0].textContent = df;
				old[0].style = e.style;
			}
			
			muts = sm;
		});
}

function loop() {
	setTimeout(() => {
		if (muts) {
			muts = null; // 初期値がtrue、変更もしない
			
			if (sets.fmt) replDatetime();
			if (sets.bbr) BBReturn();
			if (sets.orig_img) origImg();
			if (sets.wtl) wideTL();
			if (sets.ec_mode) chngBGC();
			if (sets.hide_pp) hidePromo();
			if (sets.hide_wf) hideWF();
			if (sets.hide_dmd) hideDMD();
			if (sets.hide_gv) hideGV();
			if (sets.fine_egm) {
				fineEgm();
				fineEgmViewDetl();
				fineEgmViewTL();
				fineEgmPost();
				time_fine_egm = Date.now();
			}
		} else if (sets.fine_egm == 1 && Date.now() - time_fine_egm > 4000) {
			fineEgm();
			fineEgmViewDetl();
			fineEgmViewTL();
			fineEgmPost();
			time_fine_egm = Date.now();
		}
		loop();
	}, sets.intl);
}

sets.fmt = FMT;
sets.fmts = FMTS;
sets.sun = SUN;
sets.mon = MON;
sets.tue = TUE;
sets.wed = WED;
sets.thu = THU;
sets.fri = FRI;
sets.sat = SAT;
sets.bbr = BBR;
sets.orig_img = ORIG_IMG;
sets.wtl = WTL;
sets.ec_mode = EC_MODE;
sets.hide_pp = HIDE_PP;
sets.hide_wf = HIDE_WF;
sets.hide_dmd = HIDE_DMD;
sets.hide_gv = HIDE_GV;
sets.fine_egm = FINE_EGM;
sets.fix_vq = FIX_VQ;
sets.intl = INTL;

if (!NO_GUI) initGUI();
if (sets.fix_vq) overrideXHROpen();
observer.observe(document, { childList: true, subtree: true });
loop();


})(); /*  END  */