User:Endo999/monobook.js

From OpenWetWare
Jump to: navigation, search
// does google toolbar like translation of words and selected text
// works on ie and firefox, epiphany, safari, chrome, and opera but still has bugs on
// Konqueror (in fact the code is disabled on Konqueror)
// selected text translation (up to 500 characters) only on IE, Firefox, and Epiphany, and chrome

// this has only been tested on the monobook skin


// default from and to language
// the languages must be the same as in google.language.Languages array.
// these are normally the international defaults but note:
//  portuguese: pt-PT
//  traditional chinese: zh-TW
//  simplified chinese: zh-CN
//
// must be set in this routine for dictionarylookup.js
/*
var SCLanguageDefaultTo = 'fr';
var SCLanguageDefaultFrom='en';
*/
var SCLanguageDefaultTo = 'fr';
var SCLanguageDefaultFrom='en';

// need to set document.domain here, each language should set this field here

document.domain = "en.wikipedia.org"




// default literals for system
// must be set in this routine for dictionarylookup.js
// the gadget manager can change these to the language he wishes
/*
var SCstrLanguage = "Language";
var SCstrSource = "Source";
var SCstrGoogle = "Google";
var SCstrCloseWindow = "Close Window";
var SCstrSelectLanguage = "Select Language(To)";
var SCstrWikipedialanguage = "Wikipedia language";
var SCstrDictionary = "Dictionary";
var SCstrWikipedia = "Wikipedia";
var SCstrPopupHelp = "Popup Help?";
var SCstrTurnOffPopups = "Turn Off Popups?";
var SCstrTurnOnPopups = "Turn On Popups?";
var SCstrTranslationPopups ="Translation Popups";
var SCstrOff = " - OFF";
var SCstrOn = " - ON";
var SCstrChangeOptions = "Change Options for Translation Popups";
var SCstrTranslatePage = "Google: Translate Page?";
var SCstrHelpUrl = 
"http://en.wikipedia.org/w/index.php?title=User:Endo999/dictionarylookuphelp.html&ctype=text/html";

var SCstrSingleWord = "Translation of single words";
var SCstrSelectedText = "Translation of selected text (>500 characters)";
var SCstrKonqueror = "This feature is not supported on Konqueror";
var SCstrTextTooLarge =  "Text Element too large to parse!";
var SCPopupBackgroundColor = "beige";

*/
var SCstrLanguage = "Language";
var SCstrSource = "Source";
var SCstrGoogle = "Google";
var SCstrCloseWindow = "Close Window";
var SCstrSelectLanguage = "Select Language(To)";
var SCstrWikipedialanguage = "Wikipedia language";
var SCstrDictionary = "Dictionary";
var SCstrWikipedia = "Wikipedia";
var SCstrPopupHelp = "Popup Help?";
var SCstrTurnOffPopups = "Turn Off Popups?";
var SCstrTurnOnPopups = "Turn On Popups?";
var SCstrTranslationPopups ="Translation Popups";
var SCstrOff = " - OFF";
var SCstrOn = " - ON";
var SCstrChangeOptions = "Change Options for Translation Popups";
var SCstrTranslatePage = "Google: Translate Page?";
var SCstrHelpUrl = 
"http://en.wikipedia.org/w/index.php?title=User:Endo999/dictionarylookuphelp.html&ctype=text/html";

var SCstrSingleWord = "Translation of single words";
var SCstrSelectedText = "Translation of selected text (>500 characters)";
var SCstrKonqueror = "This feature is not supported on Konqueror";
var SCstrTextTooLarge =  "Text Element too large to parse!";

var SCPopupBackgroundColor = "beige";  // you can set the popup background color here




appendCSS(
'.SCuserData { behavior:url(#default#userdata);} ' +

'#SCitem div small, #SCitem small,#SCitem div div small,#SCitem div div div small {font-size:65%;color:black}' +

'#SCitem div a:hover, #SCitem a:hover, #SCitem div div a:hover {text-decoration:underline;}' +

'.SCPopup {background-color:' + SCPopupBackgroundColor +';border: 1px solid blue;position:absolute;font-size:14pt;z-index:9999;' +'overflow:visible;line-height:normal;padding:.5em;display:block;}' +

'.SCxWindow {font-size:70%;color:black;' +
 'position:absolute;right:.5em;}'+
'.SCyWindow{font-size:50%;color:black;position:absolute;right:.5em;'+
'bottom:.5em}' +
'.SCxTranslation {font-size:70%;color:black;' +
'position:absolute;left:.5em;top;.5em;}' +
'.SCxText {color:black;}'+

'.SCPopupIE {position:absolute;background-color: ' +
 SCPopupBackgroundColor +
';border: 1px solid blue;font-size:14pt;z-index:9999; ' +
'overflow:visible;display:block;line-height:normal;padding:.5em;width:auto;}'
+
'.SChidestuff {display:none;}'

);

function SCGoogleLanguageLoaded() {
  
  SCMakeGoogleLanguages();
}

function SCloadGoogleLanguage() {
  google.load("language", "1", {"callback" : SCGoogleLanguageLoaded});
}

// this api key is not strictly necessary, but Google maintains they will email
// you if, for some reason, they withdraw the Google translation services
// the gadget manager is welcome to log onto code.google.com and get his own
// api key.  

var SCGoogleAPIKey = "ABQIAAAAIL6lIdsFmMh3QB6iZZYqHBT5zsu4IrEqi6aTPGb6EkJ6C2zK0BQyWgLmv16JfxNy3RYUKg7GyR6XAg";

importScriptURI("http://www.google.com/jsapi?callback=SCloadGoogleLanguage&key=" +
   SCGoogleAPIKey);


importScriptURI("http://en.wikipedia.org/w/index.php?title=User:Endo999/dictionarylookup1.js&action=raw&ctype=text/javascript");
 



addOnloadHook(
    function () {
        var span1 = document.createElement('DIV');
        span1.setAttribute('id','SCitem');
        var thebody = document.getElementsByTagName('BODY');
        thebody[0].appendChild(span1);

        var span2 = document.createElement('SPAN');
        span2.setAttribute('id','SCPersistElement');
        span2.setAttribute('class','SCuserData');
        thebody[0].appendChild(span2);

    }
);
var SCnewoptions;
function SCMakeGoogleLanguages()
{
 var l;
 var lcode;
 var newoptions = "";
 for (l in google.language.Languages)
 {
   lcode = google.language.Languages[l];
   if(google.language.isTranslatable(lcode))
   {
      newoptions += 
   '<option value="' + lcode + '">' + l + '</option>'+"\n";
   }
  SCnewoptions = newoptions;
 }
 
}