Wikipedia:WikiProject User scripts/Scripts/Edit Top: Difference between revisions

Content deleted Content added
Pile0nades (talk | contribs)
No edit summary
 
Pile0nades (talk | contribs)
No edit summary
Line 1:
Ever want to just change something at the top of a fairly long article, but don't feel like loading the enitre page again like the "Edit this page" link does? Well now you can do just that, using this wiki user script!
<pre><nowiki>
 
{|border="1" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse; font-size: 95%;"
!Name
!Version
!Description
!Skins
!Author
|-
|'''Edit Top'''
|1.0
|Allows you to edit just the first section of an article.
|MonoBook
|[[User:pile0nades|pile0nades]]
|}
 
==Installation instructions==
To install the script:
*Visit your user page. In the address bar, append "/monobook.js" to the end of the URL and press enter, and click "Edit this page"
*Copy/Paste the following script into the edit box, and save. The instruction say to bypass your browser cache so do that.
 
==Code==
===JavaScript===
<pre>
// This will add an [edit top] link at the top of all pages except preview pages
// by User:Pile0nades
Line 7 ⟶ 30:
function editTopLink() {
// if this is preview page or generated page, stop
if(document.getElementById("wikiPreview") || window.___location.href.indexOf("w/index.php?title=wiki/Special:") != -1) return;
 
// get the page title
Line 17 ⟶ 40:
 
// insert divContainer into the DOM before the h1
if(window.___location.href.indexOf("&action=edit") == -1)
document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
 
if(window.___location.href.indexOf("&action=edit&section=0") != -1) {
document.getElementById("wpSummary").value = "/* Intro */ ";
}
}
setTimeout("editTopLink();", 250);
 
// This code here is useful for calling multiple functions on page load
</nowiki></pre>
if(window.addEventListener) window.addEventListener("load", dothese, false);
else if(window.attachEvent) window.attachEvent("onload", dothese);
function dothese() {
// List the functions here
editTopLink(); // calls the edit top script
}
 
</pre>
 
==Usage==
[[Category:Wikipedia tools]]
Now go to any page on Wikipedia and the [edit top] link will appear at the top right. This link will load only the "zeroth" section of the article into the edit page.