StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
zyxi  
#1 Posted : Friday, May 31, 2019 8:43:36 PM(UTC)
zyxi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 3/30/2019(UTC)
Posts: 49
China

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)
Hello everyone,

Who can tell me how to replace all “Enter and Space” with a single “Space” when pasting

I try to use "text=text.replaceAll(" +"," ")" but it's wrong.

Sorry to disturb you.
Rob  
#2 Posted : Saturday, June 1, 2019 12:30:35 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 534
United States

Thanks: 5 times
Was thanked: 112 time(s) in 99 post(s)
There is no replaceAll function in JavaScript that I can find. Java and jQuery have that function, but not a pure JavaScript string.

Try this, note that I added some delays between the clipboard commands...they may not be needed, but I've found it is usually a good idea when working with the clipboard in quick succession.

Code:
//Get text from clipboard, replace all "Enter (carriage return and line feed) and Space" 
//with just a space. Then put back on the clipboard and send Ctrl+V
var text = clip.GetText();
text=text.replace(/\r\n /g," ");
sp.Sleep(100);
clip.SetText(text);
sp.Sleep(25);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_V]);


See here for more info on JavaScript replace(): https://www.w3schools.com/jsref/jsref_replace.asp
zyxi  
#3 Posted : Saturday, June 1, 2019 3:05:11 AM(UTC)
zyxi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 3/30/2019(UTC)
Posts: 49
China

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)


Thank you for your reply.
It's a pity that it can't work properly.
Rob  
#4 Posted : Saturday, June 1, 2019 8:56:03 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 534
United States

Thanks: 5 times
Was thanked: 112 time(s) in 99 post(s)
What do you mean?

It works fine for me.

Also you might need to tweak the regex pattern "/\r\n /g" as it assumes a carriage return (13) and line feed (10) character, you might be working with text which has a different new line sequence.
zyxi  
#5 Posted : Sunday, June 2, 2019 7:12:55 AM(UTC)
zyxi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 3/30/2019(UTC)
Posts: 49
China

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)

Thank you very much for your answer. It can work according to my intentions by debugging.

By the way, can a screenshot be changed in length when pasted,
and the ratio of length to width remains unchanged? Such as changing the length to 10cm.
If so, how should the code be written?
Rob  
#6 Posted : Sunday, June 2, 2019 8:25:08 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 534
United States

Thanks: 5 times
Was thanked: 112 time(s) in 99 post(s)
You certainly could do that, but I'm not much of an imaging expert.

The code in the Snip Screen Area script has the basic code/objects you would need to get started, but you would need to research how this is done.

You should be able to search google for things like "C# resize image" and be able to translate the script to S+.

The main differences in the code between a C# example and S+/JavaScript aren't too much.



Also, S+ does support plug-ins. While I do need to make some improvements in the reading of plug-ins (primarily I need to make an interface to ignore other files), you can place a .NET class DLL into the Plug-Ins folder and access it from scripts.

For example, I found this image resizer library: https://github.com/omuleanu/imager

I downloaded the project, compiled, placed the Imager.dll file in the StrokesPlus.net\Plug-Ins folder, then reloaded S+.

Then I changed the Snip Screen Area script section, this is where the existing clip.SetImage(memoryImage); line is (this is not the whole script):
Code:
var newWidth = 500;
var maxHeight = 500;
var onlyResizeIfWider = true;
var resizedImage = Imager.Resize(memoryImage, newWidth, maxHeight, onlyResizeIfWider);

//Copy the image to the clipboard
//clip.SetImage(memoryImage);  //COMMENTED out this line, to use the new resized image result from the Plug-In instead
clip.SetImage(resizedImage);


Note that my example script snippet only resizes if the image is wider than the new width I set (500px). I did not write that plug-in code, so you may need to visit the site to see how the calls are made. I see on the main page that it supports resizing, cropping, saving, and putting an image on a canvas (background color/padding around image).

Here's the compiled Omu Drawing DLL: https://www.strokesplus.net/files/Omu.Drawing.dll.zip

NOTE: You might need to right-click the DLL and mark it as safe/trusted/unblocked after extracting it. Sometimes Windows will block a DLL if it does not think it is to be trusted.

Edited by user Sunday, June 2, 2019 8:35:35 AM(UTC)  | Reason: Not specified

zyxi  
#7 Posted : Sunday, June 2, 2019 8:58:22 AM(UTC)
zyxi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 3/30/2019(UTC)
Posts: 49
China

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)

Okay, your suggestion is very good. I'll follow your tips and explore how to finish it.

Thank you again
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.