Skip to content

Commit 317ded1

Browse files
committed
feat: fix x buttons
1 parent 52081c4 commit 317ded1

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

apps/extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postiz-extension",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "A simple chrome & firefox extension template with Vite, React, TypeScript and Tailwind CSS.",
55
"scripts": {
66
"build": "rm -rf dist && vite build --config vite.config.chrome.ts && zip -r extension.zip dist",

apps/extension/src/pages/content/elements/action.component.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ export const ActionComponent: FC<{
6161
actionType: string;
6262
provider: ProviderInterface;
6363
wrap: boolean;
64+
selector: string;
6465
}> = memo((props) => {
65-
const { wrap, provider, target, actionType } = props;
66+
const { wrap, provider, selector, target, actionType } = props;
6667
const [modal, showModal] = useState(false);
6768
const handle = useCallback(async (e: any) => {
6869
showModal(true);
@@ -72,7 +73,8 @@ export const ActionComponent: FC<{
7273

7374
useEffect(() => {
7475
const blockingDiv = document.createElement('div');
75-
if (document.querySelector('#blockingDiv')) {
76+
if (document.querySelector(`.${selector}`)) {
77+
console.log('already exists');
7678
return;
7779
}
7880

@@ -87,6 +89,7 @@ export const ActionComponent: FC<{
8789
blockingDiv.style.width = `${targetInformation.width}px`;
8890
blockingDiv.style.height = `${targetInformation.height}px`;
8991
blockingDiv.style.zIndex = '9999';
92+
blockingDiv.className = selector;
9093

9194
document.body.appendChild(blockingDiv);
9295
blockingDiv.addEventListener('click', handle);

apps/extension/src/pages/content/main.content.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,30 @@ export const MainContentInner: FC = (props) => {
157157
actionType={actionEl.actionType}
158158
provider={provider}
159159
wrap={true}
160+
selector={stringToABC(provider.element.split(',').map(z => z.trim()).find(p => actionEl.element.matches(p)) || '')}
160161
/>,
161162
actionEl.element
162163
)}
163164
</Fragment>
164165
));
165166
};
167+
168+
function stringToABC(text: string, length = 8) {
169+
// Simple DJB2-like hash (non-cryptographic!)
170+
let hash = 5381;
171+
for (let i = 0; i < text.length; i++) {
172+
hash = (hash * 33) ^ text.charCodeAt(i);
173+
}
174+
175+
hash = Math.abs(hash);
176+
177+
// Convert to base-26 string using a–z
178+
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
179+
let result = '';
180+
while (result.length < length) {
181+
result = alphabet[hash % 26] + result;
182+
hash = Math.floor(hash / 26);
183+
}
184+
185+
return result;
186+
}

apps/extension/src/providers/list/x.provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ProviderInterface } from '@gitroom/extension/providers/provider.interfa
33
export class XProvider implements ProviderInterface {
44
identifier = 'x';
55
baseUrl = 'https://x.com';
6-
element = `[data-testid="tweetTextarea_0_label"]`;
6+
element = `[data-testid="primaryColumn"]:has([data-testid="toolBar"]) [data-testid="tweetTextarea_0_label"], [data-testid="SideNav_NewTweet_Button"]`;
77
attachTo = `#react-root`;
88
style = "dark" as "dark";
99
findIdentifier = (element: HTMLElement) => {

0 commit comments

Comments
 (0)