1 (изменено: DD, 2012-04-04 11:31:30)

Тема: AHK: Закладурки и AutoHotkey — дружба навеки)

Предназначен для быстрого применения выбранного букмарклета к странице — в зависимости от типа браузера, в котором она открыта.

Список букмарклет-файлов предполагается создавать в определённой папке с расширениями ".bm".
Пример содержимого такого файла:


Созданный файл может содержать комментарии — извлечена будет первая найденная строка, начинающаяся на "javascript:".

Creates a bookmarklet that will take whatever word is currently selected and look it up in the English Wiktionary.

javascript:Wi=document.getSelection(); if (!Wi) {void(Wi=prompt('Type word for Wiktionary:',''))} if (Wi) location.href='http://en.wiktionary.org/wiki/'+escape(Wi)+' '

Пример названия —

(ie(op(ff(ns(mz  Wiktionary Search.bm

— где (ie, (op, (ff, (ns, (mz — возможность совместимости этой конкретной js-процедуры с браузерами Internet Explorer, Opera, Firefox, Netscape Navigator, Mozilla соотв.

Горячая клавиша — F5


; Расположение создаваемых букмарклет-файлов
BKMKLTs = %A_ScriptDir%\BKMKLTs\*.bm

GroupAdd, OperaBrows, ahk_class OpWindow ; Opera
GroupAdd, OperaBrows, ahk_class OperaWindowClass ; Opera

GroupAdd, MozillaBrows, ahk_class MozillaUIWindowClass ; FF
GroupAdd, MozillaBrows, ahk_class MozillaWindowClass   ; FF

F5::
Menu, MyMenu, Add, DummyText, MenuHandler

Menu, MyMenu, DeleteAll
Loop, %BKMKLTs%
   Menu, MyMenu, Add, %A_LoopFileName%, MenuHandler
Menu, MyMenu, Show
Return

MenuHandler:
FileRead, BkMk, %A_ScriptDir%\%A_ThisMenuItem%
if not ErrorLevel
{
  TempClipboard:= ClipboardAll
  clipboard =

  Pos = 1
  Pos := RegExMatch(BkMk, "m`a)^javascript\:.*$", Found, Pos + StrLen(Found))
    Clipboard .= Found . "`n"

  ;Если активна Opera
  If WinActive("ahk_group OperaBrows") and If InStr(A_ThisMenuItem, "(op")
  {
    SendInput, {F8}
    Sleep, 250
    SendInput, {Ctrl Down}{sc2f}{Ctrl Up}   ;v
  }
  ;Internet Explorer
  If WinActive("ahk_class IEFrame") and If InStr(A_ThisMenuItem, "(ie")
  {
    WinActivate, ahk_class IEFrame
    ControlFocus, Edit1, ahk_class IEFrame
    ControlSetText, Edit1, %Clipboard%, ahk_class IEFrame
  }
  ;Mozilla Firefox (не настроено)
  If WinActive("ahk_group MozillaBrows") and If InStr(A_ThisMenuItem, "(ff")
    msgbox %Clipboard%

  Send, {ENTER}
  clipboard =
  BkMk =
  Clipboard:= TempClipboard
}
Return

Кое-что о закладурках: http://forum.script-coding.com/viewtopi … 238#p13238