Jump to content

Wikipedia talk:User scripts/Archive 3

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Alex Smotrov (talk | contribs) at 15:46, 25 June 2007 (added 2007 discussions). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Archive 1Archive 2Archive 3Archive 4Archive 5Archive 7


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)

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)
Oh, wow, that's more transparent than I thought. I'm just trying to add 1, actually, so it's pretty easy. I assumed that since + is used for other purposes, it wouldn't work. -Amarkov blahedits 19:26, 6 January 2007 (UTC)
Okay, so now I need to know how to convert from a string to a number and back. The way I have doesn't work. -Amarkov blahedits 20:50, 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)
Which explains why it still fails. Argh. -Amarkov blahedits 21:56, 6 January 2007 (UTC)
Okay, so the problem, I think, is that URL parameters do not work properly out of "/w/index.php?" I might be able to manage around that. -Amarkov blahedits 22:06, 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)

So it looks like this is what you're trying to do:

  1. Get the current archive number from User:Amarkov/archivenumber
  2. Increment the archive number by one and update User:Amarkov/archivenumber
  3. Move User talk:Amarkov to User talk:Amarkov/Archive $N where "$N" is the new archive number
  4. 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)

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() calls akeytt() before calling any custom hooks, so generally user scripts will need to call akeytt() themselves. Also, you modified version probably doesn't currently work, since akeytt(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 replace addLink(), addlilink() and addTab(). 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 call updateTooltipAccessKeys([ 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 call updateTooltipAccessKeys([ element ]), which will change the title accordingly. —Ilmari Karonen (talk) 19:15, 14 January 2007 (UTC)

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:

  1. User:Barticus88/dpl.js, which adds selection mode buttons to the toolbox on What links here pages (used by disambiguation)
  2. 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)

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)

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)

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)

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)

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)

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)

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)
I tried this, and it's great and all, but I was just wondering, is there a way to put it in my toolbox on the left, and make it show up under "User Contributions" only if I'm on a userpage? Thanks ^demon[omg plz] 18:26, 11 March 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)
Thanks Mike, your script above worked perfectly. Regards, ^demon[omg plz] 14:46, 14 March 2007 (UTC)


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
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)

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)

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)

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)

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)

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)

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)
  • 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)
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 --
Then, ensure all your menu has a higher z-index and you'll get a yellow background up there. --Kainaw (talk) 18:58, 20 March 2007 (UTC)
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(/media/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)

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);

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)

WikiProject user category

It is recommended that Category:Wikipedians in WikiProject User scripts be renamed to either Category:WikiProject User scripts participants or Category:WikiProject User scripts members according to convention. It is left up to the project participants/members to choose which they would like. Please hold a discussion here and when there is consensus make the change. Thank you. --NThurston 15:11, 17 April 2007 (UTC)

Requested scripts format

Am I the only one who hates to format of the "Open requests"/"Fulfilled requests" section of the project page? I've been thinking that it would be better to move this to a page that is managed like Wikipedia:Requested templates. It could either be a project subpage or it could live at Wikipedia:Requested scripts or Wikipedia:Requested user scripts. What do you all think? Mike Dillon 23:38, 22 April 2007 (UTC)

Well, the whole project imho is a mess, and "requests" are not an exception. Anything would be better than what we have now. Personally I prefer it to be a subpage. — Alex Smotrov 13:46, 23 April 2007 (UTC)
I'd agree with the proposed change (prefer it to be a subpage of the project) or pretty much anything else that isn't obviously a bad idea, considering the mess it's in at the moment. --ais523 17:18, 24 April 2007 (UTC)

How should we deal with archiving? I think that the scheme used for WP:RT is a little baroque and overly complex. The questions I see are:

  • How should archives of fulfilled or expired requests be structured?
  • Should one of the auto archiving bots be used to maintain the archive structure? (e.g. User:Werdnabot)
  • If it should be auto archived, on what schedule?

I'm willing to refactor the current "Open requests" and "Fulfilled requests" sections, but I'm not sure what to do with the fulfilled requests (which are basically all of them). Mike Dillon 01:16, 25 April 2007 (UTC)

I'm going to start playing around with the a possible header and page structure at Wikipedia:WikiProject User scripts/Requests. Mike Dillon 01:18, 25 April 2007 (UTC)
I've started breaking the existing requests into sections at User:Mike Dillon/Script requests. Mike Dillon 02:08, 25 April 2007 (UTC)

Any opinions about what to do with the fulfilled requests? I know there's not much activity here, but is anyone opposed to replacing the Open requests and Fulfilled requests sections with the new page that I created? Mike Dillon 15:10, 2 May 2007 (UTC)

Please replace the sections! (Note that there have been some changes to the WP:US mainpage since you split off the sections, so if you haven't resynchronized them yet you may have to.) I suggest putting the open/fulfilled requests onto different subpages of WP:US, transcluding them, and putting an archivebot on the fulfilled requests page (set to some long length of time, say a month). --ais523 15:25, 2 May 2007 (UTC)

OK. So I've set up the following pages:

The requests page has a bunch of fulfilled requests that should probably be moved to the fulfilled page or the archive page. We should probably also split of the archive page into more than one page. Feel free to adjust as necessary. I didn't end up transcluding any of the pages because it would have complicated having a header on the page with a bunch of <noinclude> stuff. Mike Dillon 03:42, 4 May 2007 (UTC)

P.S. I put fake anchors on WP:US to replace the previous two sections with a single "Script requests" section. Mike Dillon 03:44, 4 May 2007 (UTC)
Great improvement, thanks! --ais523 11:51, 4 May 2007 (UTC)

Question

 importScript('User:Razorclaw/extraeditbuttons.js'); 

I wrote this along the lines of another script but what I want to know is, what can I remove from the script? I see table and redirect popups but do not know what to take out. Basically can you look at the script and tell me what I don't need? Also I would like to make it compatible with WikEd. What and where would I add the extra stuff to do that? Regards, «razorclaw» 19:35, 25 April 2007 (UTC)

Size of references

Is there anyone who has a script for changing the size of the references (as given by the </references> tag) in the articles? /Lokal_Profil 15:26, 29 April 2007 (UTC)

That is to change how I view them, not a universal change. /Lokal_Profil 15:27, 29 April 2007 (UTC)
Do you want to change the size across the board, or do you want to dynamically change it by clicking a link or something? Mike Dillon 15:32, 29 April 2007 (UTC)
To change it across the board, you can probably do it with the following (untested) CSS:
.references {font-size:-2}
(replace the -2 with whatever size-change or absolute size you want). This goes in your monobook.css, not your monobook.js. --ais523 08:02, 30 April 2007 (UTC)
Tried it but it didn't seem to work. Thanks anyway though. /Lokal_Profil 14:30, 2 May 2007 (UTC)

not js but pretty cool

See: User:Razorclaw/monobook.css/permanent. Could this be explained to me? It took me a while to get it just right but its there. I don't know what all it does but the most noticeable changes are:

  1. The navigation - interaction - search & toolbox headers have red background. I can't get the other languages one to have a red background. See [1] [2] [3].
  2. The title of the page has a red background
  3. The "You have new messages" box is blue with white text and orange links.

Regards, «razorclaw» 22:47, 2 May 2007 (UTC)

If I remember correctly, user styles (as opposed to scripts) are sorted out on Meta (m:Help:User style and m:Gallery of user styles), rather than here on Wikipedia, because new styles/skins work on any Wikimedia project (scripts are more often specific to things like AfD). --ais523 08:22, 3 May 2007 (UTC)

Another script

I rustled up this small script to edit the text in the tabs at the top of the page (I have crazy computer settings which means the tabs were too wide for the page).

/* Tab text editor */
function tabTexter(ttname,tttext)
{
   var tab = document.getElementById(ttname);
   if (tab)
      tab.firstChild.innerHTML = tttext;
}
function tabTexterHook()
{
   tabTexter("ca-edit", "edit");
   tabTexter("ca-history", "hist");
   tabTexter("ca-move", "→");
   tabTexter("ca-unwatch", "☑"); //☐☑☒
   tabTexter("ca-watch", "☐");
   tabTexter("ca-talk", "talk");
}
addOnloadHook(tabTexterHook);

--h2g2bob (talk) 07:44, 7 May 2007 (UTC)

linking .js variables to template parameters

Can this be done? A link or explanation would be appreciated.

Specifically, I am interested in setting a variable named idiom to 'British', etc. and having that determine spelling within articles (e.g. Brits will see colour). The template is Template:Idioms which is under development. Antonrojo 14:43, 17 May 2007 (UTC)

The usual method would be to use CSS for something like this. People would customize their monobook.css, or a script could activate various CSS classes depending on things that it calculated itself or asked the user for (see m:Stewards/confirm for an example of this technique; try 'en' and 'de' as the language to test it). The problem would be that users without CSS-enabled browsers would see both possiblies, so it's an accessibility problem (see Wikipedia:hiddenStructure). Doing it purely with JavaScript would involve encoding the information in a non-displaying way somehow on the page; there's no non-horribly-hacky way to do that using a template. Hope that helps! --ais523 16:07, 17 May 2007 (UTC)

Vandals

I have a request for some anti-vandal tool that blocks pontental vandalism in the browser using user user scripts and then send an e-mail to an appropriate person, since the problem that I'm trying to fix are just kids who use wikipedia as a toy or dump site for insults.It also should tell the kids what they shouldn't use wikipedia for.I have a fixed IP.

There are several antivandal scripts around (see Wikipedia:Cleaning up vandalism/Tools). I don't think any of them actually send abuse emails; that sort of thing would be a last resort, not a first resort, and anyway automated scripts aren't allowed to access the abuse-links databases (you have to look them up by hand). --ais523 07:55, 22 May 2007 (UTC)
I actually meant scanning the submitted content with assorted scanners for page blanking and bad words but the e-mail would be sent to the teacher and then the next higher up person after warnings.I'm helping a solveproblem involving misuse of Wikipedia and other wikis among students.Some students actually do good, but not all.(sorry that I was not so specific)But I'll look at those scripts.CommonEditor2345 06:22, 23 May 2007 (UTC)
Resolved

Hi, I'm trying to write some code that will give me an alert if a certain page is changed, similar to the alert you get when there is a new discussion on your talk page. I was thinking I could use the history RSS feed for this, but there would still lie the problem of it popping up on every page I visit. Is there an easy solution to this? I know that the date of the most recent change exists on the ninth line of the RSS feed if it can be parsed by new lines, but I am very inexperienced in JavaScript.

Also, being new to javascript, I am having a little bit of trouble with the guides and tutorials given. I was wondering how to go about adding links to the Special:Log/newusers page, specifically ading a link that will add a welcome message to their page when clicked, preferably just by adding the text to a new topic edit on the new user's discussion page.
For both of these I am willing to do the work on my own, I just think I'll need the occasional push to get me over some hills. If anyone could give me any idea, or small tidbits of code that can help me understand:

A) How to check if the page is Special:Log/newusers with javascript
B) How to read an RSS feed with javascript
C) Any way to check to see if you have already seen the edit made to that page


I would really appreciate it. Thanks. Redian (Talk) 05:38, 26 May 2007 (UTC)

I can answer part B easily enough. In the source of each page, there are a whole lot of variables you can use in your script, for instance, for this page at the moment:
var skin = "monobook";
var stylepath = "/skins-1.5";
var wgArticlePath = "/wiki/$1";
var wgScriptPath = "/w";
var wgServer = "http://en.wikipedia.org";
var wgCanonicalNamespace = "Project_talk";
var wgCanonicalSpecialPageName = false;
var wgNamespaceNumber = 5;
var wgPageName = "Wikipedia_talk:WikiProject_User_scripts";
var wgTitle = "WikiProject User scripts";
var wgAction = "view";
var wgArticleId = "2433713";
var wgIsArticle = true;
var wgUserName = "Ais523";
var wgUserGroups = ["sysop", "*", "user", "autoconfirmed", "emailconfirmed"];
var wgUserLanguage = "en";
var wgContentLanguage = "en";
var wgBreakFrames = false;
var wgCurRevisionId = "133581389";
wgPageName is a simple way to check which page you're on. (I think it might just return "Special:Log" for all the logs, but I'm not sure on this.) I'm not sure how to check RSS feeds using scripting, but when I wrote a script similar to what you wanted (User:ais523/watchlistnotifier.js; it might be similar enough that you can just use it, or at least copy some of the code) I used the APIs instead, which are suited to bot and script use (see http://en.wikipedia.org/w/query.php and http://en.wikipedia.org/w/api.php for the sort of information that scripts can retrieve using AJAX). As for part C, the solution I used was to set a cookie holding the information for the last watchlist view, which could be compared to the retrieved value to see if it was the same. I suspect a similar solution would work for you. Hope that helps! --ais523 15:08, 26 May 2007 (UTC)
Wow thats a big help! But how do I access an API from a javascript? I'd assume I would have to set the page to a variable. How is this done? (I know very little javascript aside from what can be deduced from previous programming knowledge) Redian (Talk) 19:36, 26 May 2007 (UTC)
The code's a bit complicated to get working in all browsers; I copied the code I used off another user. Here's the original discussion, from the archives:
  • A cross-browser XMLHTTP implementation that we can plug into our own scripts. I may end up fufilling this myself, but if I don't get around to it for a while and someone else has the time, here's the request. (Yes, there are implementations elsewhere online, but I want to be sure we have our own freely licensed version). ~MDD4696 02:53, 29 March 2006 (UTC)
This only works for downloading stuff, but it's fairly succinct. It owes much to User:Zocky, if I recall correctly.
wpajax={
        download:function(bundle) {
                // mandatory: bundle.url
                // optional:  bundle.onSuccess (xmlhttprequest, bundle)
                // optional:  bundle.onFailure (xmlhttprequest, bundle)
                // optional:  bundle.otherStuff OK too, passed to onSuccess and onFailure
                
                var x = window.XMLHttpRequest ? new XMLHttpRequest()
                : window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP")
                : false;
                
                if (x) {
                        x.onreadystatechange=function() {
                                x.readyState==4 && wpajax.downloadComplete(x,bundle);
                        };
                        x.open("GET",bundle.url,true);
                        x.send(null);
                }
                return x;
        },

        downloadComplete:function(x,bundle) {
                x.status==200 && ( bundle.onSuccess && bundle.onSuccess(x,bundle) || true )
                || ( bundle.onFailure && bundle.onFailure(x,bundle) || alert(x.statusText));
        }
};

// Example:


// function dlComplete(xmlreq, data) {
//      alert(data.message + xmlreq.responseText);
// }
//  wpajax.download({url:'http://en.wikipedia.org/w/index.php?title=Thresher&action=raw',
//                   onSuccess: dlComplete, message: "Here's what we got:\n\n" });
Lupin|talk|popups 03:52, 29 May 2006 (UTC)
Basically, you download the appropriate URL for what part of the API you're using (for instance, http://en.wikipedia.org/w/query.php?action=contribcounter&titles=User:ais523&format=xml if you were counting my edits) using the wpajax object (I suggest renaming it in your script to prevent a name conflict with other people using the same code), and it will callback a function of your choice with the data in the .responseText of the first parameter (see the example in the quote above). You can then use various methods (such as modified screen-scraping) to access the relevant part of the output, which comes in the format of your choice (XML is a good format to screen-scrape from). You can look at other scripts to get more ideas about what to do. Hope that helps! --ais523 16:05, 28 May 2007 (UTC)

AutoAFD error

When I attempt to import this script using Firefox 2.0, it gives an error and does not work. Has anyone gotten it to work for Firefox?

  • The script is imported using:
    • importScript('Wikipedia:WikiProject User scripts/Scripts/AutoAFD.js');
  • The error is: 'missing name after . operator'
  • The line with the error is (without the comment):
  • To test whether the script works, I refreshed the cache and edited an article. No additional tab or link shows up.
  • The template is applied here User:Antonrojo/monobook.js

Antonrojo 15:14, 9 June 2007 (UTC)

last.fm radio player widget for Mozilla Firefox

Hi I created a last.fm radio player widget for Wikipedia. It runs with Firefox.

Further info, see here: en:User:Csörföly D/last.fm widget

The Lion of Judah SMS "You send your big neck police friends fe come cool I up - But it no work" 2007. június 14., 00:43 (CEST)