Skip to content

Instantly share code, notes, and snippets.

@tokozedg
Created October 19, 2018 07:51
Show Gist options
  • Save tokozedg/844dc149d016aeb1c010d67fbd4ccbec to your computer and use it in GitHub Desktop.
Save tokozedg/844dc149d016aeb1c010d67fbd4ccbec to your computer and use it in GitHub Desktop.
Greesemonkey - Discogs with Last.fm links
// ==UserScript==
// @name Discogs with Last.fm links
// @version 0.1
// @description Link to a search from discogs pages to Last.FM
// @author Tornike
// @include http*://*discogs.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
if(window.location.href.indexOf('https://www.discogs.com') != -1)
showDiscogs();
})();
function showDiscogs()
{
var pTitle=document.getElementById('profile_title');
if(pTitle)
{
var album = pTitle.getElementsByTagName('span');
album=album[album.length-1].textContent.trim();
var span=pTitle.getElementsByTagName('a')[0].parentNode;
var artist=span.getAttribute('title').replace(/\(.*\)/g, '');
var page_aside=document.getElementById('page_aside');
var before=page_aside.firstElementChild.nextElementSibling.nextElementSibling;
var div=document.createElement('div');
div.setAttribute('class', 'section');
before.parentNode.insertBefore(div, before);
var h3=document.createElement('h3');
div.appendChild(h3);
var img=document.createElement('img');
img.src='http://icons.iconarchive.com/icons/sicons/basic-round-social/512/last.fm-icon.png';
img.style.height='1em';
h3.appendChild(img);
h3.appendChild(document.createTextNode(' Last.FM'));
var d1=document.createElement('div');
d1.setAttribute('class', 'section_content');
div.appendChild(d1);
var a=document.createElement('a');
a.href="https://www.last.fm/search/artists?q="+artist;
a.innerHTML="Search artist";
d1.appendChild(a);
d1.appendChild(document.createElement('br'));
var a=document.createElement('a');
a.href="https://www.last.fm/search/albums?q="+encodeURIComponent(artist+' '+album);
a.innerHTML = 'Search album';
d1.appendChild(a);
d1.appendChild(document.createElement('br'));
}
var artistTable=document.getElementById('artist');
if (artistTable){
var r=0;
while(row=artistTable.rows[r++]){
console.log(r);
var artist=row.getElementsByClassName('artist')[0];
if (artist){
var album=row.getElementsByClassName('title')[0].getElementsByTagName('a')[0];
console.log(album.innerText);
var skittles=row.getElementsByClassName('skittles')[0].getElementsByClassName('skittles')[0];
if (skittles){
var a=document.createElement('a');
a.href="https://www.last.fm/search/albums?q="+album.innerText;
var img=document.createElement('img');
img.src='http://icons.iconarchive.com/icons/sicons/basic-round-social/512/last.fm-icon.png';
img.style.height='1em';
a.innerHTML=img.outerHTML
console.log(skittles);
skittles.insertAdjacentHTML('beforeend', a.outerHTML);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment