User talk:Dschwen/highlightredirects.js
From Wikipedia, the free encyclopedia
- You might look at querying api.php instead of loading the whole page with action=raw.
- #REDIRECT is not enough. there can be whitespace between # and REDIRECT which does not have to be uppercase.
Nifty though! โ Hippietrail 01:26, 23 January 2007 (UTC)
- api.php is a great suggestion, I just implemented it. Drastically reduces the request volume, and creates a appealingly absurd third layer of JavaScript interpretation (to eval the returned JSON string) :-). --Dschwen(A) 23:36, 14 February 2007 (UTC)
[edit] Suggested changes
G'day, very impressive! I respectfully suggest a couple of changes, though:
- it currently doesn't go past any anchors that are targets (i.e. have a name but no href). Fixed by testing
links[key].href
when you testlinks[key].pathname
:
if( links[key].href && links[key].pathname && links[key].pathname.substr(0,6) == '/wiki/' && !( links[key].href.substr(0,local.length) == local ) )
- it currently only picks up the uppercase form of redirect, and as stated above, ignores the permissible form with a space between the # and the redirect. Fixed by changing the test to a regex:
'if(/\#.?redirect/i.test(me.xhr.responseText)) {' +
cheers, Webaware talk 14:08, 14 February 2007 (UTC)
- Thanks a lot for your suggestions, and especially for providing the code snippets along with them! The whole thing was created as a proof of concept. If you have further ideas or suggestions please don't hold back. I appreciate any kind of input. --Dschwen(A) 22:44, 14 February 2007 (UTC)
-
- Thanks a lot for coming up with this. Not only is it very useful, it's also quite instructive - I must get my head around AJAX sometime, and now I have somewhere I can play with it without it being too boring!
- I've just noticed a couple of other instances where it stops short of getting all links, so I'll investigate and post back the fix(es). cheers, Webaware talk 23:18, 14 February 2007 (UTC)
- Ok, I've noticed failing XHRs too, but I just cannot get my finger on them. And I just switched to requesting api.php (see above). --Dschwen(A) 23:36, 14 February 2007 (UTC)
- This looks interesting, and the script now picks up all links on the pages where I found it wasn't getting them before. However, you currently have it hard-coded for en.wikipedia.org pages; it would be handy if you truncate that to just
/w/api.php?...
, so that the script can still be used from other Wiki projects (like Wikibooks, *.wikipedia.org, etc.) Webaware talk 02:19, 15 February 2007 (UTC)
- This looks interesting, and the script now picks up all links on the pages where I found it wasn't getting them before. However, you currently have it hard-coded for en.wikipedia.org pages; it would be handy if you truncate that to just
- Ok, I've noticed failing XHRs too, but I just cannot get my finger on them. And I just switched to requesting api.php (see above). --Dschwen(A) 23:36, 14 February 2007 (UTC)
Hi! Can you make this script to work in IE too? I'd like to use it but I cannot. (And I won't use Firefox!!!) Diaby talk 19:46, 14 January 2008 (UTC)
- I can try, it's been a while since I worked on that script, and I forgot the IE quirk that makes it fail. I'll try and see if i can find the reason again... --Dschwen 20:07, 14 January 2008 (UTC)
Thank you! Diaby talk 19:46, 22 January 2008 (UTC)
[edit] Comment
This looks like a very useful script :) It turns out, though, that the functionality has recently been added to MediaWiki, so run
could be replaced with:
addStylesheetRule = function(tag, style) { var ss = document.styleSheets[0]; if (ss.insertRule) { ss.insertRule(tag + '{' + style + '}', ss.cssRules.length); } else if (ss.addRule) { ss.addRule(tag, style); } } addStylesheetRule('a.mw-redirect', 'color:green');
...or something like that. (addStylesheetRule from User:Quarl/redirector.js) In addition, users could add something to their monobook.css to have redirects be highlighted on every page. Cheers, GracenotesT ยง 17:32, 6 April 2008 (UTC)
- I second that. Why make a lot of queries to the server (which, by the way, should have been just ONE query from the beginning) for information that's already included on the page? โAlexSm 15:45, 14 April 2008 (UTC)
- Done. But please, enlighten me how I could have done this with ONE query. In any case the script was a programming exercise for XHRs in the first place.. --Dschwen 15:55, 14 April 2008 (UTC)
- ...&titles=Main Page|Main page|Mainpage, unless, of course, this wasn't implemented at the time the script was written. Thanks for the rewrite. However, you might want to actually count those mw-redirect links in order to duplicate previous functionality, otherwise some users might complain that the script doesn't seem to work anymore :) โAlexSm 16:10, 14 April 2008 (UTC)
- Done. But please, enlighten me how I could have done this with ONE query. In any case the script was a programming exercise for XHRs in the first place.. --Dschwen 15:55, 14 April 2008 (UTC)
[edit] Appears on Preview page
Since you purposely hide this function from the Edit page, I don't know if it is intentional that the button still appears for the Preview page? Gary King (talk) 23:02, 5 May 2008 (UTC)
- Hmm, why not, there is visible rendered article text on the preview page, so it should work there, unlike the edit page, which has no article text links. --Dschwen 02:01, 6 May 2008 (UTC)
- That depends on a user's settings; I've got the text already showing on the edit page. Also, I see no reason for the script to work on any page except for the Article namespace, and possibly the Wikipedia namespace. I'm going to place the script in a wrapper to remove it from the User talk namespace because even with 1440 pixels horizontally on my screen, I still get a horizontal scroll bar for User Talk pages. Gary King (talk) 02:17, 6 May 2008 (UTC)