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

Notification

Icon
Error

Options
Go to last post Go to first unread
Holyman  
#1 Posted : Monday, November 11, 2019 2:10:33 PM(UTC)
Holyman

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/11/2019(UTC)
Posts: 2
Russian Federation
Location: St. Petersbourg

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
Dear Rob,
I need your help to write script, which opens links in new browser's tab.
I think it will become relevant for many people.
I am not a programmer, an approximate algorithm is given under the spoiler.
With Great respect, John Cool




Thank YOU!
thanks 1 user thanked Holyman for this useful post.
lyscop on 4/23/2020(UTC)
Rob  
#2 Posted : Monday, November 11, 2019 3:01:16 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 684
United States
Location: Tampa, FL

Thanks: 13 times
Was thanked: 155 time(s) in 134 post(s)
Hi and welcome!

So this would be an almost literal conversion (I added 2 sleep calls to prevent things from being executed too fast):
Code:
var open_link_in_background = false;

action.Window.Activate();
sp.ConsumePhysicalInput(true);

var clicked = false;
var i = action.Start.Y; //action.Start is a Point, with .X and .Y properties
var i_end = i + 6;

while(i < i_end) {
    sp.MouseMove(new Point(action.Start.X, i));
    sp.Sleep(20);
    if(sp.GetCurrentMouseCursor() == "Hand") {
        if(!clicked) {  //You could also use - if(clicked == false) - "!" is the same "not"
            if(open_link_in_background) {
                sp.MouseClick(new Point(action.Start.X, i), MouseButtons.Middle, true, true); 
            } else {
                sp.SendControlDown();
                sp.Sleep(20);
                sp.MouseClick(new Point(action.Start.X, i), MouseButtons.Left, true, true); 
                sp.SendControlUp();
            }
            clicked = true;
        }
    }
    i = i + 2;
}

sp.ConsumePhysicalInput(false);
sp.MouseMove(action.End); //action.End is also a Point


This would be the same, just refactored to reduce unnecessary code lines, allow three loop passes which seems to be the intent ("<= 6" - less than or equal to 6), and change the "i" to "Y" so it's more clear what the variable is for:
Code:
var open_link_in_background = false;

sp.ConsumePhysicalInput(true);

for(var Y = action.Start.Y; Y <= action.Start.Y + 6; Y += 2) {
    sp.MouseMove(new Point(action.Start.X, Y));
    sp.Sleep(20);
    if(sp.GetCurrentMouseCursor() == "Hand") {
        if(open_link_in_background) {
            sp.MouseClick(new Point(action.Start.X, Y), MouseButtons.Middle, true, true); 
        } else {
            sp.SendControlDown();
            sp.Sleep(20);
            sp.MouseClick(new Point(action.Start.X, Y), MouseButtons.Left, true, true); 
            sp.SendControlUp();
        }
        break; //Stop looping
    }
}

sp.ConsumePhysicalInput(false);
sp.MouseMove(action.End); 
thanks 1 user thanked Rob for this useful post.
Holyman on 11/11/2019(UTC)
Rob  
#3 Posted : Monday, November 11, 2019 4:45:19 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 684
United States
Location: Tampa, FL

Thanks: 13 times
Was thanked: 155 time(s) in 134 post(s)
Oops! I forgot your Ctrl+T part of the script, also added some extra delay after the control down call, again to allow time for the key event to be recognized (on my PC, anyway)

Code:
var open_link_in_background = false;
var clicked = false;

sp.ConsumePhysicalInput(true);

for(var Y = action.Start.Y; Y <= action.Start.Y + 6; Y += 2) {
    sp.MouseMove(new Point(action.Start.X, Y));
    sp.Sleep(20);
    if(sp.GetCurrentMouseCursor() == "Hand") {
        if(open_link_in_background) {
            sp.MouseClick(new Point(action.Start.X, Y), MouseButtons.Middle, true, true); 
        } else {
            sp.SendControlDown();
            sp.Sleep(100);
            sp.MouseClick(new Point(action.Start.X, Y), MouseButtons.Left, true, true); 
            sp.SendControlUp();
        }
        clicked = true;
        break; //Stop looping
    }
}

if(!clicked) {
    sp.SendKeys("^t");  // Send CTRL+T keystroke
}

sp.ConsumePhysicalInput(false);
sp.MouseMove(action.End); 
thanks 1 user thanked Rob for this useful post.
Holyman on 11/11/2019(UTC)
Holyman  
#4 Posted : Monday, November 11, 2019 5:45:09 PM(UTC)
Holyman

Rank: Newbie

Reputation:

Groups: Approved
Joined: 11/11/2019(UTC)
Posts: 2
Russian Federation
Location: St. Petersbourg

Thanks: 3 times
Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: Rob Go to Quoted Post
Oops!I forgot your Ctrl T part of the script

Yes! I also noticed this, I’m breaking my brain for an hour where to insert this Ctrl+I! I appreciate your time and don't want to bother you for such trifles, and i was very happy when you wrote the answer!
Because i transferred all the gestures from the old version of your wonderful program, this is the only gesture that i can' be transfer! Now it works PERFECTLY!!!
Love Thank you so much, dear Rob! Love

Rob  
#5 Posted : Monday, November 11, 2019 6:37:23 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 684
United States
Location: Tampa, FL

Thanks: 13 times
Was thanked: 155 time(s) in 134 post(s)
You're very welcome!
thanks 1 user thanked Rob for this useful post.
Holyman on 11/12/2019(UTC)
lyscop  
#6 Posted : Thursday, April 23, 2020 7:16:21 PM(UTC)
lyscop

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 4/23/2020(UTC)
Posts: 39
China

Thanks: 5 times
Was thanked: 1 time(s) in 1 post(s)
Aha, Thank you, Rob, this is my simple action, and it will show the right key menu, now I will have a try to you code.

sp.MouseClick(action.Start, MouseButtons.Right, true, true);
sp.Sleep(100) ;
sp.SendKeys("t");
lyscop  
#7 Posted : Monday, April 27, 2020 11:53:55 PM(UTC)
lyscop

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 4/23/2020(UTC)
Posts: 39
China

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

It works well whether the mouse in on a link, the link or a new tab will open in background, but the mouse will move a bit when it is not on a link, can this be modified?
lyscop  
#8 Posted : Friday, May 15, 2020 1:14:36 AM(UTC)
lyscop

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 4/23/2020(UTC)
Posts: 39
China

Thanks: 5 times
Was thanked: 1 time(s) in 1 post(s)
Another suggestion:

It works perfectly when use a gesture to open a link in background.

And when I am not want to open the link, just want to open a new tab, it will jump to the end of the tab bar, how to open a new tab like open the link next to the current tab?
lyscop  
#9 Posted : Friday, May 15, 2020 10:47:35 AM(UTC)
lyscop

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 4/23/2020(UTC)
Posts: 39
China

Thanks: 5 times
Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: lyscop Go to Quoted Post
Another suggestion:

It works perfectly when using a gesture to open a link in background.

And when I am not want to open the link, just want to open a new tab, it will jump to the end of the tab bar, how to open a new tab like open the link next to the current tab?


It is done.

I find a Chrome extension named Open New Tab HereOpen New Tab Here.

It will open a new tab next to the current tab, and it can be set as a shortcut, then replace the ctrl+t of the Open Link in New Tab script.
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.