User:Ais523/wikibreakenforcer.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

// [[User:ais523/wikibreakenforcer.js]]
// An 'improved' version of [[Wikipedia:WikiProject User scripts/Scripts/WikiBreak Enforcer]]
// Can enforce semiwikibreaks (with limited editing allowed) as well as 'true' wikibreaks
// Note that this will only work perfectly if you always use the same user/browser/computer
// combination.
// Thanks to [[User:HG]] for the idea.
 
// Before including this script, set the following variables:
// wbeEditTime      How long you can edit for at a time (in minutes); set to 0 to turn this off
// wbeWaitTime      How long you have to wait before editing periods (in minutes)
// wbeEndDateY      Year at which this script stops enforcing wikibreaks (e.g. 2007)
// wbeEndDateM      Month number at which this script stops enforcing wikibreaks (e.g. 9 for 
//                  September)
// wbeEndDateD      Day in the month at which this script stops enforcing wikibreaks
// wbeBlockAnon     Prevents you even viewing/editing Wikipedia as an anon if set to true (only do 
//                  this if you have the 'remember me' option set); if set to false, you can view and
//                  edit Wikipedia as an anon.
 
// If you find yourself locked out by this script by mistake, or change your mind about installing
// it, you can either uninstall it during an editing period, or request an administrator to remove
// it for you.
 
/* An example of how to include this script in your monobook.js:
 
wbeEditTime=60;
wbeWaitTime=540;
wbeEndDateY=2007;
wbeEndDateM=12;
wbeEndDateD=31;
wbeBlockAnon=false;
importScript("User:ais523/wikibreakenforcer.js");
 
*/
 
//<source lang="javascript">
 
function wbestartlogon()
{
  if(!confirm("Start a temporary logged on session for up to "+wbeEditTime+" minutes (when it ends,"+
              " you will be locked out for "+wbeWaitTime+" minutes)?")) return;
  var d=new Date();
  d.setTime(new Date().getTime()+(wbeEditTime+wbeWaitTime)*60000);
  document.cookie="ais523wbest="+(new Date().toUTCString())+"; expires="+(d.toUTCString())+
                  "; path=/; domain=en.wikipedia.org";
  location.reload(true);
}
 
var wbeDelayedInnerHTML;
 
function wbedelbodyset()
{
  document.body.innerHTML=wbeDelayedInnerHTML;
}
 
function wbedelbodysetdelay()
{
  window.setTimeout("wbedelbodyset()",1)
}
 
if(new Date().getTime()<new Date(wbeEndDateY,wbeEndDateM-1,wbeEndDateD).getTime())
if(location.href.indexOf("?action=submit")==-1&&location.href.indexOf("&action=submit")==-1)
{
  // It's still in the wikibreak period.
  var dc=document.cookie.split(';')
  var i=dc.length;
  var wbest="";
  while(i--) if(dc[i].split('=')[0].indexOf("ais523wbest")!=-1) wbest=dc[i].split('=')[1];
  // Three possibilities.
  if(wbest==""||new Date().getTime()-new Date(wbest).getTime()>=(wbeEditTime+wbeWaitTime)*60000)
  {
    // There isn't a blocking cookie at the moment, or it's expired.
    var ih;
    ih= "<div style='font-size:24px'><h1>Wikibreak Enforcer</h1>";
    ih+="<p>You can log on at the moment.</p>";
    ih+="<p>Choose one of these options:<ul>";
    if(wbeEditTime)
      ih+="<li><a href='javascript:wbestartlogon()'>Start a temporary logged on period.</a></li>";
    if(!wbeBlockAnon)
      ih+="<li><a href='/wiki/Special:Userlogout'>View/edit Wikipedia as an anon.</a></li>";
    ih+="<li>Go to another website (you don't need to click on this option, just go there).</li>";
    wbeDelayedInnerHTML=ih+"</ul></p>";
    hookEvent("load",wbedelbodysetdelay);
    // Disable all other scripts
    doneOnloadHook=1; addOnloadHook=function(x){}; importScript=function(x){};
    window.doneOnloadHook=1; window.addOnloadHook=function(x){}; window.importScript=function(x){};
    onloadFuncts=[]; window.onloadFuncts=[];
  }
  else if(new Date().getTime()-new Date(wbest).getTime()<wbeEditTime*60000)
  {
    // Do nothing; we're in an allotted edit time.
  }
  else if(new Date().getTime()-new Date(wbest).getTime()<(wbeEditTime+wbeWaitTime)*60000)
  {
    // In a blocked period at the moment.
    var ih;
    ih= "<div style='font-size:24px'><h1>Wikibreak Enforcer</h1>";
    ih+="<p>You're currently automatically blocked by the enforcer, to enforce your wikibreak.</p>";
    ih+="<p>Choose one of these options:<ul>";
    if(!wbeBlockAnon)
      ih+="<li><a href='/wiki/Special:Userlogout'>View/edit Wikipedia as an anon.</a></li>";
    ih+="<li>Go to another website (you don't need to click on this option, just go there).</li>";
    ih+="<li><a href='javascript:location.reload(true)'>Refresh this page.</a></li>";
    wbeDelayedInnerHTML=ih+"</ul></p>";
    hookEvent("load",wbedelbodysetdelay);
    // Disable all other scripts
    doneOnloadHook=1; addOnloadHook=function(x){}; importScript=function(x){};
    window.doneOnloadHook=1; window.addOnloadHook=function(x){}; window.importScript=function(x){};
    onloadFuncts=[]; window.onloadFuncts=[];
  }
}
//</source>
//[[Category:Wikipedia scripts]]