i2pd website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
18 KiB

/* https://github.com/fabi1cazenave/webL10n */
"use strict";document.webL10n=(function(window,document,undefined){var gL10nData={};var gTextData="";var gTextProp="textContent";var gLanguage="";var gMacros={};var gReadyState="loading";var gAsyncResourceLoading=true;var gDEBUG=1;function consoleLog(message){if(gDEBUG>=2){console.log("[l10n] "+message)}}function consoleWarn(message){if(gDEBUG){console.warn("[l10n] "+message)}}function getL10nResourceLinks(){return document.querySelectorAll('link[type="application/l10n"]')}function getL10nDictionary(){var script=document.querySelector('script[type="application/l10n"]');return script?JSON.parse(script.innerHTML):null}function getTranslatableChildren(element){return element?element.querySelectorAll("*[data-l10n-id]"):[]}function getL10nAttributes(element){if(!element){return{}}var l10nId=element.getAttribute("data-l10n-id");var l10nArgs=element.getAttribute("data-l10n-args");var args={};if(l10nArgs){try{args=JSON.parse(l10nArgs)}catch(e){consoleWarn("could not parse arguments for #"+l10nId)}}return{id:l10nId,args:args}}function fireL10nReadyEvent(lang){var evtObject=document.createEvent("Event");evtObject.initEvent("localized",true,false);evtObject.language=lang;document.dispatchEvent(evtObject)}function xhrLoadText(url,onSuccess,onFailure){onSuccess=onSuccess||function _onSuccess(data){};onFailure=onFailure||function _onFailure(){consoleWarn(url+" not found.")};var xhr=new XMLHttpRequest();xhr.open("GET",url,gAsyncResourceLoading);if(xhr.overrideMimeType){xhr.overrideMimeType("text/plain; charset=utf-8")}xhr.onreadystatechange=function(){if(xhr.readyState==4){if(xhr.status==200||xhr.status===0){onSuccess(xhr.responseText)}else{onFailure()}}};xhr.onerror=onFailure;xhr.ontimeout=onFailure;try{xhr.send(null)}catch(e){onFailure()}}function parseResource(href,lang,successCallback,failureCallback){var baseURL=href.replace(/[^\/]*$/,"")||"./";function evalString(text){if(text.lastIndexOf("\\")<0){return text}return text.replace(/\\\\/g,"\\").replace(/\\n/g,"\n").replace(/\\r/g,"\r").replace(/\\t/g,"\t").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\{/g,"{").replace(/\\}/g,"}").replace(/\\"/g,'"').replace(/\\'/g,"'")}function parseProperties(text,parsedPropertiesCallback){var dictionary={};var reBlank=/^\s*|\s*$/;var reComment=/^\s*#|^\s*$/;var reSection=/^\s*\[(.*)\]\s*$/;var reImport=/^\s*@import\s+url\((.*)\)\s*$/i;var reSplit=/^([^=\s]*)\s*=\s*(.+)$/;function parseRawLines(rawText,extendedSyntax,parsedRawLinesCallback){var entries=rawText.replace(reBlank,"").split(/[\r\n]+/);var currentLang="*";var genericLang=lang.split("-",1)[0];var skipLang=false;var match="";function nextEntry(){while(true){if(!entries.length){parsedRawLinesCallback();return}var line=entries.shift();if(reComment.test(line)){continue}if(extendedSyntax){match=reSection.exec(line);if(match){currentLang=match[1].toLowerCase();skipLang=(currentLang!=="*")&&(currentLang!==lang)&&(currentLang!==genericLang);continue}else{if(skipLang){continue}}match=reImport.exec(line);if(match){loadImport(baseURL+match[1],nextEntry);return}}var tmp=line.match(reSplit);if(tmp&&tmp.length==3){dictionary[tmp[1]]=evalString(tmp[2])}}}nextEntry()}function loadImport(url,callback){xhrLoadText(url,function(content){parseRawLines(content,false,callback)},null)}parseRawLines(text,true,function(){parsedPropertiesCallback(dictionary)})}xhrLoadText(href,function(response){gTextData+=response;parseProperties(response,function(data){for(var key in data){var id,prop,index=key.lastIndexOf(".");if(index>0){id=key.substring(0,index);prop=key.substr(index+1)}else{id=key;prop=gTextProp}if(!gL10nData[id]){gL10nData[id]={}}gL10nData[id][prop]=data[key]}if(successCallback){successCallback()}})},failureCallback)}function loadLocale(lang,callback){if(lang){lang=lang.toLowerCase()}callback=callback||function _callback(){};clear();gLanguage=lang;var langLinks=getL10nResourceLinks();var langCount=langLinks.length;if(langCount===0){var dict=getL10nDictionary();if(dict&&dict.locales&&dict.default_locale){consoleLog("using the embedded JSON directory, early way out");gL10nData=dict.locales[lang];if(!
var url = "https://api.github.com/repos/PurpleI2P/i2pdbrowser/releases/latest";
7 years ago
//var url = "http://127.0.0.1:9889/latest.json";
function renderReleaseInfo(data) {
if (!data) return;
var release = JSON.parse(data);
var downloadCount = 0, dl_btn = document.getElementById("dl-btn"), all_dls = document.getElementById("all-dls");
for (var i = 0; i < release.assets.length; i++)
downloadCount += release.assets[i].download_count;
console.log(release.name+" downloaded "+downloadCount.toLocaleString()+" times.");
if (window.navigator.platform.toUpperCase().startsWith("WIN")) {
var win_asset = release.assets.filter(function(a) {
if (a.name.startsWith("I2PdBrowser") && a.name.endsWith("exe"))
return true;
});
if (win_asset.length > 0) {
dl_btn.innerText = document.webL10n.get("header-dl-btn-windows");
dl_btn.setAttribute("href", win_asset[0].browser_download_url);
all_dls.style.display = "block";
}
/*
} else if (window.navigator.userAgent.toUpperCase().indexOf("ANDROID") !== -1) {
var droid_asset = release.assets.filter(function(a) {
if (a.name.toUpperCase().indexOf("ANDROID") !== -1) return true;
});
if (droid_asset.length > 0) {
dl_btn.text(document.webL10n.get("header.dl-btn-android"));
dl_btn.setAttribute("href", droid_asset[0].browser_download_url);
all_dls.show();
}
*/
} else {
dl_btn.innerText = document.webL10n.get("header-dl-btn");
}
}
window.addEventListener('localized', function() {
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function(){
if (httpRequest.readyState == XMLHttpRequest.DONE)
renderReleaseInfo(httpRequest.responseText);
}
httpRequest.open('GET', url);
httpRequest.send();
}, false);