Fix add caption
All checks were successful
Push image to registry / build-image (push) Successful in 8m4s
All checks were successful
Push image to registry / build-image (push) Successful in 8m4s
This commit is contained in:
@ -287,8 +287,29 @@ abstract class BrowserJob implements ShouldQueue
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function typeText(Browser $browser, string $text, string $querySelector): void
|
/**
|
||||||
|
* Parse a string for use in JavaScript.
|
||||||
|
*
|
||||||
|
* @param string $string The string to parse.
|
||||||
|
* @return string The parsed string.
|
||||||
|
*/
|
||||||
|
private function parseJavaScriptString(string $string): string
|
||||||
{
|
{
|
||||||
|
return str_replace("'", "\\'", $string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type text into an input field using JavaScript.
|
||||||
|
*
|
||||||
|
* @param Browser $browser
|
||||||
|
* @param string $text The text to type.
|
||||||
|
* @param string $querySelector The CSS selector for the input field.
|
||||||
|
*/
|
||||||
|
public function setInputValue(Browser $browser, string $text, string $querySelector): void
|
||||||
|
{
|
||||||
|
$text = $this->parseJavaScriptString($text);
|
||||||
|
$querySelector = $this->parseJavaScriptString($querySelector);
|
||||||
|
|
||||||
$browser->script("
|
$browser->script("
|
||||||
let element = document.querySelector('{$querySelector}');
|
let element = document.querySelector('{$querySelector}');
|
||||||
if (element) {
|
if (element) {
|
||||||
@ -300,4 +321,31 @@ abstract class BrowserJob implements ShouldQueue
|
|||||||
}
|
}
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paste text into an element using JavaScript.
|
||||||
|
* Can be useful for non input elements that need to get text. For example works
|
||||||
|
* with `contenteditable` elements.
|
||||||
|
*
|
||||||
|
* @param Browser $browser
|
||||||
|
* @param string $text The text to paste.
|
||||||
|
* @param string $querySelector The CSS selector for the input field.
|
||||||
|
*/
|
||||||
|
public function pasteText(Browser $browser, string $text, string $querySelector): void
|
||||||
|
{
|
||||||
|
$text = $this->parseJavaScriptString($text);
|
||||||
|
$querySelector = $this->parseJavaScriptString($querySelector);
|
||||||
|
|
||||||
|
$browser->script("
|
||||||
|
var el = document.querySelector('{$querySelector}'), text = \"{$text}\";
|
||||||
|
el.focus();
|
||||||
|
const dataTransfer = new DataTransfer();
|
||||||
|
dataTransfer.setData('text', text);
|
||||||
|
const event = new ClipboardEvent('paste', {
|
||||||
|
clipboardData: dataTransfer,
|
||||||
|
bubbles: true
|
||||||
|
});
|
||||||
|
el.dispatchEvent(event)
|
||||||
|
");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,21 +332,7 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
|||||||
|
|
||||||
// Add a caption
|
// Add a caption
|
||||||
$captionText = $this->descriptionPipeline->process($videoInfo->getDescription());
|
$captionText = $this->descriptionPipeline->process($videoInfo->getDescription());
|
||||||
$captionText = str_replace('"', '\"', $captionText);
|
$this->pasteText($browser, $captionText, 'div[contenteditable]');
|
||||||
$browser->keys('div[contenteditable]', $captionText); // Type the caption in the contenteditable div
|
|
||||||
// $browser->script("
|
|
||||||
// var el = document.querySelector('div[contenteditable]'), text = \"{$captionText}\";
|
|
||||||
// const dataTransfer = new DataTransfer();
|
|
||||||
// dataTransfer.setData('text', text);
|
|
||||||
// const event = new ClipboardEvent('paste', {
|
|
||||||
// clipboardData: dataTransfer,
|
|
||||||
// bubbles: true
|
|
||||||
// });
|
|
||||||
// document.querySelector('div[contenteditable]').dispatchEvent(event)
|
|
||||||
// ");
|
|
||||||
//$this->typeText($browser, $captionText, 'div[contenteditable]');
|
|
||||||
//$captionInput = $browser->driver->findElement(WebDriverBy::xpath('//div[@contenteditable]'));
|
|
||||||
//$captionInput->sendKeys($this->descriptionPipeline->process($videoInfo->getDescription()));
|
|
||||||
|
|
||||||
sleep(2); // Wait for the caption to be added
|
sleep(2); // Wait for the caption to be added
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user