Posts Whatever Origin
Post
Cancel

Whatever Origin

A humble open source clone of AnyOrigin

http://www.whateverorigin.org/

1
2
3
4
//Usage is similar to anyorigin. For example, to fetch the data from http://google.com with jQuery, use this snippet:
$.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent('http://google.com') + '&callback=?', function(data){
	alert(data.contents);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//advance example
jQuery.ajaxSetup({
    scriptCharset: "utf-8", //or "ISO-8859-1"
    contentType: "application/json; charset=utf-8"
});

jQuery(window).load(function() {
	var currentURL = window.location.href;
	if(currentURL.indexOf("/p/") > -1){
		jQuery.getJSON('http://whateverorigin.org/get?url=' + 
			encodeURIComponent(jQuery('.cart a').attr('href')) + '&callback=?',
			function (data) {

				//If the expected response is text/plain
				if(jQuery('.shop_attributes td').text().indexOf('8086') > -1){
					if(jQuery(data.contents).find('#tabs-1').text().trim() != '')
						jQuery("#section-description").html(jQuery(data.contents).find('#tabs-1'));
				}
				if(jQuery('.shop_attributes td').text().indexOf("amstrad") > -1){
					if(jQuery(data.contents).find('#long-description').text().trim() != '')
						jQuery("#section-description").html(jQuery(data.contents).find('#long-description'));
				}
				if(jQuery('.shop_attributes td').text().indexOf("amiga") > -1){
					if(jQuery(data.contents).find('#read-more').text().trim() != '')
						jQuery("#section-description").html(jQuery(data.contents).find('#read-more'));
				}
				//If the expected response is JSON
				//var response = $.parseJSON(data.contents);

		});
	}
});

origin - http://www.pipiscrew.com/?p=5886 whatever-origin

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags