Admin Forum:JS code to lock old blogs

Forums: Admin Central Index → Technical Help → JS code to lock old blogs Wikia's forums are a place for the community to help other members. To contact staff directly or to report bugs, please use Special:Contact.

I'd like to know if there's a way I can tweak this code to lock only blogs sorted in a given category:


 * by: Joey Ahmadi

$(function { if (wgNamespaceNumber == 500 && $('#article-comments-ul li').size > 1) { var then = $('#article-comments-ul > .SpeechBubble:first .permalink').attr('href'); then = new String(then.match(/\d{8}/)); var monthnames = ['January','February','March','April','May','June','July', 'August','September','October','November','December']; var year = then.match(/^\d{4}/); var month = then.substring(4,6); month--; month= monthnames[month]; var day = then.match(/\d{2}$/); then = new Date(month+''+day+', '+year); var old = parseInt(now - then); old = Math.floor(old/(1000*60*60*24)); if (old > 30) { $('#article-comm').attr('disabled','disabled').text('This blog post hasn\'t been commented on for over 30 days. There is no need to comment.'); $('#article-comm-submit').attr('disabled','disabled'); $('.article-comm-reply').remove; } } });

For example, only blogs categorized in "Blog posts". ―  T hailog  14:37, March 2, 2012 (UTC)


 * Looks like you would only have to modify the if-clause that contains everything else:


 * Pecoes 15:54, March 2, 2012 (UTC)

Hmm, it still locks [http://youngjustice.wikia.com/wiki/User_blog:Summer.bradshaw/My_thoughts_on_Targets:_Beware_spoilers! blogs] not categorized there... Am I doing something wrong? ―  T hailog  17:56, March 2, 2012 (UTC)


 * Maybe. Are you sure you've added the new bit in the right place? -- Pecoes 18:31, March 2, 2012 (UTC)


 * I thought the { /* ... */ } bit was supposed to stay. Fail. It works now, thanks! What if I want to add more categories? Will  work? ―  T  hailog  20:13, March 2, 2012 (UTC)


 * I was afraid you'd ask me that. That's slightly more complicated.


 * Try this:


 * Nope. :( ―  T hailog  21:12, March 2, 2012 (UTC)


 * Hm. Are you sure? Here's my test page:


 * The first console.log outputs "true" and the second "false" -- Pecoes 21:28, March 2, 2012 (UTC)


 * Unless I messed it up. Do you mind taking a peak? ―  T hailog  21:38, March 2, 2012 (UTC)

You accidentally removed an important line from your script:

It's the line that says:. Without that line the script is broken.

I gotta ask: You don't know much about JavaScript, do you? -- Pecoes 22:32, March 2, 2012 (UTC)


 * Do you even have to ask? Not. A. Thing. (Unless you count making very small adjustments to already existing codes). Is there any beginners tutorial with idiotproof instructions I could benefit from? :) Btw, now it works, so thanks a bunch! ―  T hailog  22:46, March 2, 2012 (UTC)

No, sorry! I'm sure there's lots of good beginner's tutorials out there, but I'm no longer their target group. I suppose the w3schools tutorial doesn't suck, but there might be much better ones... -- Pecoes 23:09, March 2, 2012 (UTC)