Wikipedia talk:WikiProject User scripts
From Wikipedia, the free encyclopedia
|
[edit] AutoAFD
The script don't capture correctly the pagename when there are accentuation on the title. Is there any way to fix it? --Giro720 00:07, 11 October 2006 (UTC)
- I think it has to do with unescape(). For some odd reason, unescaping when the title contains an accented word causes weird characters to appear. AZ t 16:04, 24 November 2006 (UTC)
[edit] Project directory
Hello. The WikiProject Council has recently updated the Wikipedia:WikiProject Council/Directory. This new directory includes a variety of categories and subcategories which will, with luck, potentially draw new members to the projects who are interested in those specific subjects. Please review the directory and make any changes to the entries for your project that you see fit. There is also a directory of portals, at User:B2T2/Portal, listing all the existing portals. Feel free to add any of them to the portals or comments section of your entries in the directory. The three columns regarding assessment, peer review, and collaboration are included in the directory for both the use of the projects themselves and for that of others. Having such departments will allow a project to more quickly and easily identify its most important articles and its articles in greatest need of improvement. If you have not already done so, please consider whether your project would benefit from having departments which deal in these matters. It is my hope that all the changes to the directory can be finished by the first of next month. Please feel free to make any changes you see fit to the entries for your project before then. If you should have any questions regarding this matter, please do not hesitate to contact me. Thank you. B2T2 14:27, 26 October 2006 (UTC)
[edit] Need a tag for WikiProject Fan Fiction
...I have no idea where else to find someone to help me out with this without going to the main Help Desk, and that's usually a pain to edit. :\ Hopefully one of you can help?
Anyway, all I need is a tag - like most WikiProjects have already - to put on the Talk pages of articles that fall within the scope of WikiProject Fan Fiction. Can anybody here help out with this? Runa27 22:51, 26 October 2006 (UTC)
- SON OF TWO STRANGERS. ARGH. >.< I TOLD that admin I was working on reinvigorating the project, and he STILL deleted it for being inactive! RIGHT after I added all those pages and started linking them to the project as the previous project runner had never done ... ARGH.
- Give me a few hours and I shall restart it. It'll be at that location, don't worry. (Of course if the original founder still was at all active and had actually gotten all the appropriate articles tagged as being under the project, I wouldn't have to go through all this, but oh well). I have to go to dinner first with the family, but afterwards I shall fix this. Runa27 22:57, 26 October 2006 (UTC)
-
- Actually you mispelled the link, which is why it is red; it still exists at Wikipedia:WikiProject Fan Fiction. As for the tag, look at existing templates like {{WPBooks}}. Create a template page, with a content similar to the following:
{| class="messagebox standard-talk" |- style="vertical-align:top;" | rowspan="3" width="50px" | [[Image:Open book 01.svg|60px]] | colspan="2" style="font-style:italic;text-align: center;" | This article is within the scope of '''[[Wikipedia:WikiProject Fan Fiction|WikiProject Fan Fiction]]'''. You can discuss the Project at its [[Wikipedia talk:WikiProject Fan Fiction|talk page]]. |}<includeonly></includeonly><noinclude> [[Category:Fan fiction|*]] </noinclude>
Take a look at Help:Template for more information AZ t 23:11, 26 October 2006 (UTC)
- I've made a template at {{WikiProject Fan Fiction}}. Tra (Talk) 23:20, 26 October 2006 (UTC)
[edit] Help!
I need help with my scripts. Currently, only navigation popups and InstaView are enabled. Howver, there are a lot more scripts, which aren't working. Please look at my monobook.js and then fix it if you can, or leave a suggestion on my talk page. Thanks in advance, ςפקιДИτς ☺ ☻ 01:17, 31 October 2006 (UTC).
- Replied on User talk:SFGiants. --ais523 15:11, 31 October 2006 (UTC)
[edit] Changes to accesskeys and tooltips
Mailing list thread. Apparently some planned changes in Mediawiki might break some user js, but I don't really understand. the wub "?!" 09:51, 6 November 2006 (UTC)
[edit] Replacing text through scripting
I have created a few scripts so that I am able to quickly assess articles of stub or start status for various Wikiprojects I am part of. My problem is that, as of right now, the only way for me to use the scripts is if there is nothing at all in the talk page besides the template in question (which my script then wipes out and replaces). Is there away to search for, say, {{WPBiography}} and replace only that with {{WPBiography|class=start|importance=low}} while keeping everything else intact? here is an example of one of my scripts:
// Code originally by [[User:Raylu|raylu]] // Modified by [[User:Moeron]] // // // This script adds a "stub,low" tab to the top of Article pages // when in edit mode. function docvg() { document.editform.wpTextbox1.value = '{{' + 'cvgproj' + '|' + 'class=stub' + '|' + 'importance=low' + '}' + '}'; document.editform.wpSummary.value = 'Assessed as stub, low importance -- [[Category:Unassessed computer and video game articles|You can help!]]'; document.editform.wpMinoredit.checked = false; document.editform.submit(); } function addcvg() { addTab("javascript:docvg()", "cvg", "ca-cvg", "cvg", ""); akeytt(); } addOnloadHook(function() { if (document.title.indexOf("Talk:") != -1) { addOnloadHook(addcvg); } });
Thanks for any help in advance. -- moe.RON Let's talk | done 22:04, 6 November 2006 (UTC)
- You could try doing something similar to this and do a regexp replace on the article. Tra (Talk) 22:44, 6 November 2006 (UTC)
-
- I am not very code literate, so, could you explain how I would use that script or point me where it is explained? -- moe.RON Let's talk | done 18:39, 15 November 2006 (UTC)
- Try something like
- I am not very code literate, so, could you explain how I would use that script or point me where it is explained? -- moe.RON Let's talk | done 18:39, 15 November 2006 (UTC)
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.split("{"+"{WPBiography}}"). join('{\ {' + 'WPBiography' + '|' + 'class=start' + '|' + 'importance=low' + '}' + '}';
var tb = document.editform.wpTextbox1; tb.value = tb.value.replace("{\ {WPBiography}}", "Some replacement text");
-
-
-
- No clue about performance, perhaps less temporary strings or optimized implementation. Performance aside, it allows you to look for more complex patterns using regexen, if necessary. If you specify the global flag ( /....../g ) then it replaces all instances.
- Please remove bugs (if any) before use. Shinobu 13:06, 21 December 2006 (UTC)
-
-
Try wiked. This in-page editor extension allows regular expression find and replace. You can also predefine find and replace texts which will be added to the drop-down history of the find and replace fields. Cacycle 16:29, 21 December 2006 (UTC)
[edit] Merge
Why merge? Wikipedia:Scripts seems to be about a wholly different sort of scripts. -- Jitse Niesen (talk) 00:47, 10 November 2006 (UTC)
- The merge tag was subsequently changed by the same user to aim at Scripts (in article space), so I removed the tag as a WikiProject/article space merge would clearly be improper and lead to chaos. --ais523 16:13, 13 November 2006 (UTC)
On a separate note, someone started Wikipedia:Monobook, changing it from a previous redirect to MediaWiki:Monobook.css. The page is in bad need of cleanup; perhaps it should be merged w/ WP:US, WP:JS, or Wikipedia:WikiProject User scripts/Tutorial? Since there is also Special:Mypage/monobook.css, I don't know if that would be the correct merge to do though. AZ t 17:25, 3 December 2006 (UTC)
- I'd support 'adopting' that page and moving it to a WikiProject subpage. --ais523 08:46, 4 December 2006 (UTC)
[edit] Arrows in edit summaries
At the moment, the software places a rightwards-pointing arrow on edit summaries generated by section edits and the contents of MediaWiki space place a leftwards-pointing arrow on autosummaries for redirecting, blanking, and replacing content (see WP:AES). Maybe it would be a good idea to have a standardised symbol on edit summaries generated by scripts and/or bots? --ais523 13:14, 4 December 2006 (UTC)
- I've been using an autoedit script, and I've been thinking about adding a link to relevant MoS or other pages everytime it changes something. A standard symbol for scripts would a) make this more uniform and b) take up less space than a full link in the summary, which may after all contain the summary of a normal edit too. Possible are e.g. ⒮⒝ⓈⒷⓢⓑ, but these are not available in all fonts. In fact two of them are showing up as squares already. The same applies to other extended Unicode symbols, so perhaps it's better to use e.g. (s) for scripts and (b) for bots. Then my script would insert, say " (s) - ² d ", if it changed a dash, a superscript and a date, the first link pointing to the script itself, or its manual. Shinobu 18:23, 20 December 2006 (UTC)
[edit] Wikipedia:WikiProject User scripts/Scripts/Formatter
Formatter is a nice small script useed by many users, but it doesn't seem to have a 'caretaker'. There are some suggestions on how to improve it on talk, but we don't have anybody to implement them - perhaps a person experienced with scripts could 'adopt' this script?-- Piotr Konieczny aka Prokonsul Piotrus | talk 21:28, 5 December 2006 (UTC)
- I had a qick look and most of this script's functionality can be found in the fix buttons of wikEd. I would be happy to add suggestions to wikEd. Cacycle 22:05, 5 December 2006 (UTC)
[edit] Assistance with bureaucrat JS
Some time ago, Voice of All wrote a nifty little bureaucrat script that helps to close RfAs. Unfortunately, over time, it's become rather overfeatured, including several features that makes the job harder, rather than easier. Additionally, several bugs have developed, causing even more problems. At this time, I'm looking for a talented coder who can either adapt the existing code (located in the history of User:Essjay/bureaucrat.js), or write new code to do this, and only this:
- Provide two tabs on RFA's: Success & Failure.
- Success should add {{subst:rfap}} at the very top of the page, and {{subst:rfab}} at the very bottom. The link at the top of the page that says something along the line of "Say something here" (it changes rather frequently) should be removed, and replaced by the word "Final." "Ending" (or whatever it says that day) should be changed to "Ended." There should be an auto-edit summary of "Closed, promoted."
- Failure should add {{subst:rfaf}} at the very top of the page, and {{subst:rfab}} at the very bottom. The link at the top of the page that says something along the line of "Say something here" (it changes rather frequently) should be removed, and replaced by the word "Final." "Ending" (or whatever it says that day) should be changed to "Ended." Auto-edit summary of "Closed, not promoted."
- Clicking either of those tabs should open up the edit view of RFA. No annoying popups, no javascript to remove the listing, paint a stunningly realistic Monet, or scratch my back, just open the edit view of RFA so I can remove the listing.
- Clicking success should open the edit view of the current "successful RFA's" page, whatever it is titled (there is a dicsussion about a change). Doesn't need to automatically add it, I can do that, just open the edit view.
- Clicking failure should open the regular view of the main "unsuccessful RFA's" page; I'll pick the right archive from there.
That's all I need it to do; I don't need it to open up Special:Makesysop, the user's talk page, add comments to the RfA's talk page, check voting records, waive flags, or launch ICBMs at Willy on Wheels. From there, I can take the rest.
Thanks to whomever can take care of this for me. Essjay (Talk) 03:19, 11 December 2006 (UTC)
- I've had a go at this; my attempt is currently in my script sandbox (User:ais523/sandbox.js). As you're requesting opening 3 pages, I've told it to open up the RfA mainpage and successful/unsuccessful RfA page in separate windows (it's not clear to me exactly what you're asking for there). Let me know what you think! --ais523 10:21, 11 December 2006 (UTC)
[edit] How do I get Javascript to automatically send me to another page?
Yeah... Pretty much the heading. I have no idea, but I'd like to. -Amarkov blahedits 02:29, 23 December 2006 (UTC)
- The key line looks like this:
location.href="http://en.wikipedia.org/wiki/whatever";
- You'll also need code to set it off at the right timing. One very simple example is in User:ais523/monobook.js; it purges my userpage whenever I visit it (search for 'location.href='). --ais523 17:06, 23 December 2006 (UTC)
- Also, for compatibility with bad browsers you should use window.location.href and in ais523's monobook there is the location.href relocating inside an addOnloadHook. If you just want to redirect someone on a certain condition, do not use addOnloadHook, because your page will have to load then redirect, which is very pointless. The only reason you should addOnloadHook a redirect is if you need the page to load before redirecting (like redirecting to one of the links on the page or something).
- Well, my opinion for you hope it helped GeorgeMoney (talk) 19:06, 23 December 2006 (UTC)
[edit] Okay, now how do I set up things to execute one after another?
The functions are executing on the page I'm currently on. How do I make it go to the other page before trying to execute the stuff? -Amarkov blahedits 01:24, 29 December 2006 (UTC)
- What? You need to give more detail on what exactly you're trying to do. What is the "other page"? Which functions are you using? They should be executing one after another in the order they appear in your monobook.js. Supadawg (talk • contribs) 04:11, 29 December 2006 (UTC)
- Okay, so my question made no sense. Sorry, I was tired. -Amarkov blahedits 17:18, 29 December 2006 (UTC)
- I'd be happy to help; just repost your question with details. Supadawg (talk • contribs) 19:28, 29 December 2006 (UTC)
- I'm trying to get something to go to another page, and then edit some of the objects there. The problem is, it tries to do the other actions before going to the page, which obviously does not work; most of the things I try to edit don't exist on the page I'm on. So how do I get it to go to the other page first? -Amarkov blahedits 21:09, 29 December 2006 (UTC)
- Assuming you're talking about the aivreport function in your monobook.js, it needs to be done in two parts.
- Do the redirect and nothing else
- Detect when you've hit the page you redirected to and do whatever action it is you want to do
- This is something like the "autoedit" trick done by Lupin's popups.js. It adds extra URL parameters to the redirect URL and then detects those parameters after the redirect has taken place. This is how it knows to substitute redirects and such. Detecting when to trigger the automated action can be done with any portion of the URL string, including custom parameters. Mike Dillon 23:09, 29 December 2006 (UTC)
- Assuming you're talking about the aivreport function in your monobook.js, it needs to be done in two parts.
- I'm trying to get something to go to another page, and then edit some of the objects there. The problem is, it tries to do the other actions before going to the page, which obviously does not work; most of the things I try to edit don't exist on the page I'm on. So how do I get it to go to the other page first? -Amarkov blahedits 21:09, 29 December 2006 (UTC)
- I'd be happy to help; just repost your question with details. Supadawg (talk • contribs) 19:28, 29 December 2006 (UTC)
- Now I need to figure out how to get variables to save across pages. Any ideas? -Amarkov blahedits 06:58, 30 December 2006 (UTC)
- There are two main methods: add parameters to the URL (as used by User:ais523/editcount.js; this method doesn't work from an edit page to the page that results after the save), or to use cookies (I've never used this technique, but I've seen scripts that do; I seem to remember there were cookies in Cacycle's wikEd script). --ais523 14:29, 30 December 2006 (UTC)
- It can be made to work with the edit form, but you need to add hidden form elements to the DOM. There may be browser specific quirks, but it works in Mozilla 1.7 and Firefox at least. Or are you referring to the server-side redirect that happens after the save is actually completed? Mike Dillon 16:28, 30 December 2006 (UTC)
- Okay, no idea how to do cookies, so I'm going to stuff the URL. It'll make it long, but oh well. -Amarkov blahedits 16:35, 30 December 2006 (UTC)
- (In reply to Mike Dillon) Yes, I was referring to the server-side redirect, which junks any user parameters in the URL. --ais523 16:38, 30 December 2006 (UTC)
- It can be made to work with the edit form, but you need to add hidden form elements to the DOM. There may be browser specific quirks, but it works in Mozilla 1.7 and Firefox at least. Or are you referring to the server-side redirect that happens after the save is actually completed? Mike Dillon 16:28, 30 December 2006 (UTC)
- There are two main methods: add parameters to the URL (as used by User:ais523/editcount.js; this method doesn't work from an edit page to the page that results after the save), or to use cookies (I've never used this technique, but I've seen scripts that do; I seem to remember there were cookies in Cacycle's wikEd script). --ais523 14:29, 30 December 2006 (UTC)
- Argh, now I don't know what's wrong. For some reason, the tab does not feel like showing up now. The code is at User:Amarkov/aiv.js if anyone wants to help. -Amarkov blahedits 17:13, 30 December 2006 (UTC)
- Have a look at User:Mike Dillon/Scripts/aiv.js. It adds the tab for me when on a "User talk" page and the makereport() function ends up executing once on the page. I'm not sure what exactly you were trying to do with makereport, so it looks like that still needs some work. I may have misunderstood what you are trying to do with this. Mike Dillon 17:40, 30 December 2006 (UTC)
- I see what you're trying to do. Let me see if I can get it to work. Mike Dillon 17:44, 30 December 2006 (UTC)
- Have a look at User:Mike Dillon/Scripts/aiv.js. It adds the tab for me when on a "User talk" page and the makereport() function ends up executing once on the page. I'm not sure what exactly you were trying to do with makereport, so it looks like that still needs some work. I may have misunderstood what you are trying to do with this. Mike Dillon 17:40, 30 December 2006 (UTC)
- Okay, so my question made no sense. Sorry, I was tired. -Amarkov blahedits 17:18, 29 December 2006 (UTC)
-
-
-
- OK. Check it out now. I believe it does what you want. I also made it so that you can type whatever you want into the "Reason?" prompt. Mike Dillon 17:49, 30 December 2006 (UTC)
-
-
-
-
- Cool. I made a change after you copied it to allow you to choose whether it opens in a new window or not. Mike Dillon 18:10, 30 December 2006 (UTC)
-
[edit] Wikipedia Day Awards
Hello, all. It was initially my hope to try to have this done as part of Esperanza's proposal for an appreciation week to end on Wikipedia Day, January 15. However, several people have once again proposed the entirety of Esperanza for deletion, so that might not work. It was the intention of the Appreciation Week proposal to set aside a given time when the various individuals who have made significant, valuable contributions to the encyclopedia would be recognized and honored. I believe that, with some effort, this could still be done. My proposal is to, with luck, try to organize the various WikiProjects and other entities of wikipedia to take part in a larger celebrartion of its contributors to take place in January, probably beginning January 15, 2007. I have created yet another new subpage for myself (a weakness of mine, I'm afraid) at User talk:Badbilltucker/Appreciation Week where I would greatly appreciate any indications from the members of this project as to whether and how they might be willing and/or able to assist in recognizing the contributions of our editors. Thank you for your attention. Badbilltucker 19:36, 30 December 2006 (UTC)
[edit] Proposal
Where is the appropriate place to add the script below?
addOnloadHook(addnav) function addnav() { var tb = document.getElementById('p-navigation').getElementsByTagName('ul')[0]; addlilink(tb, '/wiki/Special:Newpages', 'New pages', 'n-newpages', 'Special:Newpages', ''); } function addlilink(tabs, url, name, id, title, key){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); tabs.appendChild(li); if(id) { if(key && title) { ta[id] = [key, title]; } else if(key) { ta[id] = [key, '']; } else if(title) { ta[id] = ['', title]; } } // re-render the title and accesskeys from existing code in wikibits.js akeytt(); return li; }
It adds a "Newpages" link in the navigation sidebar. John Reaves 03:01, 5 January 2007 (UTC)
- I'm not sure what you're asking exactly. Are you trying to add this for everyone, or just publicize the code? If the former, it should be discussed at Wikipedia:Village pump (technical) first and then proposed at MediaWiki talk:Common.js. I personally don't think it should be added site-wide. If you're trying to publicize it, it should be added to Wikipedia:WikiProject User scripts/Scripts. You can either add it yourself (with the
addlilink
dependency called out but not included), or propose it at Wikipedia talk:WikiProject User scripts/Scripts. Mike Dillon 17:13, 6 January 2007 (UTC)- I'm just trying to publicize it. I'll post it at the talk page. John Reaves 05:16, 7 January 2007 (UTC)
[edit] Math in Javascript?
Heading is pretty obvious; how do I do it? -Amarkov blahedits 16:13, 6 January 2007 (UTC)
- This page is a pretty good reference: JavaScript tutorial - Operators. It's generally pretty transparent, depending on what you're going for. Mike Dillon 17:16, 6 January 2007 (UTC)
There are a number of ways to do these things. Some may be browser specific.
String to number:
var num; var str = "1"; num = +str; num = str * 1; num = new Number(str);
Number to string:
var str; var num = 1; str = "" + num; str = new String(num);
One of those should work. Mike Dillon 21:32, 6 January 2007 (UTC)
- Okay, I think that works fine. The problem I have must be with extracting the number from the edit window. Saving the page seems to add a return character, which I suspect is throwing it off, but I do not know how to fix that. -Amarkov blahedits 21:45, 6 January 2007 (UTC)
- You can trim the string by calling
str = str.replace(/^\s+|\s+$/, "")
. However, I think your problem is that you don't have an ampersand in front of your "fakeparam". Mike Dillon 21:50, 6 January 2007 (UTC)- There was a dropped ampersand in a later function, but that shouldn't have affected it, I don't think. -Amarkov blahedits 21:52, 6 January 2007 (UTC)
- Yeah, it was in "movepage()". The replace code above will remove a trailing newline, but I tested converting "1\n" into a number without trimming and had no problems. Mike Dillon 21:54, 6 January 2007 (UTC)
- There was a dropped ampersand in a later function, but that shouldn't have affected it, I don't think. -Amarkov blahedits 21:52, 6 January 2007 (UTC)
- There's still a problem. Argh. -Amarkov blahedits 22:13, 6 January 2007 (UTC)
- Are you talking about
getarchivenumber()
in your monobook.js? What do you expect it to do? Changing location.href after clicking the submit on the edit form won't work. Mike Dillon 22:23, 6 January 2007 (UTC)- I expect it to submit the form and then change pages. That may not work correctly, but the problem is that it doesn't even get that far. It stops before executing the first line; actually, just loading the page, running the javascript or not, freezes it. -Amarkov blahedits 22:31, 6 January 2007 (UTC)
- Are you talking about
- You can trim the string by calling
So it looks like this is what you're trying to do:
- Get the current archive number from User:Amarkov/archivenumber
- Increment the archive number by one and update User:Amarkov/archivenumber
- Move User talk:Amarkov to User talk:Amarkov/Archive $N where "$N" is the new archive number
- Replace the contents of User talk:Amarkov with some boilerplate text
I'm pretty sure you can't do this. The main problems are that it is not possible to control the URL that is redirected to after you save the new archive number, or the URL you end up at after the page move. It would be possible to do this using AJAX, but I don't know if any reusable code for dealing with the edit box or page move using AJAX. Writing this code yourself is beyond your abilities in this area, as I'm sure you know. It's also possible that this could be done with some sophisticated cookie handling code to maintain the state between steps, but that's also quite difficult for an inexperienced programmer. Mike Dillon 02:13, 7 January 2007 (UTC)
- Oh, I see what you mean. I guess I can deal with manual archiving. -Amarkov blahedits 02:15, 7 January 2007 (UTC)
- P.S. Why not try something like Werdnabot? I know it doesn't use the same mechanism for archiving (i.e. it transfers comments instead of moving the page), but it does its job quite well. Mike Dillon 02:15, 7 January 2007 (UTC)
So, I remembered that Quarl had some AJAX based editing code at User:Quarl/wikiedit.js. I've never used it, though, so I can't give any advice on how to accomplish what you're trying to do. I believe it would work, though. Mike Dillon 02:36, 7 January 2007 (UTC)
[edit] Calling akeytt()
The akeytt()
function is generally one of the slowest parts of the page load when called with no arguments (taking about 20-50% of the JavaScript execution time from what I've seen). I've noticed that a lot of the functions at Wikipedia:WikiProject User scripts/Scripts call akeytt()
after any call to addlilink()
. Since these things are generally being done in a function passed to addOnloadHook()
, this is totally unnecessary, since runOnloadHook()
calls akeytt()
itself.
The only time that akeytt()
should be called is for things that execute after runOnloadHook()
and in those cases it should only be called if a new link that actually has an id is added to the page. If it is called in those cases, it should pass the id to the function instead of calling it with no arguments to allow the function to avoid reinitializing access keys for all of the other links in the ta[]
array. I have changed Wikipedia:WikiProject User scripts/Scripts/Add LI link to only call akeytt()
if the link being added has an id and I changed it to pass that id to the function instead of calling it without any arguments. Mike Dillon 20:15, 6 January 2007 (UTC)
- Unfortunately,
runOnloadHook()
callsakeytt()
before calling any custom hooks, so generally user scripts will need to callakeytt()
themselves. Also, you modified version probably doesn't currently work, sinceakeytt(id)
is broken in the version of wikibits.js currently used on Wikipedia. I just committed a fix for that, but it isn't live yet, and won't be until someone syncs the servers, which may take a few days or, possibly, weeks. —Ilmari Karonen (talk) 23:21, 12 January 2007 (UTC)
-
- D'oh. Mike Dillon 15:48, 14 January 2007 (UTC)
- Anyway, I just also committed a new
addPortletLink()
function to wikibits.js, which should more or less replaceaddLink()
,addlilink()
andaddTab()
. In particular, once it goes live, addLink could be replaced with the following code:
function addLink(where, url, name, id, title, key, after) { if (after && !after.cloneNode) after = document.getElementById(after); return addPortletLink(where, url, name, id, title, key, after); }
- and Add tab with:
function addTab(url, name, id, title, key) { return addPortletLink('p-cactions', url, name, id, title, key); }
- Most direct uses of Add LI link can also be replaced, but there could be some odd cases where the first argument is something other than the first UL inside an element with a known id. —Ilmari Karonen (talk) 01:31, 13 January 2007 (UTC)
-
- ...aaand it's live. —Ilmari Karonen (talk) 15:44, 14 January 2007 (UTC)
-
-
- ...and I've now updated most of the scripts on WP:JS that used to depend on one of these modules to use the new function instead. —Ilmari Karonen (talk) 18:59, 14 January 2007 (UTC)
-
- By the way, the new code for Add LI link is also a pretty good example of how to add accesskeys without using
akeytt()
. Basically, you set the "title" and "accesskey" attributes for the element yourself, making sure the title ends with the accesskey in square brackets, and then callupdateTooltipAccessKeys([ element ])
which just changes the title to include the browser-specific accesskey prefix (such as "ctrl-alt-") between the brackets. For changing the accesskey of an existing link, just change the "accesskey" attribute yourself and callupdateTooltipAccessKeys([ element ])
, which will change the title accordingly. —Ilmari Karonen (talk) 19:15, 14 January 2007 (UTC)
[edit] Why is my toolbox item doubled?
Howdy! I have been programming since we punched holes in paper, but I only took up JavaScript this year. I don't know where to ask JS questions, so I'm starting here. I have written two scripts:
- User:Barticus88/dpl.js, which adds selection mode buttons to the toolbox on What links here pages (used by disambiguation)
- User:Barticus88/edit_section_zero.js, which adds an edit section zero button to "edit this page" (used by everybody)
Both scripts work perfectly, individually. However, no matter which way I arrange User:Barticus88/monobook.js, the "Mode: DPL T P R W U" line appears in the Toolbox either twice or not at all. Currently I have edit_zero last so it shows up twice. I don't see how one impacts the other. They're fiddling totally unrelated parts of the page. Both use addOnloadHook, but there are scripts that use addOnloadHook several times. -- Randall Bart 09:16, 10 January 2007 (UTC)
- There's an error in the section-zero script; document.getElementById(something that doesn't exist).length is an error. You want to check if the button is
null
, rather than for having a zero length. I'm not sure whether its that error that's causing the doubling, but errors are a common cause of doubling. (You can find out about the error by double-clicking the 'warning' icon in the bottom-left corner of the screen in Internet Explorer, by typing 'javascript:' in the URL bar in Netscape, and I don't own a copy of FireFox but I'm sure it has an even better way of reporting JavaScript errors.) --ais523 09:22, 10 January 2007 (UTC)
Thanx. I sussed that myself a few minutes ago, after I realized how my edit zero was mangling other special pages. It worked fine when it found ca-edit, but when it didn't.... I saw that pattern and zeroed in on the problem. Well thanx for the quick response. So what do you think of my edit zero script? It's crude (it depends on the exact number of letters in "edit this page"), but I just started JavaScript, and I never did XML in any language. You have to admit it's a tight piece of code.
I have been hanging out at Wikipedia:WikiProject Disambiguation, but I'm going to start hanging out here. I've been programming since I had to dial the phone myself and hand it to the computer, but I am currently unemployed. I think I have a more profitable future as a JavaScripter than a disambiguator. -- Randall Bart 10:42, 10 January 2007 (UTC)
- Your code seems to make it impossible to edit the entire page without hacking the URL; sometimes, a full-page edit is desirable, so I wouldn't use that script personally. If you're interested in writing User Scripts, it's probably worth pointing out that some of the documentation in this WikiProject is out of date; things like 'Get tidy title' are no longer useful because there are now variables provided automatically on each page (view the HTML source of any Wikipedia page for details). --ais523 10:55, 10 January 2007 (UTC)
Look more closely; there's a += not an =. My script piggybacks a second option on the same tab (two <a>s in one <li>). Variables: You mean the stuff following *<![CDATA[* is there for me to use? Thanx for pointing me there before I started chiseling those pieces from the url. Using the right variables improves portability. I shall rebuild this script using those variables, and add some bells and whistles. Actually just adding two whistles and retooling one bell. -- Randall Bart 22:14, 10 January 2007 (UTC) I am puzzled by wgArticlePath = "/wiki/$1". Shouldn't it be "/wiki"? How do I use this to build a URL? -- Randall Bart 22:49, 10 January 2007 (UTC)
OMG! Why did you tell me to turn on the JavaScript console? Every page on the entire Internet gets JS errors. Every page at WP gets "Unknown property 'column-count'", many get "Error in parsing value for property 'color'" or "Error in parsing value for property 'border-style'", and things like that. Doesn't anyone check for errors? -- Randall Bart 22:13, 12 January 2007 (UTC)
- Those are probably browser incompatibilities. They don't hurt anything, as they're just CSS. Nothing bad will happen with the console on. Supadawg (talk • contribs) 23:22, 12 January 2007 (UTC)
Anyway, returning to the original topic, the reason the added toolbox entries are doubled is because of a minor bug in wikibits.js which makes the hooks run twice if the execution of runOnloadHook()
terminates abnormally because of an error. I've committed a fix for that, which should appear on Wikipedia any day now. —Ilmari Karonen (talk) 01:35, 13 January 2007 (UTC)
I usually use Firefox, where "Javascript:" brings up the Javascript Console, but I was concerned whether IE was getting the same errors. I tried to follow the instruction to click the "'warning' icon in the bottom-left corner of the screen in Internet Explorer", but there was no 'warning' icon in the bottom-left corner of the screen in Internet Explorer. It turn out it's turned off in IE 7,and you have to go to Tools->Internet Options->Advanced and turn off "Disable script debugging".— Randall Bart 03:49, 22 January 2007 (UTC)
Actually, I also had to check "Display a notifications for every script error", which then brought up an alert for thenext erro, and then I unchecked the box in that alet box. Until I did that I didn't get an error button in the corner of the IE window. BTW this is IE 7.— Randall Bart 06:28, 22 January 2007 (UTC)
[edit] Template talk:Navpop
There's a protected edit request that you guys may be interested in -- I don't know my way even half around javascript, unfortunately, so any input would be appreciated. Luna Santin 21:54, 19 January 2007 (UTC)
[edit] Automatically un/choosing watch
I have a couple of scripts in my monobook that I want to alter so that "watch this page" is automatically checked, or unchecked, depending on what I'm doing to the article. Basically I just need to add something along the lines of f.wpMinoredit.checked = false;
for minor edits, but for watching articles instead. Thanks. --... discospinster talk 16:10, 24 January 2007 (UTC)
- You probably want to manipulate f.wpWatchThis.checked. --ais523 16:17, 24 January 2007 (UTC)
- Thanks, that did the trick. ... discospinster talk 16:41, 24 January 2007 (UTC)
[edit] My script is broken :(
I'm returning from an extended Wikibreak, only to find that my monobook.js is no longer working. Does anyone have a guess as to why? --Ryan Delaney talk 15:12, 30 January 2007 (UTC)
- You need to update your copy of addEditSection0. Mike Dillon 15:52, 30 January 2007 (UTC)
[edit] I find this useful:
If scripts arent working: Do a hard refresh, clear the cookies having to do with Wikipedia, restart the computer, then log back in and do another hard refresh. --Darkest Hour • ¿? 20:39, 7 February 2007 (UTC)
[edit] Cross-referece categories
Is there a tool or script out there in Wikiland that allows a user to cross reference categories? Say I wanted to find Christians in Alabama (which is a bit redundant ;-)), I could input Category:Christian Wikipedians and Category:Wikipedians in Alabama, and the tool/script/whatever would spit out a list of users who are found in both cats. I'm not even sure if such a thing is possible, but I've been curious and I couldn't find a place to ask this; I hope I've come to the right place. - auburnpilot talk 10:26, 19 February 2007 (UTC)
- I think this is beyond what user scripts can manage, and even if it wasn't, it would cause huge server load for large categories. There have been discussions on the wikitech-l mailing list about this, and so it's possible that it will be implemented in the software eventually. Hope that helps! --ais523 10:44, 19 February 2007 (UTC)
- Also see Wikipedia:Category intersection. -- Jitse Niesen (talk) 00:31, 20 February 2007 (UTC)
[edit] Template talk:Js
Another {{editprotected}} request that members of this project will know more about than I do. ;) – Luna Santin (talk) 22:27, 21 February 2007 (UTC)
- Seems fine to me as long as the page title doesn't have any apostrophes in it. That should be a reasonable assumption for pages containing JavaScript code. Also, the current version of {{js}} also has a problem with apostrophes so this isn't a new issue. Mike Dillon 02:25, 23 February 2007 (UTC)
[edit] monobook.js modification
Can anyone tell me how to add a link to an edit count tool (User Interiot/Tool2.js) in the top menu (the one with your userpage, talk page, etc) without confusing me, as I may know how to operate a computer, but I know nothing about JavaScript. ~Steptrip 02:22, 23 February 2007 (UTC)
- Don't know if this will confuse you, but I told someone how to do this a few weeks back at Wikipedia:Village pump (technical). Here is the link. Let me know if you have any questions about modifying that example for your own purposes. Mike Dillon 02:29, 23 February 2007 (UTC)
- I'll copy a version of Mike Dillon's script, modified to link to Interiot's Tool2 script page, here:
// Add a link to User:Interiot/Tool2.js to the p-personal bar. addOnloadHook(function () { addPortletLink('p-personal', wgArticlePath.replace(/\$1/, 'User:Interiot/Tool2.js'), 'Tool2', 'pt-tool2', 'Tool2', null, document.getElementById('pt-preferences')); });
-
- You can copy and paste this code into your monobook.js, your personal scripts file. --ais523 12:51, 23 February 2007 (UTC)
Here you go:
// Add a link to User:Interiot/Tool2.js to the p-tb bar. addOnloadHook(function () { var after = document.getElementById('t-emailuser'); if (!after) after = document.getElementById('t-upload'); addPortletLink('p-tb', wgArticlePath.replace(/\$1/, 'User:Interiot/Tool2.js'), 'Tool2', 't-tool2', 'Tool2', null, after); });
It will go before "E-Mail this User" if it is there, otherwise before "Upload file". It's not entirely clear what you want, but this should be close. Mike Dillon 23:35, 11 March 2007 (UTC)
Thanks, and that's *almost* it, you've got it in the right place. What I'm really wondering is if it can only show up when I'm on a userpage (like how Contributions only shows up then) and will automatically link to ?username=WHATEVER when clicked. ^demon[omg plz] 22:39, 12 March 2007 (UTC)
This should do it:
// Add a link to User:Interiot/Tool2.js to the p-tb bar. addOnloadHook(function () { // Skip non-user pages if (!/^User/.test(wgCanonicalNamespace)) return; // Skip user subpages if (wgTitle.indexOf("/") != -1) return; var url = wgArticlePath.replace(/\$1/, 'User:Interiot/Tool2/code.js'); url += "?username=" + encodeURIComponent(wgTitle); addPortletLink('p-tb', url, 'User edit count', 't-editcount', "View this user's edit count using Interiot's Tool2", null, document.getElementById('t-emailuser')); });
It should show up on the same pages as "User contributions". Mike Dillon 00:39, 13 March 2007 (UTC)
- This isn't exactly true. It won't actually show up on the "User contributions" page itself. I have some code at User:Mike Dillon/Scripts/aiv.js that does that as well, but it isn't nicely packaged into a function. Mike Dillon 00:47, 13 March 2007 (UTC)
- I packaged up the code for getting the username associated with the current page at User:Mike Dillon/Scripts/username.js. Mike Dillon 02:17, 13 March 2007 (UTC)
[edit] My scripts
I've got some scripts I think are useful in User:Random832/monobook.js can someone comment on which ones should be split off to be reusable by others? --Random832 17:31, 1 March 2007 (UTC)
- P.S. I also think it might be useful for examples of how to avoid polluting the global variable/function namespace - my js creates no functions or variables, everything's locally scoped. --Random832 17:35, 1 March 2007 (UTC)
- Personally I don't think there are many people willing to look at the code and try to figure out what it does and then it turns out it's something they've seen already. If you separated your scripts and provided some documentation, that would be a different story. — Alex Smotrov 21:55, 8 March 2007 (UTC)
- Some people write
- Personally I don't think there are many people willing to look at the code and try to figure out what it does and then it turns out it's something they've seen already. If you separated your scripts and provided some documentation, that would be a different story. — Alex Smotrov 21:55, 8 March 2007 (UTC)
addOnloadHook(function() { });
-
-
- Some people write
-
function foo() { }; addOnloadHook(foo);
-
-
- I write
-
addOnloadHook(function() { /* foo */ });
-
-
- I agree with Alex. You have to tell me what these functions do. — Randall Bart 22:31, 16 March 2007 (UTC)
- Now that I scroll down I see you do identify your functions, just not the first two.
- Fix fact template — Looks like a winner, as is, and might be genericized also.
- "Magically link soft redirects" has a risk of looping, but I assume the five second delay fives one a chance to stop it. If publicized it should contain a warning to that effect.
- Add a "purge" tab — I may use this myself, but what is ta[], and why do you check whether getElementById exists?
- Add UTC timestamp — What is this for?
- Move the "watch" and "move" tabs to the toolbox — This should be genericized and then genericized again. We need a function to move any item from tabs to toolbox, then another to move the other way, then those two should be wrappers for a function that move an item from one portlet to another.
- And pageIsDiscussion and pageParams are global variables. — Randall Bart 23:29, 16 March 2007 (UTC)
-
[edit] Scripts broke Internet Explorer
I've been fooling around with my monobook.js and metadata.js pages, trying to get both popups and the new assessment script to work together, and now, all of the sudden, it won't let me load Wikipedia in Internet Explorer. After a second or two (after I click a link or type it in the address bar), an error message pops up saying "Internet Explorer cannot open Internet site http://en.wikipedia.org/Main_page" or whatever page I try to go to. This only happens for wikipedia. All other websites work fine, and I can work on Wikipedia just fine in Mozilla. I tried blanking my monobook but it didnt help. Has anyone seen anything like this before/can anyone help me? -RunningOnBrains 05:16, 2 March 2007 (UTC)
- This happened to me once; I fixed it by booting up an ancient version of Mozilla and reverting my monobook.js, then loading IE, navigating to Wikipedia, and pressing Control-F5. --ais523 11:14, 2 March 2007 (UTC)
[edit] A new guide
I created a small guide on writing User Scripts for User Scripts WikiProject in another language Wikipedia, then translated it to English as well. Link: Guide
I suggest we put it as a Tutorial how to write scripts and the current /Tutorial will only tell how to use scripts. Or there are many other possible options. Please let me know what you think. . — Alex Smotrov 21:54, 8 March 2007 (UTC)
- Nice work. That looks like a really good start. I think it's good enough to move into a subpage of Wikipedia:WikiProject User scripts. Maybe /Guide or /Developers' guide. Mike Dillon 01:03, 13 March 2007 (UTC)
[edit] User:Dev920/Monobook.js
I added easy db to my Monobook, but it seems to have nominated it at CSD. Can somebody fix this? Dev920 (Have a nice day!) 18:11, 14 March 2007 (UTC)
- Enclose the script with this:
//<pre><nowiki>
... script goes here ...
//</nowiki>
</pre>
- ... discospinster talk 18:46, 14 March 2007 (UTC)
-
- I left a note on Dev920's talk page, but I believe the monobook.js page should always be a lowercase m. auburnpilot talk 19:06, 14 March 2007 (UTC)
- Ah, it works. Bless you all. Dev920 (Have a nice day!) 19:17, 14 March 2007 (UTC)
- I left a note on Dev920's talk page, but I believe the monobook.js page should always be a lowercase m. auburnpilot talk 19:06, 14 March 2007 (UTC)
As far as I know, you do NOT need <pre>
on .js and .css pages. — Alex Smotrov 19:41, 14 March 2007 (UTC)
- You do sometimes, but not other times. I haven't figured out when you need it and when you don't; it seems to be somewhat inconsistent. --ais523 08:57, 16 March 2007 (UTC)
-
- When I first go to a foo.js page, it's like the page starts <code><pre>, but once I edit it, it's normal. I have sections in User:Barticus88/WhatLinksHere.js, but the first time of the day I look at it, I need to edit the whole thing, then save it. Even though there are no changes and it doesn't show in the history, this act makes the page format normal. — Randall Bart 23:35, 1 April 2007 (UTC)
[edit] UTC clock and purge
Ok, I've been using the UTC clock and purge function from User:Voice of All/UsefulJS for sometime now, but as Daylight Saving Time has come around, the clock is now 1 hours fast. Is there any way to alter the coding (whether in my monobook or elsewhere) so that the clock will be accurate again? I left a message for Voice of All but haven't received a response, so I'm hoping somebody here knows how it can be adjusted. The basic script can be found here. auburnpilot talk 22:55, 15 March 2007 (UTC)
- The clock uses the system time on your computer so, assuming you're using Windows, double click on the clock on the taskbar, check the time and date is set correctly; go to the Time Zone tab and make sure that the time zone and daylight savings settings are set correctly. Also make sure that you have installed all of the automatic updates so that the computer knows when to calculate daylight savings. Tra (Talk) 23:20, 15 March 2007 (UTC)
- Yeah, the time and all is correct. With the US switching to DST 3 weeks early this year, it seems to have screwed things up....thanks though. auburnpilot talk 23:26, 15 March 2007 (UTC)
In case anybody else has seen this issue, I worked around it by switching back to standard time and then pushing my time zone forward one (CST to EST in this case). By doing this, the UTC Clock works perfectly. auburnpilot talk 03:10, 17 March 2007 (UTC)
- You may need to patch your operating system or browser. For me (using Linux and SeaMonkey 1.0), the UTC code work just fine. Mike Dillon 03:41, 17 March 2007 (UTC)
[edit] New messages woe
Instead of the bright orange box displaying you have new messages, is there a way I can have the background of the "my talk" link to flash yellow?
- the one between the userspace & my preferences links - -- Darkest Hour 16:11, 20 March 2007 (UTC)
- No, unfortunately their is not, if you see the banner informing you that you have new messages then once you click it and go to another page afterwards (hopefulyl after reading it!) then it will go away but that is the only way it can appear. Hope this helps!! Tellyaddict 16:18, 20 March 2007 (UTC)
- Its almost certain possible, but you'd have to write a monospace.js hack to do it. —Dark•Shikari[T] 16:21, 20 March 2007 (UTC)
-
- I know that but I am wondering how i woud code it. If I could find the location of the messagebar and something having to do with the links up top I might possibly be able to do it. Right now I have a css "hack" that supresses it. See: here. -- Darkest Hour 16:32, 20 March 2007 (UTC)
- You might want to put a request in at Wikipedia:WikiProject user scripts for someone to write a script like that. --ais523 16:34, 20 March 2007 (UTC)
- I know that but I am wondering how i woud code it. If I could find the location of the messagebar and something having to do with the links up top I might possibly be able to do it. Right now I have a css "hack" that supresses it. See: here. -- Darkest Hour 16:32, 20 March 2007 (UTC)
-
-
- Assuming the box has a unique ID, it wouldn't be too much of a big deal to use:
-
position:absolute; width:50%; right:0px; background:yellow; color:yellow; z-index:1; height:1em; overflow: -- whatever the "cut it off" attribute is, I forget --
- Give this a try:
function checkMsgs() { var divs = document.getElementById('bodyContent').getElementsByTagName('div'); if(divs.length <= 2) return; for(var i=0;i<divs.length;i++) { if(divs[i].className == 'usermessage') { divs[i].style.display = 'none'; var talk = document.getElementById('pt-mytalk').firstChild; talk.style.color='#ffff00'; talk.style.textDecoration='blink'; talk.style.background='#ffff00 url(http://upload.wikimedia.org/wikipedia/commons/9/96/New_%28animated%29.gif) no-repeat 0 0'; talk.style.paddingLeft='32px'; } } } addOnloadHook(checkMsgs)
- Note that most browsers don't support { text-decoration:blink; }, so I added a small animated gif and bright yellow background color for a demonstration. --Splarka (rant) 07:36, 21 March 2007 (UTC)
[edit] More
How do I get a portlet that adds what links here to the top of the page so I don't have to go all the way to the link itself. Because right now I have most of my editing functions located around the portlets. I know this works pretty well, but cannot get it in a portlet:
what links here
-- Darkest Hour 22:04, 20 March 2007 (UTC)
- If you mean an action button (a "portlet" is anything in the UI, including the action buttons, personal toolbar, nav links, search, logo, toolbox, and 'in other languages'), try this thing below. It cheats by grabbing the href of the existing whatlinkshere (if it exists). --Splarka (rant) 08:12, 21 March 2007 (UTC)
function WLHaction() { if(document.getElementById('t-whatlinkshere')) addPortletLink('p-cactions', document.getElementById('t-whatlinkshere').firstChild.href,'What links here','ca-whatlinkshere'); } addOnloadHook(WLHaction);
[edit] April Fool's gag
Presented as a sample of JavaScript code (and social engineering), and as a gag you can play on a friend, but not as an April Fool's gag on Wikipedia (because I got slapped last night), my "game" Sisyphus: User:Barticus88/Sisyphus. It's the first serious js I have written from scratch. It loops using setTimeout, which makes it quite efficient. Other things will continue running with rather small degradation.
I am mystified at why setTimeout('sisyLoop(Sisyphus)',eval(mtimer));
works. It seems to me that Sisyphus is a local variable, which doesn't exist anymore when sisyLoop is actually called. OTOH, when I passed a variable holding a simple numeric value, that blew up because it didn't exist. Isn't that numeric value an object of type Math? Why can't I pass it like other objects? But really, why can I pass Sisyphus outside the environment of, and past the lifetime of sisyFunc? — Randall Bart 00:17, 2 April 2007 (UTC)
- It isn't a local variable, because you didn't use
var Sisyphus
. Every variable in JavaScript is a global unless it is a function parameter or scoped with var. Mike Dillon 02:34, 2 April 2007 (UTC)
I essentially stopped using var and new, because nothing ever fails when I leave them out, and things fail when I leave them in. One would think they new and var create things (they do that in other languages), but things are created without them. The effect of new and var is not to create things but to destroy things (when an environment is exited).
But why couldn't I do setTimeout('sisyLoop(Sisyphus,dd)',1000);
? Sisyphus and dd were created in that same function, both without var. I hate to ask, but do capitals have an effect? JavaScript has a surprising number of similarities to Axon C4. One of the stranger features of C4 is that variable scoping is determined by whether the first letter is capitalized. I am quite sure I haven't read such a rule for JavaScript, but somehow it wouldn't surprise me. — Randall Bart 04:02, 2 April 2007 (UTC)
- Capitalization has no effect, except that variable names are case sensitive. Variables are not treated differently because of their name. As for your issue with "dd", you're not really giving enough information to see what the problem is. That being said, I don't really care to look at this much more unless it is to help you write scripts that are actually useful in building an encyclopedia. Mike Dillon 04:13, 2 April 2007 (UTC)