Community Central
Community Central
No edit summary
No edit summary
Line 4: Line 4:
 
If you require staff help, please use Special:Contact or community@wikia.com to be sure of a staff reply. -->
 
If you require staff help, please use Special:Contact or community@wikia.com to be sure of a staff reply. -->
   
  +
Testing is over. Sine is finished and ready to use.
I'm the sort of person who constantly forgets to sign his posts. But I'm also a programmer and as such I fail to see why ''I'' should do what a ''script'' could do in my stead. This is this script:
 
   
  +
Sine automatically adds your signature to your posts in forums like this one and on talk pages.
<div style="border: 1px solid black; padding: 10px"><source lang="javascript">
 
// Sine:
 
$(function () {
 
talkNameSpaces = [1,3,5,7,9,11,13,15,110,111,114,401,500,501,502,503];
 
if (-1 < $.inArray(wgNamespaceNumber, talkNameSpaces) && 'edit' == $.getUrlVar('action')) {
 
appendSine = function () {
 
if ($('input#wpMinoredit').is(':checked')) return;
 
var sine = '~~' + String.fromCharCode(126) + '~';
 
switch (editorInstance.mode) {
 
case 'wysiwyg':
 
var wysiwyg = editorInstance.getEditbox();
 
var textOnly = wysiwyg.text().trim();
 
if (!textOnly.length || sine == textOnly.substr(-4)) return;
 
var lastBlock = wysiwyg.find('> *:last-child');
 
if (lastBlock.is('p')) {
 
if (lastBlock.text().trim().length) sine = ' -- ' + sine;
 
var lastElement = lastBlock.find(':last-child');
 
lastElement[lastElement.is('br') ? 'before' : 'after'](sine);
 
} else {
 
while (!lastBlock.is('p') && lastBlock.prev().length) lastBlock = lastBlock.prev();
 
$('<p>' + sine + '</p>').appendTo(wysiwyg).css({
 
marginLeft: lastBlock.css('marginLeft')
 
});
 
}
 
break;
 
case 'source':
 
var source = editorInstance.getContent();
 
if (!source.trim().length) return;
 
var lines = source.split(/\r\n|\r|\n/).reverse();
 
var l = lines[0].trim();
 
if (l.length) {
 
if (sine == l.substr(-4)) return;
 
var isBlock = /^[*#]/.test(l) || /^(={2,6})[^=]+\1$/.test(l) ||
 
/(?:----|}}|<\/(?:blockquote|div|pre|code|nowiki)>)$/.test(l);
 
sine = (isBlock ? "\r\n" : " -- ") + sine;
 
} else {
 
for (var i = 1; i < lines.length; i++) {
 
l = lines[i].trim();
 
if (!l.length) continue;
 
if (sine == l.substr(-4)) return;
 
m = l.match(/^(\:+)/);
 
if (m) sine = m[1] + sine;
 
break;
 
}
 
}
 
editorInstance.setContent(source + sine);
 
break;
 
}
 
}
 
$('input#wpSave').click(appendSine);
 
$('a#publish').click(appendSine);
 
}
 
});
 
</source></div>
 
   
  +
To use Sine simply add:
Or at least I hope it is. I did test it and it does seem to work. But it would be helpful if a few others would test it as well before I publish it at the dev wiki.
 
   
 
<div "border: 1px solid black; padding: 10px; background-color: white;"><source lang="javascript">
To install the script go to your [[Special:Mypage/global.js|global.js]] and copypaste the code from here to there. You will need to [[w:c:dev:Hard_Refresh|refresh]] both global.js and the test page. You may also have to wait a while for the script to take effect or [[Help:Purge|purge]] manually. I'm not certain about the latter.
 
  +
importScriptPage('Sine/code.js', 'dev');
 
 
</source></div>
Note: If you ''don't'' want to have your post signed, check "Minor edit".
 
 
Let me know whether it does or does not work! Suggestions and critique are welcome too!
 
-- [[User:Pecoes|Pecoes]] 06:29, March 9, 2012 (UTC)
 
 
 
 
UPDATE1: added check for input#wpMinoredit. -- [[User:Pecoes|Pecoes]] 07:03, March 9, 2012 (UTC)
 
   
  +
to your [[Special:Mypage/global.js|global.js]].
UPDATE2: replaced call to editorInstance.setContent() with call to editorInstance.getEditbox().append() for WYSIWYG editor -- [[User:Pecoes|Pecoes]] 09:24, March 9, 2012 (UTC)
 
   
  +
Should you ever want to ''not'' sine a post, simply check "Minor Edit".
UPDATE3: made the sining for "source" editor a little smarter: when the sine would be on the same line with a block element, a newline is inserted; when the sine is on a line of its own, it will be indented if the preceding lines were indented -- [[User:Pecoes|Pecoes]] 08:50, March 10, 2012 (UTC)
 
   
UPDATE4: after a serious bit of reverse engineering I think I figured out to correctly append the sine to the RTE as well. -- [[User:Pecoes|Pecoes]] 15:13, March 10, 2012 (UTC)
+
If you find a bug or have a feature request, post on the [[w:c:dev"Talk:Sine|Sine talk page]], please. -- [[User:Pecoes|Pecoes]] 21:56, March 10, 2012 (UTC)

Revision as of 21:56, 10 March 2012

Forums: Admin Central Index Watercooler Testers needed for automated signature!
Central's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.
Note: This topic has been unedited for 4422 days. It is considered archived - the discussion is over. Do not add to unless it really needs a response.



Testing is over. Sine is finished and ready to use.

Sine automatically adds your signature to your posts in forums like this one and on talk pages.

To use Sine simply add:

importScriptPage('Sine/code.js', 'dev');

to your global.js.

Should you ever want to not sine a post, simply check "Minor Edit".

If you find a bug or have a feature request, post on the Sine talk page, please. -- Pecoes 21:56, March 10, 2012 (UTC)