Jump to content

Recommended Posts

@ keeping only certain tabs open flushing out the rest, worked out from this help and support topic

Note that if chrome is busy processing something like waiting for a page to respond or anything like that there is a good chance the script then hangs

#include <WinAPI.au3>

Global $aProtected[5] = [4, "Gmail", "autoit", "Google Search", "YouTube"]

Local $a = WinList("[CLASS:Chrome_WidgetWin_1]")
If Not IsArray($a) Then Exit

For $i = 1 To UBound($a) - 1
    If $a[$i][0] Then _Process($a[$i][1])
Next

Func _Process($hWnd)
    Local $hC = _WinAPI_GetClassName(_WinAPI_GetWindow($hWnd, $GW_CHILD)), $bClose = True, $x = 1, $tmp
    WinActivate($hWnd)
    ControlSend($hWnd, "", $hC & 1, "^t")
    ControlSend($hWnd, "", $hC & 1, "^t")
    ControlSend($hWnd, "", $hC & 1, "^{TAB}")
    $oBuffer = ObjCreate('Scripting.Dictionary')

    Do
        $bClose = True
        $tmp = WinGetTitle($hWnd, "")

        If $oBuffer.Exists($tmp) Then
            ControlSend($hWnd, "", $hC & 1, "^w")
        Else
            For $i = 1 To $aProtected[0]
                If StringInStr($tmp, $aProtected[$i]) Then
                    $bClose = False
                    ExitLoop
                EndIf
            Next
            If $bClose Then
                ControlSend($hWnd, "", $hC & 1, "^w")
            Else
                $x += 1
            EndIf
            $oBuffer.Item($tmp) = 1
        EndIf
        Sleep(300)
        ControlSend($hWnd, "", $hC & 1, "^+{TAB}")
    Until Not HWnd(ControlGetHandle($hWnd, "", $hC & $x + 1))
EndFunc   ;==>_Process

 

Edited by Deye
Slowed down
Link to post
Share on other sites
  • 2 weeks later...
On 25/12/2017 at 6:07 AM, Deye said:

@ keeping only certain tabs open flushing out the rest, worked out from this help and support topic

Note that if chrome is busy processing something like waiting for a page to respond or anything like that there is a good chance the script then hangs

#include <WinAPI.au3>

Global $aProtected[5] = [4, "Gmail", "autoit", "Google Search", "YouTube"]

Local $a = WinList("[CLASS:Chrome_WidgetWin_1]")
If Not IsArray($a) Then Exit

For $i = 1 To UBound($a) - 1
    If $a[$i][0] Then _Process($a[$i][1])
Next

Func _Process($hWnd)
    Local $hC = _WinAPI_GetClassName(_WinAPI_GetWindow($hWnd, $GW_CHILD)), $bClose = True, $x = 1, $tmp
    WinActivate($hWnd)
    ControlSend($hWnd, "", $hC & 1, "^t")
    ControlSend($hWnd, "", $hC & 1, "^t")
    ControlSend($hWnd, "", $hC & 1, "^{TAB}")
    $oBuffer = ObjCreate('Scripting.Dictionary')

    Do
        $bClose = True
        $tmp = WinGetTitle($hWnd, "")

        If $oBuffer.Exists($tmp) Then
            ControlSend($hWnd, "", $hC & 1, "^w")
        Else
            For $i = 1 To $aProtected[0]
                If StringInStr($tmp, $aProtected[$i]) Then
                    $bClose = False
                    ExitLoop
                EndIf
            Next
            If $bClose Then
                ControlSend($hWnd, "", $hC & 1, "^w")
            Else
                $x += 1
            EndIf
            $oBuffer.Item($tmp) = 1
        EndIf
        Sleep(300)
        ControlSend($hWnd, "", $hC & 1, "^+{TAB}")
    Until Not HWnd(ControlGetHandle($hWnd, "", $hC & $x + 1))
EndFunc   ;==>_Process

 

This is just what i needed, tysm

 

But how i can add an exception to dont close a certain tab?

 

EDIT: Nvm, i did not notice about the $aProtected variable, still nice work with this script, keeps clean my browser.

Edited by DynamicRookie
Link to post
Share on other sites

DR,
it is not necessary to quote every post you want to reply to. It just clutters the thread.
Simply click on the Reply button. And if needed refer to a post number or the name of the other poster :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites
  • 7 months later...

Hi Danp2,

Sorry, didn't mean to mislead .. 

I'm using more or less the same method as above
For now .., any one motivated to come up with there own can compare the results with this one if that's something to try ..
i reckoned that there ain't something that is worth to promote with this and probably not something that is acceptable by the chrome team !
I'm also tying to test other things - encryption methods @compiles and stuff..

Thanks 
Deye
 

Link to post
Share on other sites

Hi,

Can any one only give an approval that this last version is running properly
Its already at version 1.0.0.8 , Overcoming all former glitches ..

* in my tests, if the browser is super busy then it may miss a tab that was intended to be closed, else all otherwise ..
* IGWS: if your AV warns you of a virus then don't post back on such a thing (It isn't  :closedeyes:)

Thanks

Deye

Edited by Deye
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...