// ==UserScript== // @include https://www.instagram.com/* // @exclude https://www.instagram.com/p/*/embed/* // ==/UserScript== (function(opera){ var once = true; var ScriptName = 'instagram.com.js'; var qid = '66eb9403e44cc12e5b5ecda48b667d41'; // https://www.instagram.com/static/bundles/metro/ProfilePageContainer.js/19b6df5c0bbd.js var postsNum = 50; var rhx, cursor; // https://stackoverflow.com/questions/1655769/fastest-md5-implementation-in-javascript MD5=function(r){function a(r,n){var t,o,e,u,f;return e=2147483648&r,u=2147483648&n,f=(1073741823&r)+(1073741823&n),(t=1073741824&r)&(o=1073741824&n)?2147483648^f^e^u:t|o?1073741824&f?3221225472^f^e^u:1073741824^f^e^u:f^e^u}function n(r,n,t,o,e,u,f){return a((r=a(r,a(a(n&t|~n&o,e),f)))<<u|r>>>32-u,n)}function t(r,n,t,o,e,u,f){return a((r=a(r,a(a(n&o|t&~o,e),f)))<<u|r>>>32-u,n)}function o(r,n,t,o,e,u,f){return a((r=a(r,a(a(n^t^o,e),f)))<<u|r>>>32-u,n)}function e(r,n,t,o,e,u,f){return a((r=a(r,a(a(t^(n|~o),e),f)))<<u|r>>>32-u,n)}function u(r){var n,t="",o="";for(n=0;n<=3;n++)t+=(o="0"+(o=r>>>8*n&255).toString(16)).substr(o.length-2,2);return t}var f,i,C,c,g,h,d,v,S;for(f=function(r){for(var n,t=r.length,o=16*(((n=t+8)-n%64)/64+1),e=Array(o-1),u=0,f=0;f<t;)u=f%4*8,e[n=(f-f%4)/4]|=r.charCodeAt(f)<<u,f++;return e[n=(f-f%4)/4]|=128<<f%4*8,e[o-2]=t<<3,e[o-1]=t>>>29,e}(r=function(r){r=r.replace(/\r\n/g,"\n");for(var n="",t=0;t<r.length;t++){var o=r.charCodeAt(t);o<128?n+=String.fromCharCode(o):(127<o&&o<2048?n+=String.fromCharCode(o>>6|192):(n+=String.fromCharCode(o>>12|224),n+=String.fromCharCode(o>>6&63|128)),n+=String.fromCharCode(63&o|128))}return n}(r)),h=1732584193,d=4023233417,v=2562383102,S=271733878,r=0;r<f.length;r+=16)d=e(d=e(d=e(d=e(d=o(d=o(d=o(d=o(d=t(d=t(d=t(d=t(d=n(d=n(d=n(d=n(C=d,v=n(c=v,S=n(g=S,h=n(i=h,d,v,S,f[r+0],7,3614090360),d,v,f[r+1],12,3905402710),h,d,f[r+2],17,606105819),S,h,f[r+3],22,3250441966),v=n(v,S=n(S,h=n(h,d,v,S,f[r+4],7,4118548399),d,v,f[r+5],12,1200080426),h,d,f[r+6],17,2821735955),S,h,f[r+7],22,4249261313),v=n(v,S=n(S,h=n(h,d,v,S,f[r+8],7,1770035416),d,v,f[r+9],12,2336552879),h,d,f[r+10],17,4294925233),S,h,f[r+11],22,2304563134),v=n(v,S=n(S,h=n(h,d,v,S,f[r+12],7,1804603682),d,v,f[r+13],12,4254626195),h,d,f[r+14],17,2792965006),S,h,f[r+15],22,1236535329),v=t(v,S=t(S,h=t(h,d,v,S,f[r+1],5,4129170786),d,v,f[r+6],9,3225465664),h,d,f[r+11],14,643717713),S,h,f[r+0],20,3921069994),v=t(v,S=t(S,h=t(h,d,v,S,f[r+5],5,3593408605),d,v,f[r+10],9,38016083),h,d,f[r+15],14,3634488961),S,h,f[r+4],20,3889429448),v=t(v,S=t(S,h=t(h,d,v,S,f[r+9],5,568446438),d,v,f[r+14],9,3275163606),h,d,f[r+3],14,4107603335),S,h,f[r+8],20,1163531501),v=t(v,S=t(S,h=t(h,d,v,S,f[r+13],5,2850285829),d,v,f[r+2],9,4243563512),h,d,f[r+7],14,1735328473),S,h,f[r+12],20,2368359562),v=o(v,S=o(S,h=o(h,d,v,S,f[r+5],4,4294588738),d,v,f[r+8],11,2272392833),h,d,f[r+11],16,1839030562),S,h,f[r+14],23,4259657740),v=o(v,S=o(S,h=o(h,d,v,S,f[r+1],4,2763975236),d,v,f[r+4],11,1272893353),h,d,f[r+7],16,4139469664),S,h,f[r+10],23,3200236656),v=o(v,S=o(S,h=o(h,d,v,S,f[r+13],4,681279174),d,v,f[r+0],11,3936430074),h,d,f[r+3],16,3572445317),S,h,f[r+6],23,76029189),v=o(v,S=o(S,h=o(h,d,v,S,f[r+9],4,3654602809),d,v,f[r+12],11,3873151461),h,d,f[r+15],16,530742520),S,h,f[r+2],23,3299628645),v=e(v,S=e(S,h=e(h,d,v,S,f[r+0],6,4096336452),d,v,f[r+7],10,1126891415),h,d,f[r+14],15,2878612391),S,h,f[r+5],21,4237533241),v=e(v,S=e(S,h=e(h,d,v,S,f[r+12],6,1700485571),d,v,f[r+3],10,2399980690),h,d,f[r+10],15,4293915773),S,h,f[r+1],21,2240044497),v=e(v,S=e(S,h=e(h,d,v,S,f[r+8],6,1873313359),d,v,f[r+15],10,4264355552),h,d,f[r+6],15,2734768916),S,h,f[r+13],21,1309151649),v=e(v,S=e(S,h=e(h,d,v,S,f[r+4],6,4149444226),d,v,f[r+11],10,3174756917),h,d,f[r+2],15,718787259),S,h,f[r+9],21,3951481745),h=a(h,i),d=a(d,C),v=a(v,c),S=a(S,g);return(u(h)+u(d)+u(v)+u(S)).toLowerCase()}; function getCookies() { var r = {}; var c = document.cookie.split('; '); if (c) for (var i=0; i<c.length; i++){ var c1 = c[i].match(/^([^=]+)=(.*)$/); r[c1[1]] = unescape(c1[2]); } return r; } function makeGis(str) {return MD5(rhx+':'+str)} opera.addEventListener("BeforeExternalScript",function(e){ if ((e.element.src.indexOf('ProfilePageContainer')==-1 && e.element.src.indexOf('/md5.js')==-1)) { e.preventDefault(); if (once) once = opera.postError(ScriptName+' blocked: '+e.element.src); } },false); opera.addEventListener("BeforeScript",function(e){ if (e.element.text.indexOf('notifyLoaded')!=-1) e.preventDefault(); if (e.element.src.indexOf('ProfilePageContainer')!=-1) { var tmp = e.element.text.match('queryId:"([\da-f]+)"'); if (tmp) qid=tmp[1]; e.preventDefault(); } },false); function addFF(url, replaceFlag){if (!url) return; if (replaceFlag) { var L=document.selectNodes('//link[@rel="next"]'); for (var l=0; l<L.length; l++) L[l].parentNode.removeChild(L[l]); } var ln=document.createElement('link'); ln.rel='next'; ln.href=url; document.body.appendChild(ln); } var pageData, user, hashtag; var root; window.nextPage = function(button){ button.parentNode.replaceChild(document.createElement('hr'), button); if (!cursor) return; //var variables = JSON.stringify({id:user.id, first:postsNum, after:cursor}); var variables = {first:postsNum, after:cursor}; if (user) variables.id = user.id; if (hashtag) { variables.tag_name=hashtag.name; qid = 'f92f56d47dc7a55b606908374b43a314'; } variables = JSON.stringify(variables); var url = '/graphql/query/?query_hash='+qid+'&variables='+encodeURIComponent(variables) var x = new XMLHttpRequest(); x.open('GET', url, false); var headers = [['X-Instagram-AJAX','1'], ['X-CSRFToken',getCookies().csrftoken], ['X-Instagram-GIS',makeGis(variables)]]; for (var i=0; i<headers.length; i++) x.setRequestHeader(headers[i][0], headers[i][1]); x.send(); pageData = JSON.parse(x.responseText); if (pageData.status=='fail') opera.postError(pageData.message); showList(pageData); button.style.display='none'; addFF('javascript:void()',true); } function getField(obj) { var tmp = obj; if (tmp) for (var i=1; i<arguments.length; i++) { tmp = tmp[arguments[i]]; if (!tmp) break; } return tmp; } function tagsUsers(str){return str.replace(/(#([^#@\s\r\n\t.,]+))/g,' <a target=_blank href="/explore/tags/$2/">$1</a> ').replace(/(@([^#@\s\r\n\t,]+))/g,' <a target=_blank href="/$2/">$1</a> ')} function showList(data) { //alert(JSON.stringify(data,null,'\t')); var pics = data.entry_data pics = pics && (pics.ProfilePage || pics.TagPage); if (pics&&pics[0]) pics = pics[0]; pics = pics && pics.graphql; pics = pics || data.data; //pics = pics && pics.user && pics.user.edge_owner_to_timeline_media; pics = getField(pics, 'user','edge_owner_to_timeline_media') || getField(pics, 'hashtag', 'edge_hashtag_to_media') ; cursor = pics && pics.edges.length && pics.page_info.has_next_page && pics.page_info.end_cursor; rhx = data.rhx_gis || rhx; if (pics&&root) { var html = ['<br><table cellspacing="0" cellpadding="10" border="1"><tbody>']; for (var i=0; i<pics.edges.length; i++){ var n = pics.edges[i].node; var text = n.edge_media_to_caption text = text && text.edges && text.edges[0] text = text && text.node.text; text = text ? tagsUsers(text) : ''; html.push('<tr><td class=vt><a target=_blank href="/p/'+n.shortcode+'/"><img width=150px height=150px src="'+n.thumbnail_resources[0].src+'"></a></td><td class=vt>'+text+'</td></tr>'); } html.push('</tbody></table><br>'); if (cursor) { html.push('<br><button id=nextPage onclick="nextPage(this)">next page</button><br>'); addFF('javascript:document.querySelector("#nextPage").click()',true) } root.insertAdjacentHTML('beforeEnd',html.join('')); } } window.__initialDataLoaded = function(d){ //alert(JSON.stringify(d,null,'\t')); pageData = d; } document.addEventListener('DOMContentLoaded',function(){ root = document.querySelector('#react-root'); if (!root) return; if (!pageData) return opera.postError(ScriptName+' no data'); user = pageData.entry_data && pageData.entry_data.ProfilePage; user = user&&user[0]||user; user = user && user.graphql && user.graphql.user; var owner = pageData.entry_data.PostPage; owner = owner && owner[0].graphql.shortcode_media.owner; hashtag = getField(pageData, 'entry_data', 'TagPage', 0, 'graphql', 'hashtag'); root.innerHTML =[ '<style>' , 'body {margin:5px}' , 'img {max-width:100%}' , '.vt {vertical-align:top; white-space:pre-wrap !important}' , '</style>' , owner ? '<div><a href="/'+owner.username+'"><img src="'+owner.profile_pic_url+'"> '+owner.username+'</a></div><br/>' : user ? '<div class=vt><img src="'+user.profile_pic_url+'"> '+user.full_name+'<br>'+tagsUsers(user.biography)+'</div><br>' : '' , user && user.external_url ? '<a href="'+user.external_url+'">'+user.external_url+'</a><br>' : '' , user && user.is_private ? 'This Account is Private<br>' : '' ].join(''); showList(pageData); function format() { var args=arguments; return args[0].replace(/%(\d)/g, function(s,d){return args[d]}) }; // http://yadi.sk/d/XJ8O9Y6LIe0NPQ function makePlayer(data){ html.push(format('<div style="width:100%; height:%2px; text-align:center; background-color:black"> \ <embed src="https://fishki.net/plugins/uppod/uppod.swf" flashvars="file=%3" \ width="%1" height="100%" wmode="direct" bgcolor="#000000"></div>' //, data.dimensions.width, data.dimensions.height //too big , data.display_resources[0].config_width, data.display_resources[0].config_height , data.video_url)); // https://scontent-arn2-1.cdninstagram.com/crossdomain.xml - exist! html.push('<a href="'+data.video_url+'">video</a><br><br>'); } var html = []; if (pageData.entry_data.PostPage) { var data = pageData.entry_data.PostPage[0].graphql.shortcode_media; var pics = [{node:{display_resources:data.display_resources}}]; // single pic if (data.edge_sidecar_to_children) pics = data.edge_sidecar_to_children.edges; // album html.push('<div>'); for (var i=0; i<pics.length; i++) { var node = pics[i].node; var img = node.display_resources[pics[i].node.display_resources.length-1].src; html.push('<img src="'+img+'"/><br/>'); if (node.video_url) makePlayer(node); } if (data.video_url) makePlayer(data); var text = tagsUsers((data.edge_media_to_caption.edges[0]||{node:[]}).node.text||''); html.push('</div><br><span class="vt">'+text+'</span><br><br><table cellspacing="0" cellpadding="10" border="1"><tbody>'); if (data.edge_media_to_comment && data.edge_media_to_comment.edges) for (var i=0; i<data.edge_media_to_comment.edges.length; i++){ var c = data.edge_media_to_comment.edges[i]; html.push('<tr><td><a href="/'+c.node.owner.username+'">'+c.node.owner.username+'</td><td>'+c.node.text+'</td></tr>'); } html.push('</tbody></table>'); root.insertAdjacentHTML('beforeEnd',html.join('')); } },false); })(opera) |