Jump to content

User:Quarl/edit top link.js

From Wikipedia, the free encyclopedia
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.
// User:Quarl/edit_top_link.js

// requires: wikipage.js

// based on http://en.wikipedia.org/wiki/Wikipedia:WikiProject_User_scripts/Scripts/Add_Edit_Top_Link

// This will add an [edit top] link at the top of all pages except preview pages
// by User:Pile0nades

function editTopLink() {
  // if this is preview page or generated page, stop
  if (previewP || wikiPage.nsSpecialP) return;

  // get the page title
  var pageTitle = wikiPage.page;
  var editURL = wikiPage.qurl + '&action=edit&section=0';

  // create div and set innerHTML to link
  var divContainer = document.createElement("div");
  divContainer.innerHTML = '<div class="editsection" style="float:right;margin-left:5px;margin-top:3px;">[<a href="'+editURL+' title="'+pageTitle+'">edit top</a>]</div>';

  // insert divContainer into the DOM before the h1
  document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
}

addOnloadHook(editTopLink);