Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
m Reverted edits by Shahroozmontana to last revision by Zvn (HG)
Line 48:
However it's not convenient and creates unnecessary load on the WikiMedia servers. Also, it seems like these days Wikimedia servers are configured not to give out the saved .js version right away, so you have to wait some minute after saving and then [[Wikipedia:Bypass your cache|bypassing your browser cache]].
 
=== Local HTML file ===
shahrooz (admin)
* Save Wikipedia page to your local hard drive, including all corresponding .css and .js files. Specific details depend on your browser. <!--how-to might be nice-->
* Open saved page in your editor, insert your script code either between <code>&lt;script>&lt;/script></code> tags or as a separate local file with <code>&lt;script src="file://C://you_local_path/name.js">&lt;/script></code>.
* Open saved page in your browser and preview the result.
 
This is a very traffic-wise way to quickly develop a user script. However, it has the following disadvantages:
* browser will not let you test Ajax queries from a local file
* you have to save different pages depending on what exactly page (history, etc.) is needed for testing
* you have to periodically re-save all .js files to synchronize with MediaWiki changes
* if you want to "casually" test the script while you're browsing Wikipedia, you still have to use other testing methods
 
=== Load from a localhost web server ===
Line 262 ⟶ 271:
 
2) using DOM methods: <tt>'''createElement()'''</tt>, then attach as child using <tt>'''appendChild()'''</tt> or <tt>'''insertBefore()'''</tt>. For examples of usage see the code of <tt>addPortletLink()</tt>
 
=== Removing elements ===
 
To move an element simply attach it in another place with <tt>appendChild()</tt> or <tt>insertBefore()</tt>.
 
To hide an element you can set its <code>style.display</code> to <code>none</code>:
 
<source lang="javascript">
//Example: remove copyright warning from edit page
var el = document.getElementById('editpage-copywarn');
if (el) el.style.display = 'none';
</source>
 
This is easier with [[Special:Mypage/monobook.css|your monobook.css]] though: <code style="white-space:nowrap">#editpage-copywarn {display:none}</code>
 
== Edit page ==