User:Dschwen/vector.js

// JSParse (some utility parser functions) var jsparse = { tables: function(txt) { txt=txt||$('#wpTextbox1').text; return txt.match(/(\{\|(?:(?!\|\}).|\n)+\|\})/g) }, tabArray: function(tab) { var rows=tab.split('|-'); } }

// enhance user contributions view // mw.config.get('wgPageName') === "Special:Contributions/Dschwen" function ucEnhance { var p = {}; $('#mw-content-text>ul>li').each(function{ var e = $(this), t=e.find('.mw-uctop').length>0, l=e.find('.mw-contributions-title').attr('title');  if( !(l in p) && !t ) {   e.css('background-color','pink');  }  p[l]=true; }); } if( mw.config.get('wgAction') == 'view' && mw.config.get('wgPageName') === "Special:Contributions/Dschwen" ) { $(document).ready(ucEnhance); }

$(function{ var r = {};

$('.vevent').each(function(i,e){   var a = $('.dtstart').attr('title')     , b = $('.dtend').attr('title')      , s, e;    if(a||b) {      (r.mf=r.mf||[]).push([a,b]);    }  });

$('a[title^="Category:"]').each(function(i,e){   var m = /^([\d]{4}) (BC |)in /.exec($(e).text);    if(m) { (r.loc=r.loc||[]).push(m[1]*(m[2]==''?1:-1)); }  }); if( r.loc ) { // remove duplicate year numbers var i,obj={}; for(i=0;i<r.loc.length;++i){ obj[r.loc[i]]=1; } r.loc=[]; for(i in obj){ r.loc.push(i); } }

$('a[title$=" births"],a[title$=" deaths"]').each(function(i,e){   var m = /^([\d]{1,4}) (BC |)(births|deaths)$/.exec($(e).text), y;    if(m) { (r[m[3]]=r[m[3]]||[]).push(m[1]*(m[2]==''?1:-1)); }  });

var d = $('th:contains(Date)').parent.find('td').eq(0).text; if(d) { (r.table=r.table||[]).push(d); }

//console.log(mw.config.get('wgTitle'), JSON.stringify(r)); });

var wma_settings = { height : 500, width : 700, iframeurl : '//wma.wmflabs.org/iframe_dev.html' }

// ignorance is bliss ignoreUserList = { 'User:Adam Cuerden' : true };

/* Since I expect this little function to be discovered sooner or later I'll better add a little explanation. Does this qualify as passive aggressive? Maybe. But I'm   a voluntary contributor here and think I'm under no obligation to read every statement from every user. Some people are just the equivalent of a red cloth for me, and everybody will benefit from me just ignoring those people. So if it hurts noone I believe it is ok for me to make my work here as pleasant as possible. function ignoreUsers { // get discussion paragraphs, ':' indented at DD, '*' indented are 'LI', unindented are 'P' var tags = { 'DD':0, 'LI':0, 'P':0 }; var protect = { 'DL':0, 'UL':0 }; for( tag in tags ) { paragraphs = document.getElementsByTagName(tag);

// loop over all paragraphs for( key in paragraphs ) {  // loop over all immediate child elements (avoids looking at response paragraphs) var children = paragraphs[key].childNodes; if( children ) {   for( var i = 0; i < children.length; i++ ) {    // does paragraph contain a link to a blacklisted userpage? (unless we are on the blacklisted users talkpage!) var hide = false; if( children[i].nodeType === 1 &&         children[i].tagName === 'A' &&          ignoreUserList[children[i].title] === true &&         'User:' + mw.config.get('wgTitle') !== children[i].title ) {     hide=true; break; }   }

// hide this paragraph? if( hide ) {    var i = 0; while( i < children.length ) {     if( children[i].nodeType === 1 && !(children[i].tagName in protect) || children[i].nodeType !== 1 ) {      paragraphs[key].removeChild(children[i]); }     else i++; }   }

}//endif children }//endfor paragraphs }//endfor tags } $(ignoreUsers);

function detectKML { function gotXML(xml) { window.kmldata = xml; window.t1 = new Date; kml = { ways: [] } $(xml).find('LineString:not(:has(coordinates)),coordinates').each(function{  var way=[],i,j,c,p=$(this).text.split(' ');   for( i=0; i= 2 ) {     way.push( { lat: parseFloat(c[1]), lon: parseFloat(c[0]) } );    }   }   kml.ways.push(way);  }); window.t2 = new Date; console.log(JSON.stringify(kml)); } var i,l = $('table.metadata').find('a'),s=mw.config.get('wgPageName')+'/KML&action=raw'; window.t0 = new Date; for( i = 0; i < l.length; ++i ) { if( l[i].href.slice(-s.length) === s ) { $('#content').css('background-color','lightgreen'); $.ajax({   url: l[i].href,    dataType: 'xml',    success: gotXML   }); break; } } }

// User:Dschwen/coordinates.js - please include this line document.write(' ');

function buildSpotLight(r) { var canvas, c, grad, im    , shown = false , x, y, tx, ty    , dirty = null , easing = false , locked = false , ticksSinceMove = 0 , mouseShown = true ;

// build canvas canvas = $(' ').css({     pointerEvents: 'none',      zIndex: 10,      position: 'fixed',      display: 'none',      top: 0,      left: 0    }); $(window).resize( function { dirty = null } ); $('body').append(canvas);

// initial position x = 0; y = 0;

// draw and cache spotlight c = canvas[0].getContext('2d'); recache(r);

$(document).keyup( function(e) {     switch(e.which) {        case 107 : // s        case 187 : // s          mouseWheelHandler(null,1); break;        case 109 : // -        case 189 : // -          mouseWheelHandler(null,-1); break;      }    });

// mouse cursor auto hide setInterval( function {     ticksSinceMove++;      if( shown ) return; // do nothing when spotlight is active

if( mouseShown ) { if( ticksSinceMove > 5 ) { //$('body').css('cursor','none'); mouseShown = false; }     } else { if( ticksSinceMove <= 5 ) { //$('body').css('cursor',''); mouseShown = true; }     }    }, 500 );

// bind the 'dry' mousemove handler (only update coordinates, no redrawing) $(document).bind( 'mousemove', mouseMoveHandlerDry );

// methods function recache(newr) { r = newr; // resize temporarily var s = Math.ceil(2*r); canvas[0].width = s;     canvas[0].height = s;      // radial gradient grad = c.createRadialGradient(r,r,r*0.75,r,r,r); grad.addColorStop(0, 'rgba(0,0,0,0)'); grad.addColorStop(1, 'rgba(0,0,0,0.5)'); // draw shapes c.fillStyle = grad; c.fillRect(0,0,s,s); im = c.getImageData( 0, 0, s, s );

// scale back and redraw dirty = null; scale; }   function scale { var w = $(window).width, h = $(window).height; canvas[0].width = w;     canvas[0].height = h;      draw; }   function draw { c.fillStyle = 'rgba(0,0,0,0.5)'; if( dirty === null ) { c.clearRect(0,0,canvas[0].width,canvas[0].height); c.fillRect(0,0,canvas[0].width,canvas[0].height); } else { c.clearRect(dirty.x,dirty.y,dirty.w,dirty.h); c.fillRect(dirty.x,dirty.y,dirty.w,dirty.h); }     c.putImageData( im, Math.floor(x-r), Math.floor(y-r) ); dirty = { x: Math.floor(x-r), y: Math.floor(y-r), w: im.width+5, h: im.height+5 }; }   function mouseMoveHandler(e) { if( !locked && !easing ) { x = e.clientX; y = e.clientY; draw; }   }    function mouseMoveHandlerDry(e) { if( x!=e.clientX || y!=e.clientY ) { ticksSinceMove = 0; }     x = e.clientX; y = e.clientY; }   function mouseWheelHandler(e, delta) { var newr = Math.floor( r + (10+r/10)*delta ); if( newr < 30 || newr > 1000 ) { return; } recache( newr ); }   function show { $(document).unbind( 'mousemove', mouseMoveHandlerDry ); $(document).bind( 'mousemove', mouseMoveHandler ); //$(document).mousewheel( mouseWheelHandler ); $(window).bind( 'resize', scale ); //$('body').css('cursor','crosshair'); //$('body').css('cursor','none'); mouseShown = false; dirty = null; scale; canvas.fadeIn; shown = true; }   function hide { $(document).unbind( 'mousemove', mouseMoveHandler ); $(document).bind( 'mousemove', mouseMoveHandlerDry ); //$(document).unmousewheel( mouseWheelHandler ); $(window).unbind( 'resize', scale ); //$('body').css('cursor',''); canvas.fadeOut; shown = false; locked = false; }   function toggle { if( shown ) { hide; } else { show; }     return shown; }

return { toggle : toggle, show: function { if(!shown) show; locked = true; },     hide: function { if(shown) hide; },     size: function(newr) { x = x + r - newr; y = y + r - newr; recache( newr ); }   };  }

/* // Spotlight spotLight = buildSpotLight(100);

$(document).keyup( function(e) {   switch(e.which) {      case 83 : // s        spotLight.toggle; break;    }  });