User:Anandcv/monobook.js

/*document.write(''+ '');*/ var done = false; var waitCount = 0; var triedUrl = false;

var waitCount = 0; var highlightBlue = '#0066cc'; var backgroundGrey = '#222'; var staticContent = '';

// a global pane list wikiPaneList = new Array; // the matches matchLists = new Array;

//test if (typeof shbase == 'undefined') { shbase = 'https://meghaos.com/semanticAPI.php'; } if (typeof resourcebase == 'undefined') { resourcebase = shbase; } if (typeof shindex == 'undefined') { shindex = 1; } if (typeof shalgo == 'undefined') { shalgo = 'chooser'; } if (typeof shscores == 'undefined') { shscores = false; } if (typeof h3elementId == 'undefined') { h3elementId = 'siteSub'; } if (typeof matchType == 'undefined') { matchType = 'wikipedia'; }

var shparams = '';//'index=' + shindex + '&algo=' + shalgo;

// Get the parameters var params = new Array; function getParams { var query = window.location.search.substring(1); var parms = query.split('&'); for (var i=0; i 0) { var key = parms[i].substring(0,pos); var val = parms[i].substring(pos+1); params[key] = val; } } }

onWikiResults = function { // Escape Pages That We Want Static Text On, and Not Matches if(/Special:Userlogin/.test(document.location.href) ) { staticContent = ' Congratulations! You have successfully installed the Wikipedia Extension.'+ ' Search or browse Wikipedia as you normally would and the "Related Wikipedia'+     ' Matches" will automatically populate in here. '; } else if(/Special:Search/.test(document.location.href) ) { staticContent = ' Sorry! There doesn\'t seem to be a'+ ' Wikipedia article with the search term you entered. Semantic Signatures&reg;'+ ' only provides related matches for existing Wikipedia articles. '; } else if(typeof wikiMatchResult == 'undefined' || wikiMatchResult.length == 0) { if(!triedUrl) { triedUrl = true; url = shbase + '?uri='+encodeURIComponent(document.location.href)+'&format=JSON'; document.write(' '); return; }   staticContent = ' No Matches! Enter A URL and Hit "Match It!" '; }

var ssub = document.getElementById(h3elementId);

if(!ssub) { waitCount++; //alert(waitCount); if(waitCount > 10) { done = true; //alert("Wait Time Out.. 5 Seconds"); }   setTimeout(onWikiResults, 500); return; }

if(done) return; done = true;

var ssubHTML = ssub.innerHTML; var ssParent = ssub.parentNode; ssParent.removeChild(ssub);

// use mootools Assets to inject the CSS new Asset.css(resourcebase+'/css/shstyle.css', {id: 'shstyle', title: 'shstyle'});

//var shcontainerStyle = 'font-family : Trebuchet MS, Arial, Helvetica, sans-serif; text-align: center; font-size: 91%; overflow: hidden;width: 100px; margin: 1em auto;'; var listHTML = ''+ssubHTML+' '+ ' '+   '  '+    '    Related Wikipedia Articles '+ '   '+ '     '+ '  '+    '  '+    '  '+staticContent+ ' '+    ' ';

for(i in wikiMatchResult) { var paneTitle = decodeURIComponent(wikiMatchResult[i]['title']); wikiPaneList[i] = paneTitle; matchLists[wikiPaneList[i]] = wikiMatchResult[i]['matches']; }

ssParent.innerHTML = listHTML+ssParent.innerHTML;

buildPanes; }

buildPanes = function { if(staticContent.length > 20) return; var container = document.getElementById("accordionMaster"); if(!container) { waitCount++; if(waitCount > 10) { done = true; }   setTimeout(buildPanes, 500); } else { container.shmout = function(el) { if(!el.activeTog) { el.style.cursor='default'; el.style.color=backgroundGrey; }    }    container.shmover = function(el) { if(!el.activeTog) { el.style.cursor='pointer'; el.style.color=highlightBlue; }    }

var accHtml = ""; var height = 0; for ( var i=0, len=wikiPaneList.length; i'; miniHtml += ''; miniHtml += catTitle + ' ('+matchLists[catTitle].length+')'; miniHtml += ' '; // now begin the content div miniHtml += ''; height += 10; miniHtml += ' '; for (var j=0, jlen=matchLists[catTitle].length; j' } else { ref = '/wiki/' + title.replace(/%2F/g,"/"); miniHtml += '  ' }         miniHtml += decodeURIComponent(title) + ''; if(shscores && weight) miniHtml += ' ('+weight+')'; if(j < (jlen - 1)) { miniHtml += '    &#183;'; }       }        miniHtml += '  '; }     miniHtml += '  '; //newEl.setHTML(miniHtml); //accordion.addSection(newTog, newEl, i); accHtml += miniHtml; }   container.innerHTML = accHtml;

try { var accordion = new Accordion('div.toggler', 'div.element', {	opacity: false,       fixedHeight: (30 + height)+'px',	onActive: function(toggler, element) {                toggler.activeTog = true;		toggler.setStyle('color', highlightBlue);                element.setStyle('overflow', 'auto'); 	},	onBackground: function(toggler, element) {                toggler.activeTog = false;		toggler.setStyle('color', backgroundGrey);		element.setStyle('overflow', 'hidden');	}      }, container); } catch(err) { alert(err); } } }

var wikiMatchResult;

var writeCount = 0;

writeUIScript = function(url) { if(matchType == 'wikipedia') { if(typeof mw.config.get('wgPageName') == 'undefined') { triedUrl = true; url = shbase + '?uri='+encodeURIComponent(document.location.href)+'&mode=JSON'; } else { title = mw.config.get('wgPageName').replace(/_/g," "); if(!title) { writeCount++; //alert("write: " + writeCount); if(writeCount > 10) { done = true; //alert("Wait Time Out.. 5 Seconds"); }       setTimeout(writeUIScript, 500); return; }   }    url = shbase + '?uri=' + encodeURIComponent(location.href) + '&format=JSON'; document.write(' '); } else if(typeof url != 'undefined' && url.length > 0) { url = shbase + '?uri='+encodeURIComponent(url)+'&format=JSON'; document.write(' '); } else { onWikiResults; } // write out the mootools hook document.write('src="https://ajax.googleapis.com/ajax/libs/mootools/1.5.1/mootools-yui-compressed.js> ');         // Called by script above.... onWikiResults; or by doMatch on a uri }

getParams; if(typeof params['url'] != 'undefined') { url = decodeURIComponent(params['url']); //alert("Matching on URL : "+url); writeUIScript(url); } else { writeUIScript; }

//if (window.addEventListener) window.addEventListener("load",onWikiResults,false); //else if (window.attachEvent) window.attachEvent("onload",onWikiResults);