Save Every Noise

Save and automatically load all the artists you have listend to on http://everynoise.com!

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Save Every Noise
// @namespace    https://github.com/JZ6
// @version      1.6
// @description  Save and automatically load all the artists you have listend to on http://everynoise.com!
// @author       JZ6
// @match        *://everynoise.com/*
// @grant        none
// ==/UserScript==


const config = {
	entry: loadSavedArtists,
	// entry: saveAllPlayedArtists,
	divUniqueKey: 'textContent',
	lsSavedArtistsKey: `playedArtists`,
	importantKeys: [
		'baseURI',
		'id',
		'innerHTML',
		'innerText',
		'outerText',
		'textContent',
		'title'
	]
}

config.entry()

function loadSavedArtists() {
	const playedArtists = loadPlayedArtists()

	const playedDivs = getAllDivs()
		.map(hookArtistClick)
		.filter(div => playedArtists.hasOwnProperty(div[config.divUniqueKey]))

	playedDivs.forEach(div => div.setAttribute("played", true))

	console.info(`Loaded ${playedDivs.length} artists!`);
}

function hookArtistClick(div) {
	if (div.scan || div.title) {
		div.onclick = () => clickedArtist(div)
		// div.addEventListener("click", () => clickedArtist(div), false)		//Disable multiple click handlers until a work around is found for logic regarding scan current class tag.
	}
	return div
}

function clickedArtist(div) {

	const uniqueID = div[config.divUniqueKey]
	const playedArtists = loadPlayedArtists()

	if (div.hasAttribute('played')) {
		div.removeAttribute('played')
		delete playedArtists[uniqueID]
		console.info(`Removed ${uniqueID}!`);
	} else {
		div.setAttribute('played', true)
		playedArtists[uniqueID] = copyObjectSubSet(div, config.importantKeys)
		console.info(`Added ${uniqueID}!`);
	}

	savePlayedArtists(playedArtists)
}

function loadPlayedArtists() {
	const savedArtistString = localStorage.getItem(config.lsSavedArtistsKey) || '{}'
	// const savedArtistString = GM.getValue(config.lsSavedArtistsKey)
	return JSON.parse(savedArtistString)
}

function savePlayedArtists(playedArtists) {
	const savedArtistString = JSON.stringify(playedArtists)
	// GM.setValue(config.lsSavedArtistsKey, savedArtistString)
	localStorage.setItem(config.lsSavedArtistsKey, savedArtistString)
}

// Manual save
function saveAllPlayedArtists() {

	const playedArtists = {}

	getAllDivs()
		.filter(div => div.hasAttribute("played") && div.title)
		.forEach(div => playedArtists[div[config.divUniqueKey]] = copyObjectSubSet(div, config.importantKeys))

	savePlayedArtists(playedArtists)

}

function getAllDivs() {
	return [...document.getElementsByTagName("div")]
}

function copyObjectSubSet(obj, keys) {
	const result = {}
	keys.forEach(key => result[key] = obj[key])
	return result
}