Created
May 27, 2011 11:38
-
-
Save moyashi/995083 to your computer and use it in GitHub Desktop.
Safariで表示中のFlickrの写真のimgタグをカーソル位置に挿入するTypeIt4Me( http://bit.ly/iorZdU )用スクリプト
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
℁ | |
global format | |
global isize | |
--出力する画像タグを変える場合はformatを変更 | |
-- $url: isizeで指定した画像のURL | |
-- $width$: isizeで指定した画像のwidth | |
-- $height$: isizeで指定した画像のheight | |
-- $lurl$: 大画像のURL(リンク先に指定するといい感じ) | |
set format to "<a href=\"$lurl$\" target=\"_blank\"><img src=\"$url$\" width=\"$width$\" height=\"$height$\" /></a>" | |
--画像のサイズ指定: 小さい<- sq, t, s, m, z, o, l ->大きい | |
set isize to "m" | |
------------------------------- | |
-- 内部処理 | |
------------------------------- | |
if (my isRunning("Safari")) then | |
my do() | |
end if | |
on do() | |
set props to my getProps(isize) | |
if (props is not equal to missing value) then | |
set format to my replace(format, "$lurl$", (lurl of props)) | |
set format to my replace(format, "$url$", (furl of props)) | |
set format to my replace(format, "$width$", (width of props)) | |
set format to my replace(format, "$height$", (height of props)) | |
return format | |
else | |
return "" | |
end if | |
end do | |
on replace(str, org, rep) | |
try | |
set oldDel to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to org | |
set myList to text items of str | |
set AppleScript's text item delimiters to rep | |
set res to myList as string | |
set AppleScript's text item delimiters to oldDel | |
on error | |
set AppleScript's text item delimiters to oldDel | |
end try | |
return res | |
end replace | |
on isRunning(appname) | |
tell application "System Events" | |
return (count of (every process whose name contains appname)) is greater than 0 | |
end tell | |
end isRunning | |
on hasWindow() | |
tell app "safari" | |
if ((count of documents) > 0) then | |
return true | |
else | |
return false | |
end if | |
end tell | |
end hasWindow | |
on isFlickr() | |
tell application "Safari" | |
set u to URL of document 1 | |
if (u begins with "http://www.flickr.com/photos/") then | |
return true | |
else | |
return false | |
end if | |
end tell | |
end isFlickr | |
on getProps(itype) | |
--小さい <--> 大きい | |
--sq, t, s, m, z, o, l | |
tell application "Safari" | |
if (my hasWindow() and my isFlickr()) then | |
tell application "Safari" | |
set l to (do JavaScript "F.config.flickr.photo.sizes." & "l" & ".url" in document 1) as string | |
set o to (do JavaScript "F.config.flickr.photo.sizes." & "o" & ".url" in document 1) as string | |
set u to (do JavaScript "F.config.flickr.photo.sizes." & itype & ".url" in document 1) as string | |
set w to (do JavaScript "F.config.flickr.photo.sizes." & itype & ".width" in document 1) as string | |
set h to (do JavaScript "F.config.flickr.photo.sizes." & itype & ".height" in document 1) as string | |
end tell | |
return {furl:u, lurl:l, ourl:o, width:w, height:h} | |
else | |
return missing value | |
end if | |
end tell | |
end getProps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment