SHOW:
|
|
- or go back to the newest paste.
| 1 | // ==UserScript== | |
| 2 | // @name Last.fm Slack now playing thing | |
| 3 | // @namespace http://nope/ | |
| 4 | // @version 0.1 | |
| 5 | // @description gets your last.fm now playing info and puts it in slack's chat pane | |
| 6 | // @match https://*.slack.com/messages/*/ | |
| 7 | // @copyright 2014+, nathan | |
| 8 | // ==/UserScript== | |
| 9 | ||
| 10 | ||
| 11 | /////////////////////////////////////////////////////////////// | |
| 12 | /// CHANGE THESE | |
| 13 | ||
| 14 | var username = "DFAutomaton"; | |
| 15 | var apiKey = "76546d26a61f25fb62127ad517e061d3"; | |
| 16 | ||
| 17 | /////////////////////////////////////////////////////////////// | |
| 18 | ||
| 19 | ||
| 20 | ||
| 21 | ||
| 22 | ||
| 23 | ||
| 24 | ||
| 25 | ||
| 26 | ||
| 27 | ||
| 28 | console.log('Starting LFM NP 3');
| |
| 29 | ||
| 30 | var messageInput = $('#message-input');
| |
| 31 | //var npButton = $('<a onclick="return false;" id="now_playing_button" style="line-height: 36px; padding: 0px 0.5rem; border: 2px solid rgb(224, 224, 224); text-align: center; font-size: 1.5rem; text-shadow: white 0px 1px 1px; width: 44px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0.2rem; border-top-left-radius: 0.2rem; position: absolute; bottom: 22px; left: 63px; background-clip: padding-box;"><i class="fa fa-music"></i></a>');
| |
| 32 | var npButton = $('#primary_file_button').clone().attr('id', 'now_playing_button').removeClass('file_upload_btn');
| |
| 33 | var buttonCss = {'line-height': '36px', 'padding': '0 .5rem', 'border': '2px solid #e0e0e0', 'text-align': 'center', 'font-size': '1.5rem', 'text-shadow': '0 1px 1px white', 'width': '46px', 'height': '41px', 'background-clip': 'padding-box', 'border-top-right-radius': '0', 'border-bottom-right-radius': '0', 'border-bottom-left-radius': '.2rem', 'border-top-left-radius': '.2rem', 'position': 'absolute', 'bottom': '22px', 'left': '62px','background-color': 'rgba(0, 0, 0, 0)', 'background-image': '-webkit-gradient(linear, 0% 100%, 0% 0%, from(rgb(239, 239, 239)), to(rgb(255, 255, 255)))', 'background-origin': 'padding-box', 'background-size': 'auto', 'background-attachment': 'scroll', '-webkit-background-origin': 'padding-box', '-webkit-background-size': 'auto' } ;
| |
| 34 | npButton.css(buttonCss); | |
| 35 | npButton.find('i').removeClass('fa-arrow-circle-o-up').addClass('fa-music')
| |
| 36 | ||
| 37 | var lfmApiUrl = "https://ws.audioscrobbler.com/2.0/"; | |
| 38 | ||
| 39 | ||
| 40 | var data = {method: 'user.getrecenttracks', user: username, api_key: apiKey, limit:1, format:'json'}
| |
| 41 | ||
| 42 | $('#footer #messages-input-container').css('left', '108px');
| |
| 43 | ||
| 44 | ||
| 45 | ||
| 46 | var makePost = function(name, album, artist, url, imgUrl){
| |
| 47 | return '[ *' + name + '* ] _by_ [ *' + artist + '* ] _on_ [ *' + album + '* ] - ' + imgUrl; | |
| 48 | }; | |
| 49 | ||
| 50 | var npButtonClick = function(e) {
| |
| 51 | $.get(lfmApiUrl, data, function( responseData ) {
| |
| 52 | var track = responseData.recenttracks.track; | |
| 53 | ||
| 54 | //could return an array despite the limit | |
| 55 | if(track.length) {
| |
| 56 | track = track[0]; | |
| 57 | } | |
| 58 | ||
| 59 | var album = track.album['#text']; | |
| 60 | var name = track.name; | |
| 61 | var artist = track.artist['#text'] | |
| 62 | var url = track.url; | |
| 63 | var imgUrl = track.image[2]['#text']; | |
| 64 | ||
| 65 | messageInput.val(makePost(name, album, artist, url, url)); | |
| 66 | messageInput.submit(); | |
| 67 | }); | |
| 68 | ||
| 69 | }; | |
| 70 | ||
| 71 | $( document ).ready(function(){
| |
| 72 | npButton.prependTo('#footer');
| |
| 73 | npButton.click(npButtonClick); | |
| 74 | }); |