wayBetter for X 1.0.2
This commit is contained in:
parent
7e2515aa42
commit
467aea2e28
212 changed files with 10208 additions and 2345 deletions
|
|
@ -294,39 +294,6 @@ export function formatFullCount(value: number, locale?: string): string {
|
|||
|
||||
// -- Runtime: DOM patching + observers (installFeatures) --
|
||||
|
||||
const WORDING_MAP: Record<string, string> = { Post: 'Tweet', Posts: 'Tweets', Repost: 'Retweet', Reposts: 'Retweets' };
|
||||
|
||||
const WORDING_REVERSE: Record<string, string> = Object.fromEntries(Object.entries(WORDING_MAP).map(([x, twitter]) => [twitter, x]));
|
||||
const RETEXT_ATTR = 'data-bt-retext';
|
||||
const TEXT_NODE = 3;
|
||||
|
||||
/** Retexts X's own label text nodes in place. Editing the node (not `span.textContent`, which
|
||||
* swaps in a new node) keeps React owning it, so X's later updates (e.g. the label emptied when the
|
||||
* nav collapses to icon-only) still land instead of leaving a stale "Tweet" behind. */
|
||||
function retextExact(el: Element | null | undefined) {
|
||||
if (!el) return;
|
||||
for (const span of el.querySelectorAll('span')) {
|
||||
for (const node of Array.from(span.childNodes)) {
|
||||
const text = node.nodeType === TEXT_NODE ? node.nodeValue : null;
|
||||
if (text == null || !Object.hasOwn(WORDING_MAP, text)) continue;
|
||||
node.nodeValue = WORDING_MAP[text]!;
|
||||
span.setAttribute(RETEXT_ATTR, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Puts X's own wording back on labels `retextExact` changed. */
|
||||
function restoreText(root: ParentNode | null | undefined) {
|
||||
if (!root) return;
|
||||
for (const span of root.querySelectorAll(`[${RETEXT_ATTR}]`)) {
|
||||
for (const node of Array.from(span.childNodes)) {
|
||||
const text = node.nodeType === TEXT_NODE ? node.nodeValue : null;
|
||||
if (text != null && Object.hasOwn(WORDING_REVERSE, text)) node.nodeValue = WORDING_REVERSE[text]!;
|
||||
}
|
||||
span.removeAttribute(RETEXT_ATTR);
|
||||
}
|
||||
}
|
||||
|
||||
function buildFaviconDataUrl(brush: boolean): string {
|
||||
if (brush) return LOGO_PNG;
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="${THEME_BLUE}" d="${TWITTER_LOGO_PATH}"/></svg>`;
|
||||
|
|
@ -410,19 +377,6 @@ export function installFeatures(target: Window = window): FeatureHandle {
|
|||
} catch { /* degrade silently */ }
|
||||
};
|
||||
|
||||
const patchWording = () => {
|
||||
try {
|
||||
retextExact(doc.querySelector('button[data-testid^="tweetButton"]'));
|
||||
// Compact nav: X renders an icon-only round button (svg + empty label). Leave it as X drew it.
|
||||
const sideNav = doc.querySelector('[data-testid="SideNav_NewTweet_Button"]');
|
||||
if (sideNav?.querySelector('svg')) restoreText(sideNav);
|
||||
else retextExact(sideNav);
|
||||
for (const item of doc.querySelectorAll('[data-testid="retweetConfirm"], [data-testid="repostConfirm"], [data-testid="unretweetConfirm"], [data-testid="unrepostConfirm"]')) {
|
||||
retextExact(item);
|
||||
}
|
||||
} catch { /* degrade silently */ }
|
||||
};
|
||||
|
||||
const patchTitle = () => {
|
||||
if (!config.twitterWording) return;
|
||||
try {
|
||||
|
|
@ -448,10 +402,8 @@ export function installFeatures(target: Window = window): FeatureHandle {
|
|||
syncRoute();
|
||||
patchLogo();
|
||||
if (faviconDirty) { faviconDirty = false; patchFavicon(); }
|
||||
if (config.twitterWording) patchWording();
|
||||
else restoreText(doc);
|
||||
};
|
||||
// Shared body observer + frame (domHub.ts). Route, logo and wording also apply on chat pages.
|
||||
// Shared body observer + frame (domHub.ts). Route and logo also apply on chat pages (the wording is a string pack now; the title suffix stays here).
|
||||
const watch = watchDom(win, runPatches);
|
||||
const schedule = watch.schedule;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue