Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(function() {
  var list = document.querySelector('#p-tb > div:nth-child(2) > ul:nth-child(1)');
  var entry = document.createElement("li");
  var link = document.createElement("a");

  entry.className = "mw-list-item";

  link.href = "";
  link.textContent = "Copy attribution";
  link.addEventListener("click", function(e) {
    e.preventDefault();

    var text = 'From <a href="' + location.href + '"><i>' + document.querySelector("h1#firstHeading").textContent + '</i></a> on <a href="https://en.wikipedia.org/wiki/Main_Page">Wikipedia</a>, the free encyclopedia. Text is used under the <a href="https://en.wikipedia.org/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License">Creative Commons Attribution-ShareAlike 4.0 International</a> license.';
    navigator.clipboard.writeText(text).then(
      function() {
        alert("Copied to clipboard.\n\n" + text);
      }
    );
  });

  entry.appendChild(link);
  list.appendChild(entry);
})();