yazdmich

Untitled

Jan 18th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         My Fancy New Userscript
  3. // @namespace    http://www.okcupid.com/*
  4. // @version      0.1
  5. // @description  enter something useful
  6. // @author       You
  7. // @match        *://www.okcupid.com/*
  8. // @require          https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js
  9. // @grant      GM_addStyle
  10. // ==/UserScript==
  11. GM_addStyle(".spinner{-webkit-animation:rotator 1.4s linear infinite;animation:rotator 1.4s linear infinite}@-webkit-keyframes rotator{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(270deg);transform:rotate(270deg)}}@keyframes rotator{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(270deg);transform:rotate(270deg)}}.path{stroke-dasharray:187;stroke-dashoffset:0;-webkit-transform-origin:center;-ms-transform-origin:center;transform-origin:center;-webkit-animation:dash 1.4s ease-in-out infinite,colors 5.6s ease-in-out infinite;animation:dash 1.4s ease-in-out infinite,colors 5.6s ease-in-out infinite}@-webkit-keyframes colors{0%{stroke:#4285F4}25%{stroke:#DE3E35}50%{stroke:#F7C223}75%{stroke:#1B9A59}100%{stroke:#4285F4}}@keyframes colors{0%{stroke:#4285F4}25%{stroke:#DE3E35}50%{stroke:#F7C223}75%{stroke:#1B9A59}100%{stroke:#4285F4}}@-webkit-keyframes dash{0%{stroke-dashoffset:187}50%{stroke-dashoffset:46.75;-webkit-transform:rotate(135deg);transform:rotate(135deg)}100%{stroke-dashoffset:187;-webkit-transform:rotate(450deg);transform:rotate(450deg)}}@keyframes dash{0%{stroke-dashoffset:187}50%{stroke-dashoffset:46.75;-webkit-transform:rotate(135deg);transform:rotate(135deg)}100%{stroke-dashoffset:187;-webkit-transform:rotate(450deg);transform:rotate(450deg)}}#sidebar{position:fixed;background:#f3f5f9;border-radius:3px;padding:8px 5px 5px;margin-left:10px;margin-right:10px;width:295px;min-height:360px}.user{display:inline-block;padding:5px;margin-bottom:-5px;border-radius:3px}h1{font-size:larger}");
  12. var spinner = '<svg class=spinner width=65px height=65px viewBox="0 0 66 66" xmlns=http://www.w3.org/2000/svg><circle class=path fill=none stroke-width=6 stroke-linecap=round cx=33 cy=33 r=30></circle></svg>';
  13. $('#navigation').after($('<div id="sidebar" width="295" height="360">' + spinner + '</div>'));
  14. var prefix = "http:";
  15. if (location.protocol === 'https:') {
  16.     prefix = "https:";
  17. }
  18.  
  19. if (typeof $ == 'undefined') {
  20.     $ = unsafeWindow.jQuery;
  21. }
  22.  
  23. function httpGet(theUrl) {
  24.     var deferred = $.Deferred();
  25.     var xmlHttp = new XMLHttpRequest();
  26.     xmlHttp.open("GET", theUrl, true);
  27.     xmlHttp.addEventListener('load', function() {
  28.         if (xmlHttp.status === 200) {
  29.             deferred.resolve(xmlHttp.response);
  30.         } else {
  31.             deferred.reject("HTTP error: " + xmlHttp.status);
  32.         }
  33.     }, false);
  34.     xmlHttp.send(null);
  35.     return deferred.promise();
  36. }
  37.  
  38. function setMatches(elm) {
  39.     $('#matches').html($(elm).attr('data'));
  40. }
  41.  
  42. function insertMatches(url, elm) {
  43.     var me = httpGet(prefix + '//www.okcupid.com/profile?okc_api=1');
  44.     me.done(function(data) {
  45.         var profile = JSON.parse(data);
  46.         var access = profile.authcode;
  47.         url = prefix + '//www.okcupid.com/apitun/profile/' + url + '?access_token=' + access;
  48.         var promise = httpGet(url);
  49.         promise.done(function(data) {
  50.             var page = JSON.parse(data);
  51.             var match = Math.round(page.match_percentages.match / 100);
  52.             var enemy = Math.round(page.match_percentages.enemy / 100);
  53.             var match2 = Math.round(Math.sqrt(match * (100 - enemy)));
  54.             var title = '' + match + '% | ' + enemy + '% | ' + match2 + '%';
  55.             $(elm).attr('data', title);
  56.             setMatches(elm);
  57.             $(elm).mouseenter(function() {
  58.                 setMatches(elm);
  59.             });
  60.         });
  61.     });
  62. }
  63. var promise = httpGet(prefix + '//www.okcupid.com/visitors');
  64. promise.done(function(data) {
  65.     String.prototype.repeat = function(num) {
  66.         return new Array(num + 1).join(this);
  67.     };
  68.     var users = $($(data).find('.user_list'))[0].children;
  69.     var userrow = '<div class="row">' + '<div class="user"></div>'.repeat(3) + '</div>';
  70.     var userbox = '<div id="userbox"><hr><center><h1>Mouse over a user above</h1></center></div>';
  71.     $('#sidebar').html('<center><h1>Visitors</h1></center>' + userrow.repeat(3) + userbox);
  72.     var grid = $('[class=user]');
  73.     $(users).each(function(index) {
  74.         $(grid[index]).html($(this).find('.username').html().slice(0, -5 - $(this).find('.username > a').html().length) + '<img src=' + $(this).find('.user_image > img').prop('src') + ' width="85" height="85">');
  75.         $(grid[index]).attr('name', $(this).find('.name').prop('href').slice(32, -27));
  76.         $(grid[index]).mouseenter(function() {
  77.             $('#userbox > center > h1').html($(this).find('a').html() + '<br>' + $(this).attr('name') + '<br> <div id="matches"><br></div>');
  78.             insertMatches($(this).attr('name'), this);
  79.         });
  80.     });
  81. });
Advertisement
Add Comment
Please, Sign In to add comment