yazdmich

Untitled

Jun 12th, 2015
407
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        http://www.okcupid.com/*
  8. // @require      http://code.jquery.com/jquery-1.10.2.js
  9. // @require    http://cdnjs.buttflare.com/ajax/libs/toastr.js/latest/js/toastr.js
  10. // @resource   toastr http://cdnjs.buttflare.com/ajax/libs/toastr.js/latest/css/toastr.css
  11. // @grant      GM_addStyle
  12. // @grant      GM_getResourceText
  13. // ==/UserScript==
  14. var newCSS = GM_getResourceText ("toastr");
  15. GM_addStyle(newCSS);
  16. toastr.options = {
  17.   "closeButton": false,
  18.   "debug": false,
  19.   "progressBar": true,
  20.   "positionClass": "toast-bottom-left",
  21.   "showDuration": "10000",
  22.   "hideDuration": "10000",
  23.   "timeOut": "10000",
  24.   "extendedTimeOut": "10000",
  25.   "showEasing": "swing",
  26.   "hideEasing": "linear",
  27.   "showMethod": "fadeIn",
  28.   "hideMethod": "fadeOut"
  29. };
  30. this.$ = this.jQuery = jQuery.noConflict(true);
  31. function httpGet(theUrl) {
  32.     console.trace();
  33.     var deferred = $.Deferred();
  34.     var xmlHttp = new XMLHttpRequest();
  35.     xmlHttp.open("GET", theUrl, true);
  36.     xmlHttp.addEventListener('load', function() {
  37.         if (xmlHttp.status === 200) {
  38.             deferred.resolve(xmlHttp.response);
  39.         } else {
  40.             deferred.reject("HTTP error: " + xmlHttp.status);
  41.         }
  42.     }, false);
  43.     xmlHttp.send(null);
  44.     return deferred.promise();
  45. }
  46. function insertTooltip(url, element) {
  47.     url = url.split('?')[0] + '?okc_api=1';
  48.     if (element.hasAttribute('profile') === false) {
  49.         element.setAttribute('profile', null);
  50.         var promise = httpGet(url);
  51.         promise.done(function(data) {
  52.             element.profile = JSON.parse(data);
  53.             var page = element.profile;
  54.             var match = page.matchpercentage;
  55.             var enemy = page.enemypercentage;
  56.             var match2 = Math.round(Math.sqrt(match * (100 - enemy)));
  57.             title = '' + match + '%, ' + enemy + '%, ' + match2 + '%';
  58.             console.log($(element).prop('src'));
  59.             var img = '<img src="'+page.thumbnail_60+'"></img>';
  60.             toastr.info(img, title);
  61.             $(element).on('mouseenter', function() {
  62.                 toastr.info(img, title);
  63.             });
  64.             $(element).on('change', function() {
  65.                 $(element).trigger('mouseenter');
  66.             });
  67.         });
  68.     }
  69. }
  70. promise = httpGet('http://www.okcupid.com/visited');
  71. promise.done(function(data) {
  72.     String.prototype.repeat = function( num )
  73.     {
  74.         return new Array( num + 1 ).join( this );
  75.     };
  76.     users = $(data).find('div.user_row_item');
  77.     $('#navigation').after($('<div id="sidebar" float="left" style="position: fixed;  background: #f3f5f9;border-radius: 3px;  padding-bottom: 5px;  padding-top: 10px; margin-left: 10px;"></div>'));
  78.     $('#sidebar').html('<center><h2>Visited</h1></center><div class="row">'+'<div class="user" style="display: inline-block; padding: 5px">user</div>'.repeat(3)+'</div>');
  79.     $('.row').after('<div class="row">'+'<div class="user" style="display: inline-block; padding: 5px">user</div>'.repeat(3)+'</div>');
  80.     grid = $('[class=user]');
  81.     $(users).each(function(index) {
  82.         $(grid[index])[0].innerHTML = $(this).find('.username')[0].innerHTML.slice(0,-5 - $(this).find('.username > a')[0].innerHTML.length) + '<img src=' + $(this).find('.user_image > img').prop('src') + 'width="60" height="60">' ;
  83.         console.log($(this).find('.name').prop('href'));
  84.         $(grid[index])[0].title = $(this).find('.name').prop('href').slice(31,-11);
  85.         $(grid[index])[0].on('mouseenter', function() {
  86.             console.log(this.children[0].href);
  87.             insertTooltip(this.children[0].href, this);
  88.         });
  89.     });
  90. });
Advertisement
Add Comment
Please, Sign In to add comment