// arXiv (http://arxiv.org/) から必要情報を取得して // // 1. bibのエントリを作成して,ファイルの最終行に挿入 // 2. PDFをブラウザで開く // 3. PDFの保存先をクリップボードに入れる // // をします. // URL (http://arxiv.org/abs/****.****) をコピーしておくか, // マクロ実行で出てくるダイアログに入れるかします. // $pdfroot = "C:\\pdf\\arXiv"; $urllabel = "url"; $b = searchbuffer; #o = searchoption; #h = hidemaruhandle(0); beginclipboardread; $url = getclipboard; if(leftstr($url,7) != "http://"){ $url = input("URLを入力"); if(!result)endmacro; } #x = x;#y = y; gofiletop; searchdown $url; if(result){ message "もう登録しているように思われます."; moveto #x,#y; setsearch $b,#o; endmacro; } moveto #x,#y; loaddll macrodir + "\\fortex\\sub\\macrodll.dll"; if(!result)loaddll currentmacrodirectory + "\\macrodll.dll"; if(!result)loaddll macrodir + "\\macrodll.dll"; if(!result)loaddll hidemarudir + "\\macrodll.dll"; if(!result){ message "DLLロード失敗"; endmacro; } ##_ = dllfunc("SETHMJREDLL",hidemarudir + "\\HMJRE" + ".DLL"); #ie = createobject("InternetExplorer.Application"); if(#ie == 0){message "IEの起動に失敗";call Exit;} //setpropnum #ie,"Visible",true; callmethod #ie,"Navigate",$url; if(!getresultex(10)){message $url + "\nの取得に失敗";call Exit;} #i = 0; while(true){ if(#i == 10){ message "タイムアウトしました."; call Exit; } #busy = getpropnum(#ie,"busy"); #state = getpropnum(#ie,"ReadState"); if(#busy == 0 || #state == 4)break; sleep 1000; #i = #i + 1; } #doc = getpropobj(#ie,"Document"); if(#doc == 0){message "documentプロパティの取得に失敗";call Exit;} call GetElementsByTagANDClass #doc,"div","authors"; #author = ##return; if(#author == 0)message "Authorの取得に失敗.(でも続いて実行します.)"; else{ $author = dllfuncstr("GSUB",getpropstr(#author,"innerHTML"),"^.*",""); $author = dllfuncstr("GSUB",$author,"(.+?) +(.+?),","\\2, \\1 and"); $author = dllfuncstr("GSUB",$author,"(.+?) +(.+?)$","\\2, \\1"); $author = dllfuncstr("GSUB",$author,"<.*?>",""); $author = dllfuncstr("GSUB",$author,"^ *",""); } call GetElementsByTagANDClass #doc,"h1","title"; #title = ##return; if(#title == 0)message "Titleの取得に失敗.(でも続いて実行します.)"; else $title = dllfuncstr("GSUB",getpropstr(#title,"innerText"),"^[^:]*:[ \\n]*",""); call GetElementsByTagANDClass #doc,"div","dateline"; #dateline = ##return; if(#dateline == 0)message "日付の取得に失敗(でも続けて実行します.)"; else $year = dllfuncstr("MATCHSTR",getpropstr(#dateline,"innerText"),"Submitted on [0-9]+ [a-zA-Z]+ ([0-9]*)","\\1"); #lis = callmethod_returnobj(#doc,"getElementsByTagName","li"); #i = 0; #num = getpropnum(#lis,"length"); while(#i < #num){ #li = getcollection(#lis); if(strstr(tolower(getpropstr(#li,"innerText")),"pdf") != -1){#pdf = #li;break;} #i = #i + 1; } if(#pdf == 0){message "PDFファイルの取得に失敗.(でも続いて実行します.)";} $pdf = dllfuncstr("MATCHSTR",getpropstr(#pdf,"innerHTML"),"href *= *\".*/([^/]*)\"","\\1"); callmethod #ie,"Quit"; #ie = 0; $arXivnumber = dllfuncstr("MATCHSTR",$url,".*/([^/]*)$","\\1"); $pdfurl = dllfuncstr("MATCHSTR",$url,"(http://[^/]*/)","\\1") + "pdf/" + $pdf; $toclip = dllfuncstr("MATCHSTR",$pdfroot,"(.*?)\\\\?$","\\1") + "\\" + $pdf + ".pdf"; gofileend; insert "@article{arXiv:" + $arXivnumber + ",\n" + "\ttitle = {" + $title + "},\n" + "\tauthor = {" + $author + "},\n" + "\tnote = {arXiv:" + $arXivnumber + "},\n" + "\t" + $urllabel + " = {" + $url + "},\n" + "\tyear = {" + $year + "},\n" + "}\n\n"; setclipboard $toclip; openbyshell $pdfurl; call Exit; // ##1 : object // $$2 : tag // $$3 : class GetElementsByTagANDClass: ##elts = callmethod_returnobj(##1,"getElementsByTagName",$$2); ##i = 0; ##elt_num = getpropnum(##elts,"length"); while(##i < ##elt_num){ ##elt = getcollection(##elts); if(getpropstr(##elt,"className") == $$3)return ##elt; ##i = ##i + 1; } return 0; Exit: callmethod #ie,"Quit"; setsearch $b,#o; freedll; endmacro;