xReader
xReader is a javascript function for accessing other resources without restrictions by YQL.
- Current Version : v0.0.78a - 2012-11-13
- MIT License
- Source
xReader.full.js - Full version
xReader.micro.js - Micro version (without option, 725 byte)
xReader.xml - Data table for YQL - Author
SD05 (blog),
oneiroi@outlook.com - Document
xReader Korean Demo
lift restrictions!
- XHR Restriction! (Same-Origin policy)
- XHR with CORS for old ie browsers
- document.domain
- robots.txt from YQL
xReader Usage
<script src="http://kincrew.github.com/xReader/xReader.full.js"></script>
<script type="text/javascript">
xReader("http://www.yahoo.com/", function(data) {
alert(data.content);
})
<script type="text/javascript">
xReader("http://www.yahoo.com/", function(data) {
alert(data.content);
})
RUN
</script>
Download xReader.micro.js or xReader.full.js.
xReader features
- Browsers : IE5.5~, Safari, Chrome, Firefox, Opera, Netscape Navigator9
- Auto charset
- Auto redirect
- CSS selector
xReader API
xReader("URL", "CSS", callback, option)
- [string] URL
- [string] CSS - optional
- [function] callback(data)
data = {
headers : [obeject],
content : [string|object]
format : [string]
original : [obeject]
redirect : {
from : [string],
to : [string],
status : [string]
},
url : [string],
date : [date],
statue : [string],
status : [string],
error : [obeject],
YQL : [obeject]
xReader : [obeject],
option : [obeject],
maxAge : [number]
}
headers : [obeject],
content : [string|object]
format : [string]
original : [obeject]
redirect : {
from : [string],
to : [string],
status : [string]
},
url : [string],
date : [date],
statue : [string],
status : [string],
error : [obeject],
YQL : [obeject]
xReader : [obeject],
option : [obeject],
maxAge : [number]
}
- [object] option - optional
| OPTION | DESC | VALUE |
|---|---|---|
| cacheBurst | check this [YQL BLOG] | false | true |
| charset | caharset (Wait plz) | undefined | [string] |
| content | data (Wait plz) | undefined | [string] |
| contentType | content-type (Wait plz) | undefined | [string] |
| cookie | cookie | undefined | [object] |
| css | css selector | undefined | [string] |
| diagnostics | YQL diagnostics | false | true |
| format | content format | "text" | "json" | "dom" | "dom2" |
| forceCharset | force Charset | undefined | [string] |
| fallbackCharset | fallback Charset | "utf-8, euc-kr, iso-8859-1" | [string] |
| headers | http request headers | undefined | [object] |
| link | method from xReader to YQL/td> | "auto" | "ajax" | "jsonp" |
| method | http request method | "get" | "post" | "head" | "put" |
| maxAge | maxAge by the url (sec) | undefined | [number] |
| maxAgeGlobal | maxAge (sec) | undefined | [number] | "reset" |
| query | YQL Query | undefined | [string] |
| param | undefined | [object] | |
| referer | referer | undefined | [string] |
| ssl | YQL SSL | false | true |
| table | choose other table | "http://kincrew.github.com/xReader.xml" | [string] |
| target | undefined | [object] | |
| tidy | json | false | true |
| timeout | timeout (ms) | 10000 | [number] |
| ua | ua | undefined | "current" | [string] |
| xpath | xpath | undefined | [string] |
- set timeout : xReader.timeout = 1000
Simple Demo
HTML / XML
/* Headline from The Wall Street Journals*/
xReader("wsj.com", "#main_content h2 a/text()", function(data){
alert(data.content);
})
xReader("wsj.com", "#main_content h2 a/text()", function(data){
alert(data.content);
})
RUN
[TIP] If you want get only text, add "/text()"
[INFO] auto redirection : wsj.com -> http://online.wsj.com/ -> http://online.wsj.com/home-page
JSON / JSONP
/* tag : cat from flickr */
var url = "http://api.flickr.com/services/feeds/photos_public.gne?";
url += "tags=cat&tagmode=any&format=json";
xReader(url, function(data){
var items = data.content.items;
var html = "";
for (var i=0; items.length > i ;i++ ) {
html += "<div>" + items[i].description + "</div>";
}
return html;
},
{
format : "json", // type
target : document.getElementById("exDemoResult4") // output target
})
var url = "http://api.flickr.com/services/feeds/photos_public.gne?";
url += "tags=cat&tagmode=any&format=json";
xReader(url, function(data){
var items = data.content.items;
var html = "";
for (var i=0; items.length > i ;i++ ) {
html += "<div>" + items[i].description + "</div>";
}
return html;
},
{
format : "json", // type
target : document.getElementById("exDemoResult4") // output target
})
RUN
powered by Yahoo! Query Language