Benutzer:WikiBhasha.MSR/WikiBhasha.js
Erscheinungsbild
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
/********************************************************
* *
* 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));