Jump to content

User:Anilande/dr.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Anilande (talk | contribs) at 10:55, 12 January 2011 (Created page with '// ===UserScript=== // @name DRin // @namespace DRin // @include http://*.wikipedia.org/* // ===/UserScript=== // // DRin launch helper script...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// ===UserScript===
// @name           DRin
// @namespace      DRin
// @include        http://*.wikipedia.org/*
// ===/UserScript===
//
// DRin launch helper script.
// Description: this script eases the procedure to launch DRin by instrumenting
// wikipedia pages with links and options to launch the application. 
//
// The current options to launch DRin are:
// click the 'View Visually' option in the left side toolbox menu and 'View Visually' tab on top tabs list.


var drGadget = {

	// wbLoadGadget is executed after the page finishes loading. It looks for specific
	// indicators and determines how to instrument the page with different options to launch the application
	drLoadGadget : function()
	{
		var title = drGadget.getCurrentArticleTitle();
		if(title){
			docHeight = document.height - 100;
			var drUrl = 'javascript:(function(){var HTML = "<iframe src=\'http://msri-digitalpro/rin/?PlayerMode=Dynamic&NarrativeId='+title+'\' width=\'100%\' height=\''+docHeight+'px\'></iframe>";  document.getElementById("content").innerHTML = HTML; document.getElementById("tabDRin").className="selected"; document.getElementById("ca-view").className=""; document.getElementById("ca-edit").className=""; document.getElementById("ca-history").className="";})();';
		}else{
			return false;
		}
		
		// looks for the Toolbar on edit pages, creates and appends a simple button in the format expected by the toolbar
       if(document.getElementById('p-views'))
		{
			var liElem = document.createElement('li');
		    liElem.id = 'tabDRin';
			var anchorElem = document.createElement('a');
			anchorElem.title = "View visually";
			anchorElem.id = "toolbarLinkDRin";
			anchorElem.innerHTML = "<span>View visually</span>";
			anchorElem.href = drUrl;
			liElem.appendChild(anchorElem);
			var ulEle = document.getElementById('p-views').getElementsByTagName("ul")[0];
			ulEle.insertBefore(liElem, ulEle.firstChild);
		}
		// Checks for the "toolbox" section, usually present on lower left side of the page. 
		if(typeof(document.getElementById('p-tb').getElementsByTagName("div")[0].getElementsByTagName("ul")[0]) != "undefined")
		{
			var toolboxUL = document.getElementById('p-tb').getElementsByTagName("div")[0].getElementsByTagName("ul")[0];			
			// construct the DOM as expected by the toolbox div
			var liElem = document.createElement('li');
			liElem.id = 'liDRin';
			var anchorElem = document.createElement('a');
			anchorElem.title = "View visually";
			anchorElem.id = "toolbarLinkRin";
			anchorElem.href = drUrl;
			anchorElem.innerHTML = "View visually";
			liElem.appendChild(anchorElem);
			toolboxUL.insertBefore(liElem,toolboxUL.firstChild);
		}
	},
	getCurrentArticleTitle: function() {      
		if (typeof wgTitle !== "undefined") {
			if (wgAction === "view" && wgArticleId === 0 && wgIsArticle === false) {
				return false;
			}
			//in addition to the page title, get the name space also if it exists.
			if (typeof wgCanonicalNamespace !== "undefined" && wgCanonicalNamespace.length > 0) {
				return wgCanonicalNamespace + ":" + wgTitle;
			}
			return wgTitle;
		}
	}
};

setTimeout(drGadget.drLoadGadget,1000);