feat: fix x buttons

This commit is contained in:
Nevo David 2025-05-17 15:57:57 +07:00
parent 52081c46d5
commit 317ded1ddc
4 changed files with 28 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "postiz-extension",
"version": "1.0.2",
"version": "1.0.3",
"description": "A simple chrome & firefox extension template with Vite, React, TypeScript and Tailwind CSS.",
"scripts": {
"build": "rm -rf dist && vite build --config vite.config.chrome.ts && zip -r extension.zip dist",

View File

@ -61,8 +61,9 @@ export const ActionComponent: FC<{
actionType: string;
provider: ProviderInterface;
wrap: boolean;
selector: string;
}> = memo((props) => {
const { wrap, provider, target, actionType } = props;
const { wrap, provider, selector, target, actionType } = props;
const [modal, showModal] = useState(false);
const handle = useCallback(async (e: any) => {
showModal(true);
@ -72,7 +73,8 @@ export const ActionComponent: FC<{
useEffect(() => {
const blockingDiv = document.createElement('div');
if (document.querySelector('#blockingDiv')) {
if (document.querySelector(`.${selector}`)) {
console.log('already exists');
return;
}
@ -87,6 +89,7 @@ export const ActionComponent: FC<{
blockingDiv.style.width = `${targetInformation.width}px`;
blockingDiv.style.height = `${targetInformation.height}px`;
blockingDiv.style.zIndex = '9999';
blockingDiv.className = selector;
document.body.appendChild(blockingDiv);
blockingDiv.addEventListener('click', handle);

View File

@ -157,9 +157,30 @@ export const MainContentInner: FC = (props) => {
actionType={actionEl.actionType}
provider={provider}
wrap={true}
selector={stringToABC(provider.element.split(',').map(z => z.trim()).find(p => actionEl.element.matches(p)) || '')}
/>,
actionEl.element
)}
</Fragment>
));
};
function stringToABC(text: string, length = 8) {
// Simple DJB2-like hash (non-cryptographic!)
let hash = 5381;
for (let i = 0; i < text.length; i++) {
hash = (hash * 33) ^ text.charCodeAt(i);
}
hash = Math.abs(hash);
// Convert to base-26 string using az
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
let result = '';
while (result.length < length) {
result = alphabet[hash % 26] + result;
hash = Math.floor(hash / 26);
}
return result;
}

View File

@ -3,7 +3,7 @@ import { ProviderInterface } from '@gitroom/extension/providers/provider.interfa
export class XProvider implements ProviderInterface {
identifier = 'x';
baseUrl = 'https://x.com';
element = `[data-testid="tweetTextarea_0_label"]`;
element = `[data-testid="primaryColumn"]:has([data-testid="toolBar"]) [data-testid="tweetTextarea_0_label"], [data-testid="SideNav_NewTweet_Button"]`;
attachTo = `#react-root`;
style = "dark" as "dark";
findIdentifier = (element: HTMLElement) => {