User:Anilande/dr.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. |
![]() | Documentation for this user script can be added at User:Anilande/dr. |
// ===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);