Last active
December 18, 2015 17:38
-
-
Save tmplinshi/5819427 to your computer and use it in GitHub Desktop.
This script is intended used for chat client.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ====================================================================================================================== | |
; IM Emoticons v1.00 (2013-6-20) by tmplinshi | |
; Tested on: AHK_L v1.1.10.01 (A32) / WINDOWS XP SP3 | |
; ====================================================================================================================== | |
; | |
; This script is intended used for chat client. | |
; | |
; Usage: Click or drag emotion into the chat window. | |
; ====================================================================================================================== | |
#NoEnv | |
#SingleInstance force | |
SetWorkingDir, %A_ScriptDir% | |
SetBatchLines, -1 | |
CoordMode, Mouse, Screen | |
gui_title := "IM Emoticons v1.00" | |
; ---------------------------- Settings ---------------------------- | |
; Emoticons root Folder | |
RootDir := A_ScriptDir | |
; Show as normal window (with title and taskbar button.) | |
ShowGuiTitle := False | |
; Auto close window when focus lost | |
LossFocus_CloseGui := True | |
; Hide scrollbar | |
; (When hiding, the ActiveX's height will auto resize. Otherwise, height will be 215.) | |
HideScrollbar := True | |
; Highlight image under mouse | |
; (If the folder contains too much gifs, it may result in improper operation smooth.) | |
HighlightImage := True | |
; ---------------------------- /Settings ---------------------------- | |
; Html code --- head | |
html_head = | |
(LTrim | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<script> | |
function copyImage(ID) | |
{ | |
var HeaderImage = document.getElementById(ID); | |
var controlRange; | |
if (document.body.createControlRange) | |
{ | |
controlRange = document.body.createControlRange(); | |
controlRange.addElement(HeaderImage); | |
controlRange.execCommand('Copy'); | |
} | |
return false; | |
} | |
</script> | |
</head> | |
) | |
; Html code --- hide scrollbar | |
if HideScrollbar | |
style_HideScrollbar := "html { overflow: hidden }" | |
; Html code --- highlight image under mouse | |
if HighlightImage | |
html_MouseMove = | |
(LTrim | |
onmouseover="this.className='borderOn'" | |
onmouseOut="this.className='borderOff'" | |
class="borderOff" | |
) | |
; Html code --- style | |
html_style = | |
(LTrim | |
<style> | |
table { | |
margin: auto; | |
text-align: center; | |
} | |
td { | |
position: fixed; | |
width: 24pt; | |
height: 24pt; | |
text-align:center; | |
} | |
img { | |
max-width:100`%; | |
max-height:100`%; | |
} | |
.borderOn { | |
border: solid 1px #4CA0D9; | |
background-color: #D0F0FF; | |
} | |
%style_HideScrollbar% | |
</style> | |
) | |
; Html code --- td attributes | |
td_attrib = | |
(LTrim Join%A_Space% | |
%html_MouseMove% | |
onclick="document.all._cp.src=this.innerHTML" | |
) | |
; ################################# | |
; Create html | |
; ################################# | |
; | |
; Create folder ".html" | |
IfNotExist, .html | |
FileCreateDir, .html | |
MaxCount := 0 | |
Loop, %RootDir%\*, 2 ; Search folder | |
{ | |
if A_LoopFileName = .html | |
Continue | |
; Delete html file, then recreate | |
htmlFile = .html\%A_LoopFileName%.html | |
FileDelete, %htmlFile% | |
; html code --- TOP | |
FileAppend, %html_head%%html_style%<table border="1" cellspacing="0px" bgcolor="#F6FBFE" bordercolor="#D3E4F0">`r`n, %htmlFile% | |
; html code --- MIDDLE | |
_count := "", tr_start := "", tr_end := "", TotalImages := 0 | |
Loop, %A_LoopFileLongPath%\* ; Search images | |
{ | |
if A_LoopFileExt not in bmp,jpg,jpeg,gif,png,ico | |
Continue | |
; When add "tr" tag | |
_count += 1 | |
tr_start := (_count=1) ? "<tr>" : "" | |
tr_end := (_count=14) ? "</tr>" : "" | |
; "alt" value for tooltip | |
SplitPath, A_LoopFileName,,,, alt | |
FileAppend, | |
(LTrim Join | |
%tr_start%<td %td_attrib%> | |
<img src="%A_LoopFileLongPath%" alt="%alt%" id="%alt%"></td>%tr_end%`r`n | |
) | |
, %htmlFile% | |
_count := (_count=14) ? 0 : _count | |
TotalImages ++ | |
} | |
MaxCount := (TotalImages > MaxCount) ? TotalImages : MaxCount | |
; html code --- BOTTOM | |
FileAppend, | |
(LTrim Join | |
</table> | |
<iframe name="_cp" src="about:blank" style="display:none;"></iframe> | |
) | |
, %htmlFile% | |
; Save category names | |
if _count != | |
CategoryList := CategoryList "|" A_LoopFileName | |
else | |
FileDelete, %htmlFile% | |
} | |
if !CategoryList | |
{ | |
MsgBox, 48,, Can't find images. The program will exit. | |
ExitApp | |
} | |
CategoryList := LTrim(CategoryList, "|") | |
; | |
ActiveXHeight := ( HideScrollbar ? ( Ceil(MaxCount / 14) * 40 ) : 200 ) + 15 | |
; ################################# | |
; GUI | |
; ################################# | |
; | |
if !ShowGuiTitle | |
{ | |
Gui, Color, EEAA99 | |
Gui +LastFound +Owner | |
WinSet, Transparent, 200 | |
WinSet, TransColor, EEAA99 | |
Gui -Caption | |
} | |
; ----------- | |
StringSplit, c, CategoryList, | | |
Gui, Font, s12 | |
Gui, Color, White | |
Gui, +LastFound +AlwaysOnTop | |
GroupAdd MyGui, % "ahk_id " . WinExist() | |
Gui, Add, ActiveX, xm w530 h%ActiveXHeight% vWB, Shell.Explorer | |
WB.Silent := True | |
WB.Navigate(A_ScriptDir "\.html\" c1 ".html") | |
ComObjConnect(WB, WB_events) | |
Gui, Add, Tab2, x25 w505 h25 Buttons AltSubmit -Wrap -Background BackgroundFFFFFF vTabNumber gChangeCategory, %CategoryList% | |
Gui, Show,, %gui_title% | |
if LossFocus_CloseGui | |
SetTimer, CloseGui, 200 | |
TrayTip, %gui_title%, Hotkey: Press Ctrl+1 to show window. | |
WinGetPos, x, y, w, h | |
Return | |
; ################################# | |
; Hotkey: show window | |
; ################################# | |
; | |
^1:: | |
MouseGetPos, x, y, winID | |
y := (y + h > A_ScreenHeight) ? (y - h) : y | |
x := (x + w > A_ScreenWidth) ? (x - w) : x | |
Gui, Show, x%x% y%y% | |
if LossFocus_CloseGui | |
SetTimer, CloseGui, 200 | |
return | |
; ################################# | |
; Auto close window when focus lost | |
; ################################# | |
; | |
CloseGui: | |
IfWinNotActive, ahk_group MyGui | |
{ | |
Gui, Cancel | |
SetTimer, CloseGui, Off | |
} | |
return | |
; ################################# | |
; Change Category | |
; ################################# | |
; | |
ChangeCategory: | |
GuiControlGet, TabNumber | |
htmlFile := A_ScriptDir "\.html\" c%TabNumber% ".html" | |
WB.Navigate(htmlFile) | |
return | |
#IfWinActive ahk_group MyGui | |
~WheelUp:: | |
~WheelDown:: | |
MouseGetPos,,,, CurrCtrl | |
if (CurrCtrl = "Internet Explorer_Server1") | |
{ | |
if (A_ThisHotkey = "~WheelDown") | |
ControlSend, Internet Explorer_Server1, {PgDn} | |
else | |
ControlSend, Internet Explorer_Server1, {PgUp} | |
return | |
} | |
; --------------------------------------- | |
if (CurrCtrl != "SysTabControl321") | |
return | |
GuiControlGet, TabNumber | |
TabNumber_new := (A_ThisHotkey = "~WheelDown") ? (TabNumber + 1) : (TabNumber - 1) | |
if (TabNumber_new > c0) | |
TabNumber_new := 1 | |
else if (TabNumber_new <= 0) | |
TabNumber_new := c0 | |
GuiControl, Choose, TabNumber, |%TabNumber_new% | |
htmlFile := A_ScriptDir "\.html\" c%TabNumber_new% ".html" | |
WB.Navigate(htmlFile) | |
return | |
;#IfWinExist, ahk_group MyGui | |
;Esc::Gui, Cancel | |
#IfWinActive | |
; ################################# | |
; Close GUI | |
; ################################# | |
; | |
GuiEscape: | |
GuiClose: | |
Gui, Cancel | |
; ============================================================================================= | |
class WB_events | |
{ | |
NavigateComplete2(wb, url) | |
{ | |
if ( url = "about:blank" || SubStr(url, -4) = ".html" ) | |
return | |
Gui, Cancel ; Close GUI | |
WinWaitClose | |
Clipboard_bak := ClipboardAll ; Backup clipboard | |
Clipboard := | |
; Copy image | |
img_id := RegExReplace(url, "^.*\\([^>]+)\.[^.]+>$", "$1") | |
__CopyImg(img_id) | |
ClipWait, 5 | |
SendInput, ^v ; Paste | |
Sleep, 200 | |
KeyWait, v | |
Clipboard := Clipboard_bak ; Restore clipboard | |
Clipboard_bak = ; Clear clipboard backup | |
} | |
} | |
__CopyImg(img_id) | |
{ | |
global | |
WB.document.parentWindow.execScript("Javascript:copyImage('" img_id "')") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment