WSH: jQuery 1.6.2を使用する例 (WSF)
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
<job> | |
<!-- | |
WSHでjQuery 1.6.2を使用する例 (Shift_JISで保存してください…) | |
# 元プログラム | |
http://d.hatena.ne.jp/hirataka522/20080806/1218031483 | |
# 使用例(コマンドプロンプト) | |
cscript kion.wsf 大垣 | |
--> | |
<script language="JScript"> | |
var html = new ActiveXObject("htmlfile"); | |
// 4639行目、Sizzle.uniqueSort()で使用するsortOrderを定義する際のコードの一部が | |
// if ( document.documentElement.compareDocumentPosition ) となっていて | |
// documentElementがnullだとエラーになるのでダミーHTMLを書き込みます。 | |
html.write('<html></html>'); | |
var window = html.parentWindow; | |
var navigator = window.navigator; | |
var document = window.document; | |
var location = document.location; | |
window.ActiveXObject = ActiveXObject; | |
// 939行目、doScrollCheck()の定義中にsetTimeout()を使用していて、 | |
// WSHにはsetTimeout()がないためsetTimeoutを定義します。ただし | |
// var setTimeout = window.setTimeout; | |
// とすると「書き込みできません」というエラーが出るため関数式でラッピングします。 | |
var setTimeout = function(func, delay) { return window.setTimeout(func, delay) }; | |
</script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" /> | |
<script language="JScript"> | |
var url = "http://www.google.co.jp/search?q=天気 "+ WScript.Arguments.item(0); | |
var $ = window.$; | |
// 7818行目、jQuery.ajaxTransport内のクロスドメインリクエストが出来るかのチェックが | |
// if ( !s.crossDomain || jQuery.support.cors ) となっていて、 | |
// クロスドメイン通信と見なされている状態(※1)でCORS(Cross Orign Resource Sharing)が | |
// 有効でない(※2)場合jQuery.ajax()が"No Transport"エラーになるため、 | |
// jQuery.support.corsを手動で有効にします。 | |
// ※1: location.hrefとjQuery.ajax()で渡されるurlのホストチェックによる(7227行目) | |
// ※2: 生成したXMLHttpRequestオブジェクトにXMLHttpRequest level2のwithCredentialsが | |
// あるかどうかの判定による(7809行目) | |
$.support.cors = true; | |
$.ajax({ | |
url: url, | |
async: false, | |
complete: function(res){ | |
html.write(res.responseText); | |
// Googleの構造が変わっているのでセレクタを変更します。 | |
WScript.Echo($('div.g table table td:contains("°C")').text()); | |
} | |
}); | |
</script> | |
</job> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WSH: jQuery 1.6.2を使用する もどうぞ