User:TestBotOnly/vector.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | The accompanying .css page for this skin is at User:TestBotOnly/vector.css. |
const LocalizationBannerHtml = '<span style="font-size: 1em;line-height: 1.5em;"> <a onclick="return onSurveyLinkClick(this);" target="_blank" href="http://survey.wikipediaresearch.org/?a=1&b="><b>Wie zufrieden bist du mit Wikipedia? <u>Dein</u> Feedback ist wichtig!</b><br/>Als Dankeschön erhältst du die Chance, ein Wikipedia T-Shirt zu gewinnen.<br/>Klicke hier, um an der Befragung teilzunehmen!</a></span>'; <!-- TODO: replace by {{{surveybannerhtml}}} -->
const LocalizationWinProbability = 1 / 1; <!-- TODO: replace by {{{surveywinprobability}}} -->
const LocalizationTimeSpan = 3 ; <!-- TODO: replace by {{{surveytimespan}}} -->
const constDone = 'done';
const constTodo = 'todo';
jQuery('#siteNotice').html('<div id="editorSurvey2011" style="display:none"> <div id="editorSurvey2011-logo"> </div> <div id="editorSurvey2011-content">' + LocalizationBannerHtml + '</div> <div id="cn-toggle-box"> <a href="#" onclick="$(\'#editorSurvey2011\').hide();setSurveyStatus(constDone);return false;"> <img border="0" src="http://bits.wikimedia.org/skins-1.17/common/images/closewindow.png" alt="Close" /> </a> </div></div>');
jQuery(document).ready( function()
{
console.log('jQuery(document).ready');
// If the survey should not be hidden...
if ( document.cookie.indexOf('surveyStatus=' + constDone.toString() ) == -1 )
{
initSurveyIfNeeded();
}
} );
function initSurveyIfNeeded()
{
console.log('initSurveyIfNeeded');
var tsSetting = 'surveyStartTime=';
var timeStampLocation = document.cookie.indexOf( tsSetting );
// If the survey is not set at all
if ( document.cookie.indexOf('surveyStatus=' + constTodo.toString()) == -1 )
{
// If the user is an editor, do lottery.
if ( window.location.toString().indexOf( 'action=edit' ) != -1 )
{
var selectionSize = LocalizationWinProbability ;
// If the user wins the lottery, set DisplayTodo
if ( Math.random() < selectionSize ) {
setSurveyStatus(constTodo);
} // If the user loses, set done.
else {
setSurveyStatus(constDone);
}
}
// (If the user is not an editor, do nothing.)
}
else
{
// If the start of the survey is set, display it when still within 5 mins, otherwise set done.
if ( timeStampLocation != -1 )
{
if ( parseInt( document.cookie.substr( timeStampLocation + tsSetting.length, 13 ) ) + ( 1000*60* LocalizationTimeSpan ) > (new Date()).getTime() )
{
displaySurvey();
}
else
{
setSurveyStatus(constDone);
}
}
// If the start of the survey is not set, check for the right page (first page that is not an "action" page)
else if ( window.location.toString().indexOf( 'action=' ) == -1 )
{
var date = new Date();
var currentTime = date.getTime().toString();
date.setTime(date.getTime()+(31*24*60*60*1000));
var expires = date.toUTCString();
document.cookie = 'surveyStartTime=' + currentTime + '; expires=' + expires + '; path=/'; displaySurvey();
}
}
}
function setSurveyStatus(status)
{
console.log('setSurveyStatus: ' + status);
var date = new Date();
date.setTime(date.getTime()+(31*24*60*60*1000));
var expires = date.toUTCString();
document.cookie = 'surveyStatus=' + status.toString() + '; expires=' + expires + '; path=/';
}
function displaySurvey()
{
console.log('displaySurvey');
jQuery('#editorSurvey2011').show();
<!-- Notice for WMF reviewer: Would it possible to use the WMF tracker? -->
jQuery('head').append('<link rel="stylesheet" href="http://wikimediafoundation.org/tracker/bannerImpression.php?req=css&surveyView=1 " type="text/css" />');
}
function onSurveyLinkClick( senderObject )
{
console.log('onSurveyLinkClick');
setSurveyStatus(constDone);
var sender = $( senderObject );
var a = Math.random().toString();
var currentHref = sender.attr( 'href' );
sender.attr( 'href', currentHref + a );
return true;
}