Sauvegarde / Wikipedia - Table Parser

// ==UserScript==
// @name         Wikipedia - Table Parser
// @namespace    https://openuserjs.org/users/Sauvegarde
// @description  Save tracklist table content in clipboard (for music albums)
// @author       Sauvegarde
// @match        https://fr.wikipedia.org/wiki/*
// @iconURL      https://en.wikipedia.org/favicon.ico
// @grant        none
// @version      0.1
// @updateURL    https://openuserjs.org/meta/Sauvegarde/Wikipedia_-_Table_Parser.meta.js
// @downloadURL  https://openuserjs.org/install/Sauvegarde/Wikipedia_-_Table_Parser.user.js
// @copyright    2021, Sauvegarde (https://openuserjs.org/users/Sauvegarde)
// @license      MIT
// ==/UserScript==

/* jshint esversion: 6 */

(function() {
    'use strict';

	document.querySelectorAll("table.tracklist").forEach(tracklist => {
		const tracknames = [];
		for(let i = 1; i < tracklist.rows.length; ++i) {
			const cell = tracklist.rows[i].cells[1];
			if (cell) {
				tracknames.push(`${cell.innerText}`);
			}
		}
		const button = document.createElement("button");
		button.addEventListener("click", () => writeToClipboard(tracknames.join('\n')).then(() => {button.innerHTML += " 👍";}));
		button.innerHTML = "Export track names";
		tracklist.parentElement.appendChild(button);
	});

	/** Attempt to copy the text (ctrl+c) into the system clipboard. */
	function writeToClipboard(str) {
		return navigator.clipboard.writeText(str);
	}
})();