var url_parser={ get_args: function (s) { var tmp=new Array(); s=(s.toString()).split('&'); for (var i in s) { i=s[i].split("="); tmp[(i[0])]=i[1]; } return tmp; }, get_args_cookie: function (s) { var tmp=new Array(); s=(s.toString()).split('; '); for (var i in s) { i=s[i].split("="); tmp[(i[0])]=i[1]; } return tmp; } };
oauth.vk.com/authorize?client_id=ID_&scope=_&redirect_uri=http://oauth.vk.com/blank.html&display=touch&response_type=token
www.facebook.com/dialog/oauth?client_id=ID_&scope=_&redirect_uri=http://sovgvd.info/blank.html&response_type=token
access_token=&expires_in=__
&user_id=ID_
.
var plugin_vk = { wwwref: false, plugin_perms: "friends,wall,photos,messages,wall,offline,notes", auth: function (force) { if (!window.localStorage.getItem("plugin_vk_token") || force || window.localStorage.getItem("plugin_vk_perms")!=plugin_vk.plugin_perms) { var authURL="https://oauth.vk.com/authorize?client_id=12345&scope="+this.plugin_perms+"&redirect_uri=http://oauth.vk.com/blank.html&display=touch&response_type=token"; this.wwwref = window.open(encodeURI(authURL), '_blank', 'location=no'); this.wwwref.addEventListener('loadstop', this.auth_event_url); } }, auth_event_url: function (event) { var tmp=(event.url).split("#"); if (tmp[0]=='https://oauth.vk.com/blank.html' || tmp[0]=='http://oauth.vk.com/blank.html') { plugin_vk.wwwref.close(); var tmp=url_parser.get_args(tmp[1]); window.localStorage.setItem("plugin_vk_token", tmp['access_token']); window.localStorage.setItem("plugin_vk_user_id", tmp['user_id']); window.localStorage.setItem("plugin_fb_exp", tmp['expires_in']); window.localStorage.setItem("plugin_vk_perms", plugin_vk.plugin_perms); } } };
var plugin_fb = { wwwref: false, plugin_perms: "read_stream,manage_friendlists,read_friendlists,read_mailbox,publish_actions,offline_access", auth: function (force) { if (!window.localStorage.getItem("plugin_fb_token") || force || window.localStorage.getItem("plugin_fb_perms")!=plugin_fb.plugin_perms) { var authURL="https://www.facebook.com/dialog/oauth?client_id=123456&scope="+this.plugin_perms+"&redirect_uri=http://sovgvd.info/blank.html&response_type=token"; this.wwwref = window.open(encodeURI(authURL), '_blank', 'location=no'); this.wwwref.addEventListener('loadstop', this.auth_event_url); } }, auth_event_url: function (event) { var tmp=(event.url).split("#"); if (tmp[0]=='https://sovgvd.info/blank.html' || tmp[0]=='http://sovgvd.info/blank.html') { plugin_fb.wwwref.close(); var tmp=url_parser.get_args(tmp[1]); window.localStorage.setItem("plugin_fb_token", tmp['access_token']); window.localStorage.setItem("plugin_fb_exp", tmp['expires_in']); window.localStorage.setItem("plugin_fb_perms", plugin_fb.plugin_perms); } } };
plugin_habr.wwwref.executeScript({ code: "document.cookie;" }, function(arg) { plugin_habr.auth_event_url(arg); });
var plugin_habr = { wwwref: false, auth: function (force) { if (!window.localStorage.getItem("plugin_habr_PHPSESSID") || force) { var authURL="http://habrahabr.ru/login/"; this.wwwref = window.open(encodeURI(authURL), '_blank', 'location=yes'); this.wwwref.addEventListener('loadstop', this.auth_jsinjection); } }, auth_event_url: function (url) { var tmp=url_parser.get_args_cookie(url); if (tmp['PHPSESSID'] && tmp['hsec_id']) { plugin_habr.wwwref.close(); window.localStorage.setItem("plugin_habra_PHPSESSID", tmp['PHPSESSID']); window.localStorage.setItem("plugin_habra_hsec_id", tmp['hsec_id']); } }, auth_jsinjection: function () { plugin_habr.wwwref.executeScript({ code: "document.cookie;" }, function(arg) { plugin_habr.auth_event_url(arg); }); } }
Source: https://habr.com/ru/post/181007/