Created
May 16, 2016 18:09
-
-
Save robinp7720/b3ce7b2acad84e267c27d26b267ac411 to your computer and use it in GitHub Desktop.
This file contains 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
// ==UserScript== | |
// @name New Userscript | |
// @namespace https://mysunland.org | |
// @version 0.1 | |
// @description A better search of scratch! | |
// @author You | |
// @match https://scratch.mit.edu/* | |
// @require http://code.jquery.com/jquery-latest.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Create search suggestions box | |
jQuery('.search').append('<ul class="answers"></ul>'); | |
jQuery('.answers').css({ | |
background: '#219ddb', | |
margin: '0', | |
'margin-top': '-7px', | |
}); | |
jQuery('head').append('<style> .answers li a{color: white !important; padding:5px}</style>'); | |
jQuery('input[name="q"]').attr('autocomplete','off').css({'border-bottom-left-radius':'0','border-bottom-right-radius':'0'}); | |
jQuery('input[name="q"]').on('input propertychange paste', function () { | |
jQuery.ajax('https://mysunland.org/scratch/ajax/search.php', { | |
data: { | |
search: $('input[name="q"]').val() | |
}, | |
method: 'GET', | |
dataType: 'json' | |
}).done(function (data) { | |
console.log(data); | |
var count = 0; | |
var users = data['hits']['hits']; | |
var length = users.length; | |
jQuery('.answer').remove(); | |
for (var i = 0; i < length; i++) { | |
var item = users[i]['_source']; | |
if (jQuery('#' + item.username).length > 0) { | |
jQuery('#' + item.username).removeClass('old-answer'); | |
} else { | |
var html = '<li class="answer" id="' + item.username + '"><a href="https://scratch.mit.edu/users/' + item.username + '/">' + item.username + '</a></li>'; | |
jQuery('.answers').append(html); | |
} | |
} | |
}); | |
}); | |
console.log('Script loaded!'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment