Last active
August 29, 2015 14:04
-
-
Save hnq90/5792caddbbfacb9b5a6c to your computer and use it in GitHub Desktop.
Get link Flickr
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
| // View Flickr source code | |
| (function () { | |
| var init = function () { | |
| getflickr(); | |
| } | |
| var topLargest = 3; | |
| var orderSizesByHeight = function (sizes) { | |
| var sz = [], | |
| szLen, total, result = {}; | |
| for (var obj in sizes) { | |
| sz.push(sizes[obj]); | |
| } | |
| result.total = szLen = sz.length; | |
| sz.sort(function (a, b) { | |
| return parseInt(a.height, 10) > parseInt(b.height, 10); | |
| }); | |
| if (topLargest && !! parseInt(topLargest, 10) && sz.length >= topLargest) { | |
| for (var i = szLen - 1; i >= 0; i--) { | |
| if (i < szLen - topLargest) { | |
| var modSz = sz[i]; | |
| modSz.hidden = true; | |
| sz[i] = modSz; | |
| } | |
| } | |
| } | |
| result.sizes = sz; | |
| return result; | |
| }; | |
| var getflickr = function () { | |
| var allSizesScript = document.querySelectorAll("script[type='text/javascript']"), | |
| regex = new RegExp("(modelExport:)(.*?]})(,)", 'm'), | |
| html, data, photoObj, ordered; | |
| if (allSizesScript && allSizesScript.length > 1) { | |
| allSizesScript = allSizesScript[allSizesScript.length - 1]; | |
| if (allSizesScript.innerHTML && allSizesScript.innerHTML.length > 0) { | |
| html = allSizesScript.innerHTML; | |
| if (html.indexOf('modelExport:') > -1) { | |
| data = regex.exec(html); | |
| if ( !! data && !! data['length'] && data.length > 1) { | |
| photoObj = JSON.parse(data[2]); | |
| ordered = orderSizesByHeight(photoObj["photo-models"][0].sizes, 3); | |
| osz = ordered.sizes; | |
| //".photo-sidebar-actions-view" | |
| for (var count = 0; count < osz.length; count++) { | |
| console.log(osz[count]["url"]); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }; | |
| init(); | |
| })(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment