Skip to content

Instantly share code, notes, and snippets.

@0xLeon
Last active February 13, 2021 16:39
Embed
What would you like to do?
BisaChat Plus 4
// ==UserScript==
// @name BisaChat Plus
// @namespace http://projects.0xleon.com/userscripts/bcplus
// @version 4.0.0.dev1
// @description Make BisaChat Great Again
// @author Stefan Hahn
// @match https://bisachat.bisafans.de/index.php?room/*
// @grant none
// @run-at document-end
// ==/UserScript==
(function($) {
'use strict';
let lastfmConnectNowPlayingHandler = function() {
let lastfmUsername = window.localStorage.getItem('bcplus.alpha.nowPlaying.lastfmUsername');
if (!lastfmUsername) {
console.log('Last.fm Connect: Last.fm Nutzername nicht konfiguriert');
return false;
}
$.ajax({
url: 'https://ws.audioscrobbler.com/2.0/',
dataType: 'jsonp',
data: {
api_key: window.atob('NDk0Mjk2MzMxNzJlNzRkZWU2OGM3YTNlN2E2Zjc5N2U='),
format: 'json',
method: 'user.getRecentTracks',
user: lastfmUsername,
limit: 1
},
success: function(data, textStatus, jqXHR) {
if (data && data.recenttracks && data.recenttracks.track) {
if (data.recenttracks.track[0] && data.recenttracks.track[0]['@attr'] && data.recenttracks.track[0]['@attr'].nowplaying && ('true' === data.recenttracks.track[0]['@attr'].nowplaying)) {
let npData = [
data.recenttracks.track[0].artist['#text'], // artist
data.recenttracks.track[0].name, // title
data.recenttracks.track[0].album['#text'] // album
];
let message = 'hört gerade: %artist% - %title%'.replace(/(%artist%)|(%tit(?:le|el)%)|(%album%)/gi, function(m, a, b, c) {
return npData[0 * +(a !== undefined) + 1 * +(b !== undefined) + 2 * +(c !== undefined)]
});
let roomInfoMatch = /room\/(\d+)-.*?\//.exec(window.location.search)
if (roomInfoMatch === null || roomInfoMatch.length < 2) {
console.log('Last.fm Connect: Fehler beim Auslesen der roomID')
return
}
$.ajax({
url: 'index.php?ajax-proxy/&t=' + SECURITY_TOKEN,
dataType: 'json',
method: 'post',
data: {
'className': 'chat\\data\\message\\MessageAction',
'actionName': 'push',
'parameters[commandID]': 7,
'parameters[roomID]': parseInt(roomInfoMatch[1], 10),
'parameters[parameters]': JSON.stringify({
text: message
})
}
})
}
else {
console.log('Last.fm Connect: Aktuell wird nichts gescrobbelt');
}
}
else if (data && data.error) {
console.log('Last.fm Connect: Fehler - ' + data.error.toString() + ' - ' + data.message);
}
else {
console.log('Last.fm Connect: Ungültige Daten emfpangen');
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('Last.fm Connect: Fehler - ' + textStatus + ' - ' + errorThrown);
console.log(errorThrown);
}
});
};
let li = document.createElement('li');
let a = document.createElement('a');
let spanIcon = document.createElement('span');
let spanText = document.createElement('span');
a.setAttribute('class', 'button');
a.setAttribute('href', '#');
a.setAttribute('id', 'bcplus-now-playing');
spanIcon.setAttribute('class', 'icon icon16 fa-lastfm-square');
li.appendChild(a);
a.appendChild(spanIcon);
a.appendChild(document.createTextNode(' '));
a.appendChild(spanText);
spanText.appendChild(document.createTextNode('Now Playing'));
document.querySelector('#chatQuickSettingsNavigation .buttonGroup').appendChild(li);
document.addEventListener('keyup', function(event) {
if (event.key === 'y' && event.ctrlKey) {
event.preventDefault();
event.stopPropagation();
document.querySelector('#chatInputContainer textarea').focus();
lastfmConnectNowPlayingHandler();
}
}, true);
a.addEventListener('click', function(event) {
event.preventDefault();
event.stopPropagation();
document.querySelector('#chatInputContainer textarea').focus();
if (event.ctrlKey) {
let lastfmUsername = window.prompt('Gib deinen Last.fm Nutzernamen ein!');
if (!!lastfmUsername) {
window.localStorage.setItem('bcplus.alpha.nowPlaying.lastfmUsername', lastfmUsername);
}
}
else {
lastfmConnectNowPlayingHandler();
}
return false;
}, false);
})(window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment