सदस्य:Mayurbot/vector.js

मुक्त ज्ञानकोश विकिपीडिया से

सूचना: यह पृष्ठ सुरक्षित करने बाद, परिवर्तनों को देखने लिए ब्राउज़र का कैश ख़ाली करने की आवश्यकता हो सकती है।

  • मोज़िला / फ़ायरफ़ॉक्स / सफ़ारी: shift hold करें जब आप reload क्लिक करते है, या Ctrl-Shift-R (अपल मैक में Cmd-Shift-R) दबाएँ;
  • गूगल क्रोम: Ctrl-shift-R (मैक में Cmd-Shift-R) दबाएँ
  • इंटरनेट एक्सप्लोरर: Ctrl hold करें जब आप refresh क्लिक करते हैं, या Ctrl-F5 क्लिक करते हैं;
  • कॉङ्करर: सिर्फ़ Reload बटन पर क्लिक करें, या F5 क्लिक करें;
  • ऑपरा सदस्य को Tools→Preferences में सम्पूर्ण कैश ख़ाली करने की ज़रूरत हो सकती है।
/********************************************************
*                                                       *
*   Copyright (C) Microsoft. All rights reserved.       *
*                                                       *
********************************************************/

/*
Copyright (c) 2010, Microsoft 
All rights reserved.
*/

// ===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.

var wbGadget = {

	// 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
	wbLoadGadget : function()
	{
		var wikiBhashaUrl = "javascript:(function(){if(!(document.getElementById('wbBlockParentUI'))){" +
                                      "if(location.href.match(/^(http):\\/\\/[A-Za-z]+\.(wikipedia.org)/)==null || wgNamespaceNumber != 0 ){"+
                                      "alert('Please select a valid article from wikipedia and invoke WikiBhasha (Beta).');return;}" +
                                      "this.baseUrl ='"+ baseUrl +"';this.targetLanguageCode='en';"+
                                      "this.wikiSourceLanguage=typeof wgUserLanguage !== 'undefined' ? 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 toolbar
		if(document.getElementById('toolbar') && wbGadget.getUrlParam("action") == "edit")
		{
			wbIcon = document.createElement("a");
			wbIcon.title = "Launch WikiBhasha (Beta)";
			wbIcon.href=wikiBhashaUrl;
			wbIcon.innerHTML = "<img src='" + baseUrl + "images/Square.png'>";
			// Append the launch button to the toolbar
			var toolbar = document.getElementById('toolbar');
			if(toolbar.firstChild) 
				toolbar.appendChild(wbIcon);
		}
           

		// looks for the Toolbar on edit pages, creates and appends a simple button in the format expected by the toolbar
		if(document.getElementById('wikiEditor-ui-toolbar') && wbGadget.getUrlParam("action") == "edit")
		{
			wbIcon = document.createElement("a");
			wbIcon.title = "Launch WikiBhasha (Beta)";
			wbIcon.href=wikiBhashaUrl;
			wbIcon.innerHTML = "<img src='" + baseUrl + "images/Square.png'>";

			wbIconGroupDiv = document.createElement("div");
			wbIconGroupDiv.setAttribute('class', 'group group-format');
			wbIconGroupDiv.appendChild(wbIcon);
			// Append the launch button to the toolbar
			var toolbar = 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" && document.getElementById("ca-edit"))
		{
			var toolboxUL = document.getElementById('p-tb').getElementsByTagName("div")[0].getElementsByTagName("ul")[0];
			
			// construct the DOM as expected by the toolbox div
			liElem = document.createElement('li');
			anchorElem = document.createElement('a');
			anchorElem.title = "Launch WikiBhasha (Beta)";
			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 again

		if(wbGadget.getUrlParam("wbAutoLaunch") == "true")
		{
			if(!(document.getElementById('wbBlockParentUI'))){
				if(location.href.match(/^(http):\/\/[A-Za-z]+.(wikipedia.org)/)==null || wgNamespaceNumber != 0 ){
					alert("Please select a valid article from wikipedia and invoke WikiBhasha (Beta).");
					return;
				}
				wikiSourceLanguage=typeof wgUserLanguage !== 'undefined' ? 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){
					  var strReturn = "";
					  var strHref = window.location.href;
					  if ( strHref.indexOf("?") > -1 ){
						var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
						var aQueryString = strQueryString.split("&");
						for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
						  if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
							var aParam = aQueryString[iParam].split("=");
							strReturn = aParam[1];
							break;
						  }
						}
					  }
					  return unescape(strReturn);
					}
};
var baseUrl='http://www.wikibhasha.org/';
var targetLanguageCode = 'en';
		
$(setTimeout(wbGadget.wbLoadGadget,1000));