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.
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.
/*** WikiBhasha* Copyright (C) 2010, Microsoft* * This program is free software; you can redistribute it and/or* modify it under the terms of the GNU General Public License version 2* as published by the Free Software Foundation.* * This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.* * You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.**/// ===UserScript===// @name wikiBhasha// @namespace wikiBhasha// @include http://*.wikipedia.org/*// ===/UserScript===//// WikiBhasha launch helper script.// Description: this script eases the procedure to launch WikiBhasha by instrumenting// wikipedia pages with links and options to launch the application. It executes the// same routine as the bookmarklet and is portable across Wikipedia installations.//// The current options to launch WikiBhasha are:// 1. Looks for "action=edit" in the URL and check if toolbar exists. if present adds a// icon to the toolbar for launching WikiBhasha.// 2. inserts a "WikiBhasha" option in the left side toolbox menu.// 3. Looks for "wbAutoLaunch=true" in the URL and launch WikiBhasha.varwbGadget={// 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 applicationwbLoadGadget:function(){varwikiBhashaUrl="javascript:(function(){if(!(document.getElementById('wbBlockParentUI'))){"+"if(location.href.match(/^(http|https):\\/\\/[A-Za-z\-]+\.(wikipedia.org)/)==null || mw.config.get('wgNamespaceNumber') != 0 ){"+"alert('Please select a valid article from wikipedia and invoke WikiBhasha (Beta).');return;}"+"this.baseUrl ='"+baseUrl+"';this.targetLanguageCode='en';"+"this.wikiSourceLanguage=typeof mw.config.get('wgUserLanguage') !== 'undefined' ? mw.config.get('wgUserLanguage') : '"+targetLanguageCode+"';"+"wbBookMarkletLinkDiv=document.createElement('div');"+"wbBookMarkletLinkDiv.id='wbLoadDiv';"+"wbBookMarkletLinkDiv.innerHTML='<div style=\"background-color:Black;color:#FFFFFF;position:absolute;text-align:center;font-size:13px;font-weight:bold;left:0px;top:0px;padding:10px 0;z-index:1000;width:100%;border-bottom:3px solid gray;\">Loading...</div>';"+"document.body.appendChild(wbBookMarkletLinkDiv);"+"wbBookMarkletScripts=document.createElement('script');"+"wbBookMarkletScripts.setAttribute('src','"+baseUrl+"js/main.js');"+"document.body.appendChild(wbBookMarkletScripts);"+"}})()";// looks for the Toolbar on edit pages, creates and appends a simple button in the format expected by the toolbarif((document.getElementById('toolbar')||document.getElementById('wikiEditor-ui-toolbar'))&&wbGadget.getUrlParam("action")=="edit"&&!(document.getElementById('iconWikiBhasha'))){varwbIcon=document.createElement("a");wbIcon.title="Launch WikiBhasha (Beta)";wbIcon.id="iconWikiBhasha";wbIcon.href=wikiBhashaUrl;wbIcon.innerHTML="<img src='"+baseUrl+"images/Square.png'>";if(document.getElementById('toolbar')){// Append the launch button to the default toolbarvartoolbar=document.getElementById('toolbar');if(toolbar.firstChild)toolbar.appendChild(wbIcon);}elseif(document.getElementById('wikiEditor-ui-toolbar')){varwbIconGroupDiv=document.createElement("div");wbIconGroupDiv.setAttribute('class','group group-format');wbIconGroupDiv.appendChild(wbIcon);// Append the launch button to the new type toolbarvartoolbar=document.getElementById('wikiEditor-ui-toolbar');if(toolbar.firstChild)toolbar.firstChild.appendChild(wbIconGroupDiv);}}// Checks for the "toolbox" section, usually present on lower left side of the page. This is displayed only if the// article page is being viewed and not if it's on an edit page.if(typeof(document.getElementById('p-tb').getElementsByTagName("div")[0].getElementsByTagName("ul")[0])!="undefined"&&(mw.config.get('wgUserLanguage')==targetLanguageCode||document.getElementById("ca-edit"))&&!(document.getElementById('toolbarLinkWikiBhasha'))){vartoolboxUL=document.getElementById('p-tb').getElementsByTagName("div")[0].getElementsByTagName("ul")[0];// construct the DOM as expected by the toolbox divvarliElem=document.createElement('li');varanchorElem=document.createElement('a');anchorElem.title="Launch WikiBhasha (Beta)";anchorElem.id="toolbarLinkWikiBhasha";anchorElem.href=wikiBhashaUrl;anchorElem.innerHTML="WikiBhasha (Beta)";liElem.appendChild(anchorElem);toolboxUL.appendChild(liElem);}// This is going to be used by the main application when the user launches it from an article// page, and will prevent the need for the user to click on the bookmarklet/button againif(wbGadget.getUrlParam("wbAutoLaunch")=="true"&&!(document.getElementById('wbLoadDiv'))){if(!(document.getElementById('wbBlockParentUI'))){if(location.href.match(/^(http|https):\/\/[A-Za-z\-]+.(wikipedia.org)/)==null||mw.config.get('wgNamespaceNumber')!=0){alert("Please select a valid article from wikipedia and invoke WikiBhasha (Beta).");return;}wikiSourceLanguage=typeofmw.config.get('wgUserLanguage')!=='undefined'?mw.config.get('wgUserLanguage'):targetLanguageCode;wbBookMarkletLinkDiv=document.createElement('div');wbBookMarkletLinkDiv.id='wbLoadDiv';wbBookMarkletLinkDiv.innerHTML='<div style="background-color:Black;color:#FFFFFF;position:absolute;text-align:center;font-size:13px;font-weight:bold;left:0px;top:0px;padding:10px 0;z-index:1000;width:100%;border-bottom:3px solid gray;">Loading...</div>';document.body.appendChild(wbBookMarkletLinkDiv);wbBookMarkletScripts=document.createElement('script');wbBookMarkletScripts.setAttribute('src',baseUrl+'js/main.js');document.body.appendChild(wbBookMarkletScripts);}}},getUrlParam:function(strParamName){varstrReturn="";varstrHref=window.location.href;if(strHref.indexOf("?")>-1){varstrQueryString=strHref.substr(strHref.indexOf("?")).toLowerCase();varaQueryString=strQueryString.split("&");for(variParam=0;iParam<aQueryString.length;iParam++){if(aQueryString[iParam].indexOf(strParamName.toLowerCase()+"=")>-1){varaParam=aQueryString[iParam].split("=");strReturn=aParam[1];break;}}}returnunescape(strReturn);}};varbaseUrl='http://www.wikibhasha.org/';vartargetLanguageCode='en';addOnloadHook(function(){setTimeout(wbGadget.wbLoadGadget,1000);});