Skip to content

Commit

Permalink
feat: taskPasteIntoBio of twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Misaka-0x447f committed Sep 19, 2019
1 parent 1740ab8 commit 4f5d30d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/social-network-provider/twitter.com/ui/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@ const taskPasteIntoPostBox: SocialNetworkUI['taskPasteIntoPostBox'] = async (tex
}

const taskPasteIntoBio = async (text: string) => {
const getValue = () => editProfileTextareaSelector().evaluate()!.value
await untilDocumentReady()
try {
const b = editProfileButtonSelector().evaluate()
await sleep(200)
b!.click()
editProfileButtonSelector()
.evaluate()!
.click()
} catch {
prompt(geti18nString('automation_request_click_edit_bio_button'))
}
await sleep(400)
try {
const i = editProfileTextareaSelector().evaluate()!
await sleep(200)
i.focus()
dispatchCustomEvents('input', i.value + text)
} catch {
console.warn('Text not pasted to the text area')
prompt(geti18nString('automation_request_paste_into_bio_box'), text)
}
throw new Error('Logic not complete for now, remove this before next release')
// TODO: detect if things successfully paste in, by something like, innerText
if (getValue() !== text) {
console.warn('Text pasting failed')
prompt(geti18nString('automation_request_paste_into_bio_box'), text)
}
}

const taskGetPostContent = async () => {
Expand Down
1 change: 1 addition & 0 deletions src/social-network-provider/twitter.com/utils/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const newPostEditorFocusAnchor = () =>

export const newPostEditorHasFocus = () => querySelector(`.public-DraftEditorPlaceholder-hasFocus`)

export const gotoProfileButtonSelector = () => querySelector('[role="navigation"] [aria-label="Profile"]')
export const editProfileButtonSelector = () =>
querySelector<HTMLAnchorElement>('[data-testid="primaryColumn"] [href="/settings/profile"]')
export const editProfileTextareaSelector = () => querySelector<HTMLTextAreaElement>('textarea[placeholder*="bio"]')
Expand Down
2 changes: 1 addition & 1 deletion src/social-network-provider/twitter.com/utils/url.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PersonIdentifier, PostIdentifier } from '../../../database/type'
import { usernameValidator } from './user'
import { geti18nString } from '../../../utils/i18n'
import { host } from '../index'

const host = location.hostname
export const toPostUrl = (post: PostIdentifier<PersonIdentifier>) => {
if (!usernameValidator(post.identifier.userId)) {
throw new Error(geti18nString('service_username_invalid'))
Expand Down

0 comments on commit 4f5d30d

Please sign in to comment.