Jump to content

User talk:Gary/comments in local time.js

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Script breaks in IE7

[edit]

Due to some missing "var"s, the script tries to set window.length, which causes IE to throw a javascript error and prevents other javascripts on the page from running (see Template_talk:WPBS#There Seems To Be a Problem). This diff should fix it, and cleans up the rest of the missing "var"s I could spot. Anomie 17:14, 14 June 2009 (UTC)[reply]

Okay sorry for the wait; fixed. I had to get Windows XP and install Parallels since I don't have a Windows computer, so it took some time before I finally got around to it. Gary King (talk) 17:49, 17 July 2009 (UTC)[reply]

Enhanced version of script

[edit]

I liked your script so much that I took the liberty of enhancing it to condense the output while still showing useful additional information. I hope you don't mind the fork. My version is at User:UncleDouggie/comments_in_local_time.js. You can also check out the diff listing. The starting point for the diff listing is your version as of 05:13, 27 July 2009 UTC with a few formatting changes to strip leading tabs from otherwise blank lines and add a small header comment. My method of invoking the script can be found here. Full documentation on the changes and the new default options is given in the script header in a format that could easily be adapted to update Wikipedia:Comments in Local Time should you desire to update your baseline.

Options used for sample timestamps:

LocalComments = {
	dateDifference: true,
	dropDays: 93,
	dropMonths: 24,
	dateFormat: 'dmy',
	timeFirst: true,
	twentyFourHours: true,		// Non-default option
	dayOfWeek: false
};

Here are some sample timestamps taken at 09:27, 30 August 2009 UTC / 02:27, 30 August 2009 (UTC-7):

  • 17:07, Yesterday (UTC−7)
  • 00:10, 27 August 2009 (3 days ago) (UTC−7)
  • 13:29, 22 August 2009 (8 days ago) (UTC−7)
  • 01:28, 23 July 2009 (38 days ago) (UTC−7)
  • 07:27, 21 June 2009 (70 days ago) (UTC−7)
  • 06:40, 13 May 2009 (3 months ago) (UTC−7)
  • 10:41, 13 June 2008 (14 months ago) (UTC−7)
  • 13:04, 8 October 2007 (22 months ago) (UTC−7)
  • 17:46, 18 April 2007 (2 years ago) (UTC−7)
  • 01:29, 31 December 2006 (2 years ago) (UTC−8)

The previous behavior of the script is still fully supported using these options:

LocalComments = {
	dateDifference: true,
	dropDays: 0,
	dropMonths: 0,
	dateFormat: 'dmy',
	timeFirst: true,
	twentyFourHours: false,
	dayOfWeek: true
};

The script could easily be changed to use this last set of options as the default if desired, and it would then be fully backwards compatible. I changed the defaults since the purpose of the enhancements was obviously to change the behavior. I found the dayOfWeek=true option to be overkill. Seeing the day of the week for comments many months old didn't do much for me. The usage of "last" only for days within the last 7 days also seemed confusing. I suppose we could add another option to only show the day of the week if the date is less than 7 days old if people want it.

The number of days shown may be different from your original script in many cases because I changed the computation method. The previous method used 1 January + delta days, which was usually quite off because it mapped the second delta month to February, which has only 28 days. This resulted in somewhat strange behavior in that a date of 13 May 2009 displayed on 29 August 2009 showed a delta of (3 months, 13 days). My new method still isn't exact, but it is normally within one day, and it made adding the new features easier.

UncleDouggie (talk) 10:40, 30 August 2009 (UTC)[reply]

I just fixed a small bug and updated the diff listing link above. UncleDouggie (talk) 14:10, 30 August 2009 (UTC)[reply]

Okay it looks good. I don't plan on making any more major changes to the script as there hasn't been any more comments about it; frankly, only a small percentage of people use the options, probably about 5% or less. Gary King (talk) 18:07, 30 August 2009 (UTC)[reply]
I fixed a bug when dropDays > 365. Hopefully that's the last one as I've now tried all the various option combinations. The reason I did the fork is that I didn't see the options I wanted to have. Perhaps more people would use options if these were available. Thanks for the great work in creating the script! UncleDouggie (talk) 18:47, 30 August 2009 (UTC)[reply]

Talk page jumps around

[edit]

Since the release of MediaWiki 1.17, this script is frequently causing talk pages to jump on the screen when a URL is opened that includes a section anchor. I have greatly reduced this behavior in my enhanced version of the script described above. The same change could be made in the base script as well. More information is here, although that discussion will be quickly moved off into archive 85 or 86. —UncleDouggie (talk) 07:44, 21 February 2011 (UTC)[reply]

Okay thanks, done. I don't notice anything different so far but I'll continue to monitor it. Gary King (talk · scripts) 03:54, 22 February 2011 (UTC)[reply]

Minor enhancement: no TZ

[edit]

I dislike seeing the time zone, so I made a minor change and am using it now: User:Foxyshadis/comments in local time.js. Only change is inclusion of a new option, utc: false, which disables showing the time zone. (I should probably have named it tz or timeZone, meh.) Foxyshadis(talk) 05:58, 17 July 2011 (UTC)[reply]

enhancement: support livepreview

[edit]

patch. Note: some new code from [1], otherwise it will not replaces and treat for action=edit properly.--YFdyh000 (talk) 23:28, 20 June 2016 (UTC)[reply]

Done I assume you have tested this sufficiently — Martin (MSGJ · talk) 08:25, 22 June 2016 (UTC)[reply]

The script isn't compatible with page-updating user scripts

[edit]

@Gary: Hi! Your script is executed on page load ($(() => {), not on wikipage.content event. But there are scripts that update the content of the page by Ajax, without refresh by means of the browser, among which my tool Convenient Discussions. First of all, your script needs to be called like this when used together with it:

mw.hook('convenientDiscussions.commentsReady').add(function () {
	importScript('User:Gary/comments in local time.js'); // [[User:Gary/comments in local time.js]]
});

But it also doesn't work when the page is reloaded by means of the script (say, after replying). Your script is also unable to process arbitrary DOM (say, only the preview area under the comment form created by Convenient Discussions or other tool).

In Russian Wikipedia, I updated the analogous script to use the wikipage.content event and process only the $content passed by the event instead of the whole page content. Could you do the same? Cheers! Jack who built the house (talk) 15:24, 3 March 2021 (UTC)[reply]

Gary seems to have been inactive since January. Maybe an interface administrator could help. 𝟙𝟤𝟯𝟺𝐪𝑤𝒆𝓇𝟷𝟮𝟥𝟜𝓺𝔴𝕖𝖗𝟰 (𝗍𝗮𝘭𝙠) 19:26, 6 March 2021 (UTC)[reply]

mw-body-content?

[edit]

@Gary: Just passing by (as I was trying to understand why your latest script changes killed one of my user scripts) and I see that you added mw-body-content to the script. Why? — GhostInTheMachine talk to me 12:31, 24 August 2022 (UTC)[reply]

You recommended to me to add it, right? Gary (talk · scripts) 19:30, 24 August 2022 (UTC)[reply]
Sigh. It is late ... — GhostInTheMachine talk to me 21:38, 24 August 2022 (UTC)[reply]