Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
Bby67 la Simpatie.ro
Femeie
19 ani
Bucuresti
cauta Barbat
19 - 70 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [AUTOHOTKEY] Script to wrap text between tags [AHK] Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
SEE POST 3 FOR THE UPDATED v3 VERSION - works in all programs, not only browsers, has undo

I will post below the script which must be saved with the .ahk extension and opened using the AutoHotkey software in order to be compiled.

As you can see from the top 4 lines between quote tags, it addresses 4 browsers: Mozilla, Chrome, IE and Opera.

The script can be also converted into a simple executable using the autohotkey included compiler. It can be added to startup either by converting to exe (which is independent of the AHK software and can be run without installing it) or as the default script in AHK.

Will be quoting the text below using the script between quote tags ;)

Version 1 (v1)


GroupAdd, Browsers, ahk_class MozillaWindowClass
GroupAdd, Browsers, ahk_class Chrome_WidgetWin_0
GroupAdd, Browsers, ahk_class IEFrame
GroupAdd, Browsers, ahk_class OperaWindowClass

#IfWinActive ahk_group browsers
!sc030::Wrap("b") ; Alt+B
!sc016::Wrap("u") ; Alt+U
!sc017::Wrap("i") ; Alt+I
!sc019::Wrap("img") ; Alt+P
!sc010::Wrap("quote") ; Alt+Q
!sc023::Wrap("h") ; Alt+h
!sc01F::Wrap("s") ; Alt+s
!sc02D::Wrap("code") ; Alt+x
!Up::Wrap("sup") ; Alt+Up
!Down::Wrap("sub") ; Alt+Down

Wrap(tag) {
OldClipboard := Clipboard
Clipboard := ""
sleep, 10
send, ^c
sleep, 10
if (Clipboard = "") {
Clipboard := OldClipboard
return
}
Clipboard := "[" tag "]" . Clipboard . "[/" tag "]"
send, ^v
Clipboard := OldClipboard
}


_______________________________________


pus acum 9 ani
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
Version 2 (v2):

GroupAdd, Browsers, ahk_class MozillaWindowClass
GroupAdd, Browsers, ahk_class Chrome_WidgetWin_0
GroupAdd, Browsers, ahk_class IEFrame

#IfWinActive ahk_group browsers
~!b::Wrap("b")
~!u::Wrap("u")
~!i::Wrap("i")
~!p::Wrap("img")
~!q::Wrap("quote")
~!x::Wrap("code")
~!c::Wrap("color")
#IfWinActive

Wrap(tag)
    {
     OldClipboard := Clipboard
     send, ^c
     Sleep, 10
     Clipboard := "[" tag "]" . Clipboard . "[/" tag "]"
     send, ^v
     Clipboard := OldClipboard
    }


Source:


_______________________________________


pus acum 4 ani
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
Version 3 (v3) - BEST SO FAR:
- works in any software (not just browsers)
- has undo (with Alt+Del) to remove the previously inserted tag
- you can insert tags without selecting text and it will move cursor between tags so you can go straight to adding text


HOW TO USE:

1. Start the script (you must have AutoHotkey installed) - by default a green H appears in the notification area

2. Select text you want to wrap between tags // Or you can place the cursor in an empty space and insert empty tags then the cursor will automatically move in between them.

3. Press one of the following combinations:
- ALT+b - bold tags [b][/b]
- ALT+u - underline tags [u][/u]
- ALT+i - italic tags [i][/i]
- ALT+1 - img tags [img][/img]
- ALT+2 - color tags [color=][/color]
- ALT+q - quote tags [quote][/quote]
- ALT+x - code tags [code][/code]
- ALT+y - angle tags < > (I use them in Discord)

4. In case you add some tags by mistake you can easily remove them with ALT+Del key combination, then add the right tags

IMPORTANT:

Copy the code in the post as the post is.
Do not copy the source of this post as I had to add italic tags in order to prevent some color, code and quote tags from happening inside the code and ruining it.


I marked all comments in the code in this color.


    /*#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
    ; #Warn  ; Enable warnings to assist with detecting common errors.
    SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
    SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
    */

    /*
    [script info]
    version     = 2.5
    description = wrap selected text in %symbols%
    author      = davebrny
    source      = https://gist.github.com/davebrny/088c48d6678617876b34f53571e92ee6
    */


SendMode Input
return ; end of auto-execute
;---------------------------



!b::
::wb::
goTo, wrap_bold        ;   text

!u::
::wu::
goTo, wrap_underline        ;   text

!i::
::wi::
goTo, wrap_italic        ;   text

!1::
::w1::
goTo, wrap_img          ;   [img]text[/img]

!2::
::w2::
goTo, wrap_color1        ;   [color=aqua]text[/color]

!3::
::w3::
goTo, wrap_color2        ;   [color=lime]text[/color]

!4::
::w4::
goTo, wrap_color3        ;   [color=gold]text[/color]

!5::
::w5::
goTo, wrap_color4        ;   [color=salmon]text[/color]

!6::
::w6::
goTo, wrap_color5        ;   [color=#ebadeb]text[/color]

!q::
::wq::
goTo, wrap_quote        ;   [quote]text[/quote]

!x::
::wx::
goTo, wrap_code            ;   [code]text[/code]

!y::
::wy::
goTo, wrap_angle        ;   <text>

!del::
::wdel::
goTo, wrap_delete       ;   _text_  --->  text




;-----------------------





wrap_bold:
wrap_underline:
wrap_italic:
wrap_img:
wrap_color1:
wrap_color2:
wrap_color3:
wrap_color4:
wrap_color5:
wrap_quote:
wrap_code:
wrap_angle:

this_label := a_thisLabel
clipboard_text := get_clipboard()
for what, with in { "wrap_bold"           : "[b]" clipboard_text "[/b]"
                  , "wrap_underline"      : "[u]" clipboard_text "[/u]"
                  , "wrap_italic"       : "[i]" clipboard_text "[/i]"
                  , "wrap_img"             : "[img]" clipboard_text "[/img]"
                  , "wrap_color1"         : "[color=aqua]" clipboard_text "[/color]"
                  , "wrap_color2"         : "[color=lime]" clipboard_text "[/color]"
                  , "wrap_color3"         : "[color=gold]" clipboard_text "[/color]"
                  , "wrap_color4"         : "[color=salmon]" clipboard_text "[/color]"
                  , "wrap_color5"         : "[color=#ebadeb]" clipboard_text "[/color]"
                  , "wrap_quote"           : "[quote]" clipboard_text "[/quote]"
                  , "wrap_code"           : "[code]" clipboard_text "[/code]"
                  , "wrap_angle"         :  "<" clipboard_text ">" }

    stringReplace, this_label, this_label, % what, % with, all
new_text := this_label
goSub, send_wrap
return



wrap_delete:
clipboard_text := get_clipboard()
loop, 2
    {
    stringLeft, left_character, clipboard_text, 1
    stringRight, right_character, clipboard_text, 1
    if regExMatch(left_character, "[\Q'%*-_""~``([{><\E]")
        and if regExMatch(right_character, "[\Q'%*-_""~)``]}><\E]")  ; if  '%*-_"~`([{
        {
        stringTrimLeft, clipboard_text, clipboard_text, 1
        stringTrimRight, clipboard_text, clipboard_text, 1
        }
    else break
    }
new_text := clipboard_text
goSub, send_wrap
return



get_clipboard(){
    global
    if !inStr(a_thisHotkey, ":")    ; if hotkey was used
        {
        revert_clipboard := clipboardAll
        clipboard =
        send ^{c}
        clipWait, 0.3
        if clipboard is space
            clipboard =
        }

    return clipboard
}



send_wrap:
if !inStr(a_thisHotkey, ":") and if (clipboard = "")       ; if hotkey was used
     position := "{Left " round( strLen(new_text) / 2) "}"    ; move cursor between symbols
else position := ""
clipboard := new_text
send % "^{v}" . position
sleep 150
clipboard := revert_clipboard
return



all credits for this code go to davebrny,


_______________________________________


pus acum 2 ani
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
New code by davebrny -

Original code below, I haven't made a personalized one yet.
First of all, comment by davebrny on script usage:


txt.wrap
wrap selected text in *symbols* using a two-stage hotkey

USAGE

- highlight some text
- press alt + w to activate wrap mode
- then press any other key to have that character added to either side of the text
- to remove characters from both sides, press delete or d
- wrap mode will turn off itself after 5 seconds or can be turned off at any time by pressing the esc key

Characters are only deleted on either side if they match and are not alphanumeric, or else if they are in the wrap list

If no text is selected then the wrap characters will be pasted and the cursor will be moved between them

SETTINGS

select_after
set to false if you dont want the text to be re-highlighted after its wrapped

input_limit
how many characters you want to add in one go. if its set to 2 or more and you are only adding 1 when in wrap mode then the enter key will need to be used to complete the wrap. if its set to 1 then the enter key isnt needed

alternatively, if select_after is enabled then you can get the same effect by doing two wraps one after another such as alt+w+" then alt+w+% to get "%TXT%"

delete_limit
if you know you will only ever want to delete 1 character on each side then set this to 1.
the default is set to 2 so things like **TXT** and ~~TXT~~ can be deleted in one go

custom wraps
new wraps can be added to the ini section at the top of the file.
a single character is used for the ini key and the ini value should have TXT in it with whatever characters you want on either side of it

if you are using ; or [ for the ini key then they need to have a literal ` character before them so they are not ignored by the script

if there is more than 1 of the same character in the list then the one the is lower down will be the one thats used. (upper and lower case letters will be seen as different characters though)

WRAP EXAMPLES

characters that normally require the shift key to be pressed

2  = "TXT"
5  = %TXT%
8  = *TXT*
9  = (TXT)
-  = _TXT_
`[ = {TXT}
#  = ~~TXT~~
autohotkey

c = /*TXT*/
h = ^!+{TXT}
t = trim(TXT)
s = inStr(TXT)
markdown

b = **TXT**
s = ~~TXT~~
B = ```TXT```
l = [TXT](url)
p = ![TXT](url)
html

i = <i>TXT</i>
b = <b>TXT</b>
1 = <h1>TXT</h1>
2 = <h2>TXT</h2>
c = <!-- TXT -->
k = <kbd>TXT</kbd>
i = <img src="TXT">
l = <a href="TXT">text</a>
phpBB forum BBCode

b = TXT
i = TXT
u = TXT
q =
TXT

c =

Code:

TXT

l = [list]TXT[/list]
m =  [img]TXT[/img]
u =  TXT
g = [gist]TXT[/gist]
@ = [mention]TXT[/mention]


AND NOW HERE'S THE CODE, RAW AND UNCUT:


/*
[wrap list]
(  =  (TXT)
`[ =  [TXT]
{  =  {TXT}
<  =  <TXT>
>  =  >TXT<
a  =   /`*TXT*`/
h  = <!-- TXT -->
k  = <kbd>TXT</kbd>
m  =  ``` TXT ```
p  = '''' TXT ''''
[settings]
select_after = true
input_limit  = 1
delete_limit = 2
*/

#noEnv
#singleInstance, force
sendMode input

iniRead, select_after, % a_lineFile, settings, select_after
iniRead, input_limit,  % a_lineFile, settings, input_limit
iniRead, delete_limit, % a_lineFile, settings, delete_limit

iniRead, ini_section, % a_lineFile, wrap list    ; save wraps to variables
sort, ini_section, F long_lines_first_w
stringReplace, ini_section, ini_section, % "/``*", % "/*", all    ; remove literals
stringReplace, ini_section, ini_section, % "*``/", % "*/", all
loop, parse, % ini_section, `n, `r
    {
    occurrence := (inStr(a_loopField, "=", , 1) = 1) ? ("L2") : ("")  ; (if key name is the equals symbol, then L2)
    stringGetPos, pos, a_loopField, =, % occurrence
    stringMid, ini_value, a_loopField, pos + 2
    stringMid, ini_key, a_loopField, pos, , L
    ini_key   := trim(ini_key)
    ini_value := trim(ini_value)
    if (ini_key = "```;") or (ini_key = "``[")    ; remove literals
        stringTrimLeft, ini_key, ini_key, 1
    asc := asc(ini_key)    ; convert key character to key number
    %asc% := ini_value
    wrap_list .= (wrap_list = "" ? "":"`n") . ini_value
    }
ini_section := ""

return ; end of auto-execute ---------------------------------------------------



!w:: goSub, select_wrap
!+w::goSub, repeat_last_wrap


select_wrap:
toolTip, text wrap . . .
repeat_last_wrap:
selected := selected_text_w()
if (a_thisLabel = "select_wrap")
    {
    input, key, L%input_limit% T5, {delete}{d}{enter}{esc}
    key := (key = "") ? strReplace(errorLevel, "EndKey:", "") : key
    key := (key = "Escape") ? strReplace(key, "Escape", "") : key
    asc := asc(key)
    this_wrap := %asc%    ; get wrap stored in key number
    }

if (key = "delete") or (key = "d")
    goSub, remove_wrap
else if (errorLevel != "Timeout") and if (key != "")
    {
    if (this_wrap)
        split_wrap(this_wrap, l_wrap, r_wrap)
    else
        {
        l_wrap := key
        r_wrap := key
        if (strLen(key) > 1)
            {
            reversed_string := ""
            loop, parse, key
                reversed_string := a_loopField . reversed_string
            r_wrap := reversed_string
            }
        }
    paste_text_w(l_wrap . selected . r_wrap)
    }
toolTip, ; close
return


remove_wrap:
new_string := ""
loop, parse, % wrap_list, `n, `r    ; figure out which wrap is being used
    {
    split_wrap(a_loopField, l_wrap, r_wrap)
    if inStr(selected, l_wrap) and inStr(selected, r_wrap)
        {
        l_len  := strLen(l_wrap)    ; length of characters
        r_len  := strLen(r_wrap)
        l_string := subStr(selected, 1, l_len)    ; take same length from the string
        r_string := subStr(selected, 1 - r_len, r_len)
        if (l_wrap = l_string) and (r_wrap = r_string)    ; match found on both sides
            {
            new_string := subStr(selected, l_len + 1, strLen(selected) - (l_len + r_len))
            break
            }
        }
    }
if (new_string = "")    ; check for matching character on each side
    {
    tmp_string := selected
    loop, % delete_limit
        {
        left_char := subStr(tmp_string, 1, 1)
        right_char := subStr(tmp_string, 0, 1)
        if (left_char = right_char) and regExMatch(left_char, "[^a-zA-Z0-9]") ; if match and not alphanumeric
            tmp_string := subStr(tmp_string, 2, strLen(tmp_string) - 2)       ; remove both sides
        else break
        }
    if (tmp_string != selected)    ; if something changed
        new_string := tmp_string
    }
if (new_string)
    paste_text_w(new_string)
return


long_lines_first_w(line_a, line_b, offset) {
    if strLen(line_b) != strLen(line_a)
        return strLen(line_b) - strLen(line_a)
    return -offset
}


selected_text_w() {
    global save_clipboard
    save_clipboard := clipboardAll
    clipboard := ""
    send ^{c}
    clipWait, 0.1
    if clipboard is not space
        return clipboard
}


paste_text_w(string) {
    global
    clipboard := string
    send ^{v}
    sleep 200
    if (selected = "")
        send % "{left " strLen(r_wrap) "}"    ; move caret between characters
    else if (select_after = "true")
        {
        if (a_thisLabel = "remove_wrap")      ; select whole string
            send % "{left " strLen(string) "}+{right " strLen(string) "}"
        else
            {
            stringGetPos, pos, string, % selected    ; select original selection
            send % "{left " (strLen(string) - pos) "}+{right " strLen(selected) "}"
            }
        }
    sleep 300
    clipboard := save_clipboard
}


split_wrap(wrap_text, byRef l_wrap, byRef r_wrap) {
    stringGetPos, pos, wrap_text, TXT
    stringMid, l_wrap, wrap_text, pos, , L
    stringMid, r_wrap, wrap_text, pos + 4
}

/*
[script info]
version     = 0.4
description = wrap selected text in %symbols%
author      = davebrny
source      =
*/


_______________________________________


pus acum 2 ani
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
Updated post #3 to add predefined colors to hotkeys ALT + 2, 3, 4, 5, 6

Instead of the single color snippets:

!2::
::w2::
goTo, wrap_color        ;   [color=]text[/color]

and

wrap_color:

and

"wrap_color"         : "[color=]" clipboard_text "[/color]"

I added 5 colors: aqua, lime, gold, salmon and some pink


_______________________________________


pus acum 1 an
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
The following script does this:

First off you manually select multiple lines of text:
line 1
line 2
line n

Press CTRL+Q

Each of the lines above is wrapped around with < > tags:
<line 1>
<line 2>
<line n>

Copy the following code to Notepad, then save with .ahk extension. You must have AutoHotkey software installed in order to be able to run the script.


; CTRL+Q hotkey
^q::

; hotkey above activates copy of the selected text
Send ^c

; tags that will be added BEFORE and AFTER each line of text
val1 = < ; BEFORE
val2 = > ; AFTER

; snippet below loops through the text from clipboard and adds tags above to each line
x:=Clipboard

x=
Loop, parse, clipboard, `n, `r
{
    x .= val1 A_LoopField val2 "`r`n"
    ; x=%x%%val1%%A_LoopField%%val2%`r`n ; equivalent to the line above - use either this or that
}
Clipboard:=x

; automatically pastes the text wrapped with the tags
Send ^v

Return


Source for the main code that does all the tag adding:

Source for hotkey and clipboard copy / paste and the alternative (equivalent) x = line:


_______________________________________


pus acum 1 an
   
Pagini: 1  

Mergi la