Help us understand the problem. What is going on with this article?

Evernoteに保存したミイルのノートに位置情報を追加するハンドラ

More than 3 years have passed since last update.
  • 食事記録SNSミイル
  • iOS版ミイル内で「シェア」>「Evernote」>「保存」したノート
  • ノートのソースURLにはミイルに投稿したURLが含まれる
    • http://miil.me/g/...またはhttp://miil.me/p/...
  • Mac版EvernoteでミイルのノートからURLを取得してSafariでページを開く
  • 投稿ページ中部にある店情報からミイルの店舗ページへ移動
    • http://miil.me/v/...
  • 店舗ページ中部に埋め込まれた地図から位置情報を取得
  • ミイルのノートに位置情報を追加
setAddressToMiilNoteInEvernote.scpt
tell application "Evernote"
    set {miilNote} to selection
end tell
my setAddressToMiilNoteInEvernote(miilNote)

on setAddressToMiilNoteInEvernote(miilNote)
    tell application "Evernote"
        tell miilNote
            set {lat:latitude, lng:longitude} to my getLatlngOfRestaurantFromMiil(source URL)
        end tell
    end tell
end setAddressToMiilNoteInEvernote

on getLatlngOfRestaurantFromMiil(miilURL as text)
    if miilURL does not start with "http://miil.me/" then
        error
    end if
    my openURLinSafari(miilURL)
    tell application "Safari"
        if character 16 of miilURL is in {"g", "p"} then
            set JSResult to "loading"
            repeat while JSResult = "loading"
                set JSResult to do JavaScript "if(!document.getElementsByClassName('detailphoto')[0]) {
    'loading';
} else {
    var elements = document.getElementsByClassName('venueHdl mb20');
    if(!elements[0]) {
        'error';
    } else {
        elements[0].firstChild.click();
    }
}" in document 1
                if JSResult = "error" then
                    error "店舗を取得できませんでした"
                end if
            end repeat
        end if
        set latlng to missing value
        repeat while latlng = missing value
            delay 1
            set latlng to do JavaScript "var latlng = document.getElementById('venueMapView').firstElementChild.children;
latlng[0].getAttribute('content') + '\\n' + latlng[1].getAttribute('content');" in document 1
        end repeat
        close current tab of window 1
    end tell
    return {lat:paragraph 1 of latlng as number, lng:paragraph 2 of latlng as number}
end getLatlngOfRestaurantFromMiil

on openURLinSafari(aURL)
    tell application "Safari"
        open location aURL
        repeat
            try
                set aTab to current tab of window 1
                exit repeat
            on error number -1719
            end try
        end repeat
    end tell
    my waitForSafariLoading(aTab)
    return aTab
end openURLinSafari

on waitForSafariLoading(aTab)
    repeat while my loadingOfSafari(aTab)
        delay 1
    end repeat
end waitForSafariLoading

on loadingOfSafari(aTab)
    try
        tell application "Safari"
            return (URL of aTab = missing value) or (do JavaScript "document.readyState" in aTab)  "complete"
        end tell
    on error
        return true
    end try
end loadingOfSafari

更新情報

  • 2015-10-15: Mac用Twitterクライアント「夜フクロウ」経由で試作
  • 2015-12-21: EvernoteのノートからURLを取得するように変更
  • 2015-12-22: 店舗の位置情報取得元を住所から地図へ変更
  • 2015-12-26: 店舗情報がない投稿に対応
szk-3
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away