Last active
December 12, 2015 09:58
-
-
Save t-kashima/4755019 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var keyword = 'りんご'; | |
function searchComplete(searcher) { | |
var results = searcher.results; | |
if( results && (0 < results.length)) { | |
var content = document.getElementById( 'content' ); | |
// 情報を取得する | |
for( var i = 0; i < results.length; i++ ) { | |
if (canAnimate(results[i].tbUrl) === true) { | |
logDebug('url:' + results[i].tbUrl); | |
} | |
} | |
var cursor = searcher.cursor; | |
// logDebug('estimatedResultCount:' + cursor.estimatedResultCount); | |
searcher.gotoPage(searcher.cursor.currentPageIndex + 1); | |
} | |
} | |
searchImages(keyword); | |
logDebug('animation-gif.js ready'); |
This file contains hidden or 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
var DEBUG = true; | |
function logDebug(message) { | |
if (DEBUG == true) { | |
console.log(message); | |
} | |
} |
This file contains hidden or 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
var elementContent = document.querySelector('#content'); | |
var bytes; | |
function getFileStream(url) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', url, false); | |
xhr.overrideMimeType('text/plain; charset=x-user-defined'); | |
xhr.send(null); | |
if (xhr.status != 200) { | |
return; | |
} | |
return xhr.responseText; | |
} | |
function checkByteByIndex(index, checkNumber) { | |
if (bytes.length <= index) { | |
return false; | |
} | |
if (bytes[index] !== checkNumber) { | |
return false; | |
} | |
return true; | |
} | |
function canAnimate(url) { | |
var fileStream = getFileStream(url); | |
bytes = []; | |
for (var i = 0; i < fileStream.length; i++) { | |
bytes[i] = fileStream.charCodeAt(i) & 0xff; | |
} | |
var canAnimate = false; | |
var size = bytes.length; | |
for (var i = 0; i < size; i++) { | |
if (checkByteByIndex(i, 33) === true && | |
checkByteByIndex((i + 1), 255) === true && | |
checkByteByIndex((i + 2), 11) === true) { | |
canAnimate = true; | |
break; | |
} | |
} | |
return canAnimate; | |
} | |
logDebug('gif.js ready'); |
This file contains hidden or 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
<!DOTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>animation Gif</title> | |
</head> | |
<body> | |
<div id="content"></div> | |
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<script type="text/javascript" src="const.js"></script> | |
<script type="text/javascript" src="gif.js"></script> | |
<script type="text/javascript" src="search-google.js"></script> | |
<script type="text/javascript" src="animation-gif.js"></script> | |
</body> | |
</html> |
This file contains hidden or 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
var keyword; | |
// must implements searchComplete | |
function loadedSearchApi() { | |
var imageSearch = new google.search.ImageSearch(); | |
imageSearch.setRestriction( | |
google.search.ImageSearch.RESTRICT_FILETYPE, | |
google.search.ImageSearch.FILETYPE_GIF | |
); | |
imageSearch.setResultSetSize(8); | |
imageSearch.setSearchCompleteCallback( | |
this, | |
searchComplete, | |
[imageSearch] | |
); | |
logDebug('search keyword:' + this.keyword); | |
imageSearch.execute(this.keyword); | |
} | |
function searchImages(keyword) { | |
this.keyword = keyword; | |
google.setOnLoadCallback(loadedSearchApi); | |
google.load('search', '1'); | |
} | |
logDebug('search-google.js ready'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment