#ß UTF-8 K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage2)
#
# ---------------------- troubleshoot_prefs.kmm   ----------------------
#  Creates a plain report page to show current settings of some important prefs 
#  (useragent, cookies, referer, storage, SSL etc.), installed adblockers, with 
#  links to some configuration sheets, error console, addons, profile folder, 
#  it lists automatic macro actions after each page load, contains little tips 
#  about the usual suspects for troubleshooting etc.
#
#  It does NOT change any settings, only sets "general.warnOnAboutConfig=false".
#  And it can NOT figure out reasons and solutions.
#  It's purely informational and meant mainly for users, who are not completely 
#  clueless but don't quite know where to start looking for possible probs.
#  The upper part with confusing details about K-Meleon version, UA etc. can be 
#  copied into the forum when asking for help, sometimes this helps the supporters.

#  Version :   		V11  /  2018-03-09 / by siria (with help for version.ini and fix for about-links by Anon.)
#  Menu:  		Help > Troubleshooting INFO
#  Forum:  		http://kmeleonbrowser.org/forum/read.php?9,142878
#  K-Meleon version:   1.5.4 (partly) - today (KM-Goanna 77) -  future probably too
# ------------------------------------------------------------------------

# example UA for FF50 on Win10:
# Mozilla/5.0 (Windows NT 10.0; rv:50.0) Gecko/20100101 Firefox/50.0

troubleshootprefs{
macroinfo=_("Show a plain report page with some current settings, links and tips for troubleshooting");
$_trbprf_vini=iniread("Version","LastVersion","", getfolder(ProfileFolder)."\\version.ini");
#
# KM7X:  First show  single mini-alert with current UA, if macro started on http-site
# May report with which UA a page was loaded, for site-exceptions or if UA was meanwhile toggled
$_trbprf_UAFake=getpref(STRING,"general.useragent.override");
if ($_trbprf_vini>"30000000") {
	if (index($URL,"http")==0) {
		$_x=injectJS("(function(){return navigator.userAgent;}())");
		if ($_x>"") {
			if ($_x != $_trbprf_UAFake) {
				$_x=hostname($URL)."\n\n".$_x;
				alert($_x,"UserAgent:");
				}}
		else injectJS("(function(){return navigator.userAgent;}())");
}}
# Needed to get DEFAULT useragent, string will be restored after report is finished
delpref("general.useragent.override");
# OPEN new empty page for filling in the report after $OnLoad
# Only a chrome link allows to open "about:" links with normal LEFT-click, and only since KM1.6
$OpenURL="chrome://console2/content/blank.html";
$_trbprf_vini<"17170000" ? $OpenURL="resource:///res/hiddenWindow.html" : 0;
&OpenURL_InNew;
# too buggy:  $OnLoadOnce=$OnLoadOnce."_troubleshootprefs_collect;";
$OnLoad=$OnLoad."_troubleshootprefs_collect;";
}

_troubleshootprefs_collect{
$OnLoad=gsub("_troubleshootprefs_collect;","",$OnLoad);
# Check if injectJS works and/or can return something:
$_x=injectJS("(function(){var x='999'; return x;})()");
if ($_x=="999") {
	$_injJSret="true";
	$_injJSretxt="Macros:  injectJS returns OK";
}else{
	$_injJSret="false";
	$_injJSretxt="Macros:  injectJS no return";
	injectJS("(function(){var x=document.location.href; document.location.href=x+'#trbprfinfo';})()");
	index($URL,"#trbprfinfo")> 0 ? 0 : $_injJSretxt="Macros:  NO injectJS";
}
$_txt="(V11. "._("Upper part may help for support in forum etc.").")  Question: Is this LINUX-Wine? YES/NO\n";
#
&_troubleshootprefs_getKMver;
$_txt=$_txt."\n".$_kmVer;
$_txt=$_txt."\n".$_injJSretxt;
#
# $_txt=$_txt."\n----------";
$_txt=$_txt."\n";
#
$_x=getfolder(RootFolder); $_y=getfolder(ProfileFolder);
index($_y,$_x)==0 ? $_x="<b>Profile</b> inside KM (portable)" : $_x="<b>Profile</b> outside KM";
$_txt=$_txt."\n".$_x;
$_x=getpref(STRING,"kmeleon.general.skinsCurrent");
$_txt=$_txt."\nSkin: \"".$_x."\"  /  Privacy Toolbar: ";
# Prob-1:  If the toolbar was never MOVED by user, there don't exist ANY prefs yet!
# Prob-2:  when using ANOTHER skin, the prefs of the old one STAY,  incl. visibility=true!
if (getpref(BOOL,"kmeleon.toolband.&Privacy Bar.visibility")==true) $_x="visible=true (if in skin?)";
else $_x=(getpref(INT,"kmeleon.toolband.&Privacy Bar.size")? "visible=false (if in skin?)" : "not found (or not moved?)");
$_txt=$_txt.$_x;
#
&_trbprf_getLang;
$_txt=$_txt."\n".$_lang;
#
&_trbprf_getOSCPU;
$_txt=$_txt."\n".$_oscpu;
#
#$_txt=$_txt."\n----------";
$_txt=$_txt."\n";
#
$_ua=$_trbprf_UAFake;
$_txt=$_txt."\n<b>GENERAL.USERAGENT.OVERRIDE</b> (fake) = ";
if ($_ua=="") $_txt=$_txt."  ( -- )";
else { length($_ua)<90 ? $_txt=$_txt.$_ua : $_txt=$_txt."\n.... ".$_ua; }
# $_txt=$_txt."\n<b>DEFAULT UA</b> (JS) NAVIGATOR.USERAGENT = \n....  $navUA ";
$_txt=$_txt."\n<b>DEFAULT UA</b>  =  $navUA ";
$_txt=$_txt."\ngeneral.useragent.site_specific_overrides = ";
$_txt=$_txt.(getpref(BOOL,"general.useragent.site_specific_overrides")? "true":"false")."  (KM77 or hacked 75..: ...agent.override.example.com=Moz...)";
$_x=getpref(BOOL,"general.useragent.compatMode.firefox");
$_txt=$_txt."\ngeneral.useragent.compatMode.firefox  =  ";
$_x==true ? $_txt=$_txt."true   (UA= Gecko+Firefox+KM)   (KM74-76 / for addons?)" : 0;
$_x==false ? $_txt=$_txt."false   (UA= Gecko+KM)   (KM74-76 / for addons?)" : 0;
if ($_eng=="Goanna") {
	$_x=getpref(INT,"general.useragent.compatMode");
	$_txt=$_txt."\ngeneral.useragent.compatMode  =  ".$_x;
	$_x==0 ? $_txt=$_txt."  (UA= Goanna+KM)" : 0;
	$_x==1 ? $_txt=$_txt."  (UA= Gecko+Goanna+KM)" : 0;
	$_x==2 ? $_txt=$_txt."  (UA= Gecko+Goanna+FF+KM)" : 0;
	}
$_txt=$_txt."\nkmeleon.install_firefox_extension  =  ";
$_txt=$_txt.(getpref(BOOL,"kmeleon.install_firefox_extension")? "true":"false")."  (KM74-76)";
# Blocks NEW installs. Already installed ones keep working
$_txt=$_txt."\nxpinstall.enabled  =  ";
$_txt=$_txt.(getpref(BOOL,"xpinstall.enabled")? "true":"false")."  (KM7X, allow more xpi-Addons)";
#
# no effect in Goanna acc moonchild palemoon forum / only used for some loading function, not relevant Goanna
# But possibly affects older KM-versions, with hacked omni or custom extensions? 
#$_txt=$_txt."\ngeneral.useragent.enable_overrides  =  ";
#$_txt=$_txt.(getpref(BOOL,"general.useragent.enable_overrides")? "true":"false");
#
$_x=getpref(INT,"kmeleon.privacy.useragent.Count");
if ($_x>0) $_txt=$_txt."\nkmeleon.privacy.useragent.Count = ".$_x."   (old auto-switcher, needs jar or hacked omni. 0=off=global UAs possible)";
#
# $_txt=$_txt."\n----------";
#
&_trbprf_getAdblocks;
$_txt=$_txt."\n\n".$_ads;
#
# $_txt=$_txt."\n----------";
$_txt=$_txt."\n\n<b>SOME SINGLE SETTINGS:</b>";
#
$_txt=$_txt."\njavascript.enabled  =  ";
$_txt=$_txt.(getpref(BOOL,"javascript.enabled")? "true":"false");
$_txt=$_txt."\nsignon.autofillForms  =  ";
$_txt=$_txt.(getpref(BOOL,"signon.autofillForms")? "true":"false")."   (Autofill form fields, Logins)";
$_txt=$_txt."\nsignon.rememberSignons  =  ";
$_txt=$_txt.(getpref(BOOL,"signon.rememberSignons")? "true":"false")."   (Remember Passwords)";
#  True = calling "Save As..." tosses files silently into last used (forgotten?) place 
if (getpref(BOOL,"kmeleon.download.useSaveDir")) {
	$_txt=$_txt."\nkmeleon.download.useSaveDir = true  => Silent downloads into:\n...  ";
	$_txt=$_txt.getpref(STRING,"kmeleon.download.saveDir");
}else $_txt=$_txt."\nkmeleon.download.useSaveDir = false    (true=Silent downloads)";
#
if (getpref(BOOL,"kmeleon.download.useDownloadDir")) {
	$_txt=$_txt."\nkmeleon.download.useDownloadDir = true  => ";
	$_x=getpref(STRING,"kmeleon.download.dir");
	if ($_x>"") $_txt=$_txt."into ".$_x;
	else $_txt=$_txt."Silently into Downloads folder";
}else $_txt=$_txt."\nkmeleon.download.useDownloadDir = false    (true=Silent downloads)";
#
#  Save COOKIES ?  0 (=Yes)  1 (=only from same domain)  2 (=No)   8 (=session only)
$_txt=$_txt."\nnetwork.cookie.cookieBehavior  =  ";
$_txt=$_txt.getpref(INT,"network.cookie.cookieBehavior")."   (0=all, 1=domain, 2=none, 3=special, 8=session?)";
#  Send HTTP-REFERER info  (where you arrive from, from which previous page and link)
#  0 (=No)  1 (=Yes when clicking links)  2 (=Yes from clicking links or loading images)
$_txt=$_txt."\nnetwork.http.sendRefererHeader  =  ";
$_txt=$_txt.getpref(INT,"network.http.sendRefererHeader")."   (HTTP  0=No, 1=links, 2=links+images)";
#  Send HTTPS-REFERER (encrypted pages) to other https sites:  true or false
$_txt=$_txt."\nnetwork.http.sendSecureXSiteReferrer  =  ";
$_txt=$_txt.(getpref(BOOL,"network.http.sendSecureXSiteReferrer")? "true":"false")."    (HTTPS, Logins)";
#  Block websites from exchanging pics by JS. Important for some maps, captchas etc.
$_txt=$_txt."\ndom.disable_image_src_set  =  ";
$_txt=$_txt.(getpref(BOOL,"dom.disable_image_src_set")? "true":"false")."   ('true' can block maps, captchas etc)";
$_txt=$_txt."\nkmeleon.plugins.gestures.load  =  ";
$_txt=$_txt.(getpref(BOOL,"kmeleon.plugins.gestures.load")? "true   (captcha probs?)":"false");
if ($_trbprf_vini>"33554439") {
	# since KM74beta4up1 = 33554440
	$_txt=$_txt."\nbrowser.sessionstore.restore_on_demand  =  ";
	$_txt=$_txt.(getpref(BOOL,"browser.sessionstore.restore_on_demand")? "true":"false");
	}
$_txt=$_txt."\nsecurity.enable_ssl3  =  ";
$_txt=$_txt.(getpref(BOOL,"security.enable_ssl3")? "true":"false")."    (old unsafe)";
$_t=getpref(INT,"security.tls.version.max");
if ($_t==0) {
	$_txt=$_txt."\nsecurity.enable_tls  =  ";
	$_txt=$_txt.(getpref(BOOL,"security.enable_tls")? "true":"false");
	}
$_txt=$_txt."\nsecurity.tls.version.min/max = ";
$_txt=$_txt.getpref(INT,"security.tls.version.min")."/".getpref(INT,"security.tls.version.max");
$_txt=$_txt."  (0=SSL3, 1=TLS 1.0, 2=1.1, 3=1.2, 4=1.3)";
$_txt=$_txt."\n    (If TLS set too low, or ancient KM version (max TLS1.0), gives 'ssl_error_<b>no_cypher_overlap</b>')";
#
$_txt=$_txt."\ndom.storage.enabled  =  ";
$_txt=$_txt.(getpref(BOOL,"dom.storage.enabled")? "true":"false")."    (huge 'supercookies' in profile)";
$_txt=$_txt."\ndom.indexedDB.enabled = ";
$_txt=$_txt.(getpref(BOOL,"dom.indexedDB.enabled")? "true":"false")."  (false: prob Google Drive, Dropbox, Wheather etc., default size no limit)";
# $_txt=$_txt.(getpref(BOOL,"permissions.default.indexedDB")? "true":"false")."    (Which now???)";
$_txt=$_txt."\npermissions.default.subdocument = ";
$_txt=$_txt.getpref(INT,"permissions.default.subdocument")."   (0 or 1=allow, 2=block, 3=same site)  Frames, iFrames";
$_txt=$_txt."\npermissions.default.media = ";
$_txt=$_txt.getpref(INT,"permissions.default.media")."  (01/2/3 dto.)  <b>HTML5  Video</b>, one of lots media prefs";
#  Object: controls <EMBED> and <OBJECT> tags, like PLUGIN content.  JS not needed (unlike for Flashblock)
#  Blocking does NOT work if a movie etc. is called directly, only if embedded in a webpage
$_txt=$_txt."\npermissions.default.object = ";
$_txt=$_txt.getpref(INT,"permissions.default.object")."  (01/2/3 dto.) <b>embedded</b> Plugins, like <b>Flash</b> video (only if EMBED or OBJECT tags!)";
$_txt=$_txt."\nplugin.load_flash_only = ";
$_txt=$_txt.(getpref(BOOL,"plugin.load_flash_only")? "true":"false")."  (KM77: true=only Flash, false=load all NPAPI-Plugins, Java, Silverlight, etc.)";
# PDF:   http://www.klaus-hartnegg.de/gpo/2014-08-21_Firefox_steals_pdf.html
# Doworks in KM already or not? But off by default, so no prob.
$_txt=$_txt."\npdfjs.disabled  =  ";
$_txt=$_txt.(getpref(BOOL,"pdfjs.disabled")? "true  (=open PDF external)":"false  (=open PDF in browser with javascript)")."  (KM7X, works or not?)";
#  was that hardware acceleration? Some prob with black flashing tabs?
$_txt=$_txt."\nlayers.offmainthreadcomposition.enabled  =  ";
$_txt=$_txt.(getpref(BOOL,"layers.offmainthreadcomposition.enabled")? "true":"false")."   ('true' can flash black?)";
$_txt=$_txt."\nlayers.acceleration.disabled  =  ";
$_txt=$_txt.(getpref(BOOL,"layers.acceleration.disabled")? "true":"false");
#$_txt=$_txt."\n----------";
$_txt=$_txt."\n\n<hr>";
#
$_txt=$_txt."\n<b>Automatic macro actions</b> after every page load (created in *.kmm files).\nExecuted in that order:\n\n".gsub(";","\n",$OnLoad);
#$_txt=$_txt."\n\n----------";
$_txt=$_txt."\n<hr>";
#
&_trbprf_addLinks;
$_txt=$_txt."\n".$_links;
#
&_troubleshootprefs_write;
}

_troubleshootprefs_write{
$_trbpTXT=$_txt;
# Replace all quotes " with single quote ' to avoid JS probs.  Escape more? which?
$_trbpTXT=gsub("\"","'",$_trbpTXT);
# <br> are linebreaks in page display,   \\n in source-code
$_trbpTXT=gsub("\n"," <br>\\n",$_trbpTXT);
$_trbpTXT=gsub("  "," &nbsp;",$_trbpTXT);
$_trbpSRC="<!DOCTYPE HTML><html>\\n<title>troubleshootprefs (V11)</title>\\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\\n";
$_trbpSRC=$_trbpSRC."<style type='text/css'> html {background-color: #fff4b8; margin: 20px; font-family: sans-serif;}</style>\\n\\n";
$_trbpSRC=$_trbpSRC.$_trbpTXT." \\n<br><br><br></html>";
# alert($_html,"$_html debug");
#
$_trbpCode="var page=\"".$_trbpSRC."\"; ";
$_trbpCode=$_trbpCode."var x=navigator.oscpu; page=page.replace('$NavOscpu',x); ";
$_trbpCode=$_trbpCode."var y=navigator.userAgent; page=page.replace('$navUA',y); ";
$_trbpCode=$_trbpCode.$_trbprf_CODE_vini." page=page.replace('$_trbprf_vini',z); ";
#
$_trbpCode=$_trbpCode."document.documentElement.innerHTML=page; document.close(); ";
$_trbprfFIN="(function() {".$_trbpCode."})()";
# alert($_code,"$_code debug");
injectJS($_trbprfFIN);
#
# workaround for KM1.7 alpha bug, no injectJS at all, needs open(JS)
if (index($_injJSretxt,"Macros:  NO injectJS")==0) {
	if (getpref(BOOL,"javascript.enabled")==false) {
		$_x=confirm("Function injectJS seems broken in this (beta?) KM-version.\n\nEnable Javascript?","Workaround needs Javascript",OKCANCEL,STOP); 
		$_x=="OK" ? setpref(BOOL,"javascript.enabled",true) : 0;
		}
	open("javascript:".$_trbprfFIN);
}
if (confirm("Opens Error Console, \nabout:addons, \nprofile folder, etc.\n\n(Or use the links at the bottom of this page)","SHOW MORE ?",OKCANCEL,"")=="OK") &_troubleshootprefs_openMORE;
else &_trbprf_restoreUA;
&_trbprf_resetVars;
}

#---------------------------------  Config Links

_trbprf_addLinks{
$_links="Also check menu:  Tools > Privacy";
$_links=$_links."\n";
$_x=getfolder(ProfileFolder); $_x="file:///".gsub("\\","/",$_x);
$_links=$_links."\n<a href=\'".$_x."'><b>Profile</b></a>  Edit > Configuration > Profile Directory";
$_links=$_links."    (check sessions, bookmarks, storage, adblock, ...)";
$_links=$_links."\n   -   prefs.js = current settings, unless identic to default (will be deleted). Shown bold on about:config";
$_links=$_links."\n   -   user.js = <b>startup settings</b>. Restored at every browser start. No automatic deletion, comments possible.";
$_links=$_links."\n         (Menu:  Edit > Configuration > User Settings)";
$_links=$_links."\nDo not manually edit prefs.js while K-Meleon is open, or your changes will be lost.";
$_links=$_links."\nYour edited file gets ignored completely? Check for syntax errors, semi-colons, missing linebreak at end etc.";
$_links=$_links."\n";
	$_trbprf_vini<"17170000" ? $_x="* " : $_x="";
$_links=$_links."\n".$_x."<a href=\'chrome://console2/content/console2.xul'><b>Error Console</b></a>  Enable <b>ALL</b> types in upper left corner. KMM=<b>Macro Errors</b> (macrolanguage, not css or js)";
$_links=$_links."\n.... (Menu Tools > Error Console, or show button: View>Toolbars>Javascript Console)";
$_links=$_links."\n\n<hr>";
#
# normal page links on bottom of report page
$_links=$_links."\n<b>Some lesser known Configuration Links</b> (of many)     Main configuration: <b>F2</b>";
$_links=$_links."\n";
$_links=$_links."\nImportant:\nThe browser engine inside K-Meleon (Gecko or Goanna) comes with countless native prefs and 'about:' settings pages. Most, but <b>not all</b> of them are used by K-Meleon too, although they may be visible. This can be confusing, but the K-Meleon GUI is slightly neglected since many years. There are some newer Gecko-functions which actually work like in Firefox too, but they didnt make it into the GUI yet, so you must know which prefs to toggle manually in about:config, or even have to create those prefs first. On the other hand KM has inherited a bunch of new Gecko prefs and ABOUT-pages from the engine, which you can see, but not everything has a function or is meant to in KM. A few features are either intentionally cropped (like WebRTC), or K-Meleon uses own modules and other prefs instead (like Search macro), or just not finished yet.\nThe K-Meleon configuration is traditionally found in menu Edit>Preferences (F2) and Edit>Configuration.\nThe ABOUT-pages are inherited from the engine, and except aboutconfig rather new in KM (like about:addons)\nThis macro is also meant for use in all KM-versions from KM1.5.4 until 77 or later, but what works or not in which one isn't always clear.";
$_links=$_links."\n";
$_links=$_links."\n<hr>";
if ($_trbprf_vini<"17170000") {
	# Old KM 1.5 blocks left-click on about-links, security error. Since KM1.6 allowed, but only on "chrome" page
	$_links=$_links."\n<b>* => IMPORTANT:</b> Internal links only work with <b>MIDDLE-click</b> or RIGHT-click, or CTRL+LEFT-click";
	}
$_links=$_links."\n";
$_links=$_links."\n<a href=\'about:addons'>about:addons</a>  (KM7X) Firefox <b>Addons</b>, XPI";
$_links=$_links."\n<a href=\'about:support'>about:support</a>  (KM7X) <b>Mozilla troubleshooting</b> info";
$_links=$_links."\n";
$_links=$_links."\n<a href=\'about:config'>about:config</a>  (Viewing is harmless. Backup possible, copy prefs.js in current profile folder)";
$_links=$_links."\n<a href=\'about:config?filter=/adblock.*;/i'>about:config filter:</a>  /<b>adblock</b>.*;/i";
$_links=$_links."\n<a href=\'about:config?filter=/download.*;/i'>about:config filter:</a>  /<b>download</b>.*;/i";
$_links=$_links."\n<a href=\'about:config?filter=/(video.*;|media.*;|html5.*;|flashblock.*;|\.flash.*;)/i'>about:config filter:</a>  /(<b>video</b>.*;|media.*;|html5.*;|flashblock.*;|\.flash.*;)/i";
$_links=$_links."\n<a href=\'about:config?filter=/(update.*;|report.*;|url.*;)/i'>about:config filter:</a>  /(<b>update</b>.*;|report.*;|url.*;)/i";
$_links=$_links."\n<a href=\'about:config?filter=/(permission.*;|javascript.*;)/i'>about:config filter:</a>  /(<b>permission</b>.*;|javascript.*;)/i";
$_links=$_links."\n";
$_links=$_links."\n<a href=\'about:permissions'>about:permissions</a>  (KM75?) native Mozilla, works partly in KM (PREFS work in old KM too: <b>permissions.default.xxx</b>)";
$_links=$_links."\n<a href=\'about:memory'>about:memory</a>  (KM7X) Check <b>RAM</b> in tabs etc.";
$_links=$_links."\n<a href=\'about:about'>about:about</a>  List of all About pages for KM-version";
$_links=$_links."\n";
$_links=$_links."\n<a href=\'chrome://kmprefs/content/pref.xul?filetypes'>KM Prefs (F2): File Handling</a>  Download options   (For mimetypes better try below or install rvjMimeEdit)";
$_links=$_links."\n<a href=\'about:preferences#applications'>about:preferences</a>  (KM75?) <b>File Types, Page Colors, Link Style</b>. Rest only partly for KM (use F2)";
$_links=$_links."\n";
$_links=$_links."\n";
$_links=$_links."\n<b>HTTPS security SSL/TLS Certificates</b>";
$_links=$_links."\n<a href=\'chrome://kmprefs/content/pref.xul?encryption'>KM Prefs (F2): Encryption</a>  (2 Tabs)";
$_links=$_links."\n<a href=\'chrome://pippki/content/certManager.xul'>KM Prefs (F2): Cert Manager</a>  (Exceptions in tab3)  Tools>Privacy> View Data > View Cert.";
$_links=$_links."\n<a href=\'https://www.howsmyssl.com'>www:  howsmyssl.com</a>  Test certificates cyphers etc.";
$_links=$_links."\n";
$_links=$_links."\n<hr>";
$_links=$_links."\n";
$_links=$_links."\n<a href=\'http://kb.mozillazine.org/Error_loading_websites'>www:  mozillazine.org</a>  Mozilla tips to fix broken websites";
$_links=$_links."\n<a href=\'http://kmeleonbrowser.org/wiki/FAQ'>www:  K-Meleon FAQ</a>  (ENGLISH partly updated, other languages much older)";
$_links=$_links."\n<a href=\'http://kmeleonbrowser.org/forum/'>www:  K-Meleon Forum</a>";
$_links=$_links."\n";
$_links=$_links."\n<b>To solve browser problems</b> it sometimes helps to clear cache, clear cookies, ";
$_links=$_links."\nchange UserAgent (by macro, attention there can be several conflicting methods), ";
$_links=$_links."\nrestart the browser, restart system, check Adblock settings, proxies, ";
$_links=$_links."\n<b>check write permission</b> in profile and in KM program folder (toolbars.cfg), ";
$_links=$_links."\ndelete the startupCache in Profile folder (KM7X), ";
$_links=$_links."\ncheck external antivirus tools, CCleaner etc.";
$_links=$_links."\nIn a few cases non-ASCII URLs in session lists have blocked startup (older KM)";
$_links=$_links."\n";
$_links=$_links."\n<b>Or 'lost' the whole profile</b>?";
$_links=$_links."\nKM looks for profiles in 2 locations: system user folder or KM program folder. ";
$_links=$_links."\nWhere it looks, depends from the existence of an empty file 'profile.ini' in KM folder.";
$_links=$_links."\nCreate it manually (=<b>portable</b>) or delete it (=installed) to switch, then restart.";
$_links=$_links."\nIt's also possible to have several profiles in each location (Edit > Manage Profiles)";
$_links=$_links."\nLook inside profile folders with menu Edit>Configuration>Profile Directory.";
$_links=$_links."\n\n\n";
}


_trbprf_restoreUA{
if ($_trbprf_UAFake=="") delpref("general.useragent.override");
else setpref(STRING,"general.useragent.override",$_trbprf_UAFake);
}

_troubleshootprefs_openMORE{
&_trbprf_restoreUA;
# open next links if confirm "Open More?" is YES:
setpref(BOOL,"general.warnOnAboutConfig",false); 
$_trbprf_vini>"30000000" ? &_trbprf_openMORE7X : &_trbprf_openMORE1X;
}

_trbprf_openMORE7X{
$OpenURL="about:about"; &OpenURL_InNew;
$OpenURL="about:config"; &OpenURL_InNew;
$OpenURL="about:memory"; &OpenURL_InNew;
# Permissions+Preferences Sheets since roughly KM75? 
$OpenURL="about:permissions"; $_trbprf_vini>"33619970" ? &OpenURL_InNew : 0;
$OpenURL="about:preferences#applications"; $_trbprf_vini>"33619970" ? &OpenURL_InNew : 0;
$OpenURL="about:support"; &OpenURL_InNew;
$OpenURL="about:config?filter=/(update.*;|report.*;|url.*;)/i"; &OpenURL_InNew;
$OpenURL="about:config?filter=/(permission.*;|javascript.*;)/i"; &OpenURL_InNew;
$OpenURL="about:config?filter=/(video.*;|media.*;|html5.*;|flashblock.*;|\.flash.*;)/i"; &OpenURL_InNew;
##### add "save" ? or "ask"? 
$OpenURL="about:config?filter=/download.*;/i"; &OpenURL_InNew;
$OpenURL="about:config?filter=/adblock.*;/i"; &OpenURL_InNew;
$OpenURL="about:addons"; &OpenURL_InNew;
&_trbprf_openMORE2;
}

_trbprf_openMORE2{
# mimeTypes config in F2 very buggy since ages, in newer KM better use about:preferences
$_trbprf_vini<"33619971" ? opennew("chrome://kmprefs/content/pref.xul?filetypes"):0;
# Profile Folder, Error Console, settings for Downloads / etc
macros("cfg_ProfileDir");
opennew("chrome://console2/content/console2.xul");
}

_trbprf_openMORE1X{
# config FILTER in URL only works in KM7X.  In KM1.X workaround with clipboard (needs Foreground)
# Prob:  in KM1.5.4 no REGEX-filter possible => always empty
# $OnLoadOnce too buggy
# Weirdest bug: impossible to open those 2 first, or the rest doesn't work without 
# yet another waiting step (testalerts show first c then b then a ?!)
$OpenURL="about:about"; &OpenURL_InNew;
$OpenURL="about:config"; &OpenURL_InNew;
$OnLoad=$OnLoad."_trbprf_aboutCfg1X_0;";
}
_trbprf_aboutCfg1X_0{ 
if ($URL=="about:config") {
	$OnLoad=sub("aboutCfg1X_0;","aboutCfg1X_a;",$OnLoad);
	$OpenURL="about:config"; $_fltr="/(update.*;|report.*;|url.*;)/i"; 
	&OpenURL_InNew;
}}
_trbprf_aboutCfg1X_a{ 
setclipboard($_fltr); id(ID_EDIT_PASTE); 
$OnLoad=sub("aboutCfg1X_a;","aboutCfg1X_b;",$OnLoad);
if ($_trbprf_vini<"17170436") alert("Prob:\nIn very old K-Meleon 1.5.4 the filter only works for \nsimple words, no regex. Please change it manually.","about:config FILTER",EXCLAIM);
$OpenURL="about:config"; $_fltr="/(permission.*;|javascript.*;)/i"; 
&OpenURL_InNew;
}
_trbprf_aboutCfg1X_b{ 
setclipboard($_fltr); id(ID_EDIT_PASTE); 
$OnLoad=sub("aboutCfg1X_b;","aboutCfg1X_c;",$OnLoad);
$OpenURL="about:config"; 
$_trbprf_vini<"17170436" ? $_fltr="download" : $_fltr="/download.*;/i"; 
&OpenURL_InNew;
}
_trbprf_aboutCfg1X_c{ 
setclipboard($_fltr); id(ID_EDIT_PASTE); 
$OnLoad=sub("aboutCfg1X_c;","aboutCfg1X_d;",$OnLoad);
$OpenURL="about:config"; 
$_trbprf_vini<"17170436" ? $_fltr="adblock" : $_fltr="/adblock.*;/i"; 
&OpenURL_InNew;
}
_trbprf_aboutCfg1X_d{ 
setclipboard($_fltr); id(ID_EDIT_PASTE); 
$OnLoad=sub("aboutCfg1X_d;","aboutCfg1X_e;",$OnLoad);
$OpenURL="about:config"; 
$_fltr="/(video.*;|media.*;|html5.*;|flashblock.*;|\.flash.*;)/i"; 
&OpenURL_InNew;
}
_trbprf_aboutCfg1X_e{ 
setclipboard($_fltr); id(ID_EDIT_PASTE); 
$OnLoad=sub("_trbprf_aboutCfg1X_e;","",$OnLoad);
&_trbprf_openMORE2;
}
#---------------------------------------------------

_trbprf_getAdblocks{
$_ads="<b>ADBLOCKERS:</b>";
#  Very basic CSS-adblock included out-of-box, in 2017 still dating from 2006 and lots of false positives:
$_ads=$_ads."\nAd1-CSS:  kmeleon.adblocking = ";
$_ads=$_ads.(getpref(BOOL,"kmeleon.adblocking")? "true":"false")."   (profile/chrome/adblock.css)";
#------------
#  BAB = "Basic" adblock kplugin, included out-of-box in some KM-versions:
$_pref="kmeleon.plugins.adblock.load"; 
#  What if addons/kplugins don't exist, but prefs are still TRUE in profile? Created by macro or manually?
getpref(BOOL,$_pref) ? $_x="true" : $_x="false";
$_y=readfile(getfolder(RootFolder)."\\kplugins\\adblock.dll"); 
if (($_x=="true") and ($_y=="")) $_x="true = ERROR: dll missing";
else $_y=="" ? $_x="not installed" : 0;
$_ads=$_ads."\nAd2-BAB:  ".$_pref." = ".$_x."  (kplugins/adblock.dll)";
$_y=index($macroModules,"Adblockplugin;");
if (($_x==true) or ($_y>-1)) { 
	$_ads=$_ads."\nAd2         kmeleon.plugins.adblock.disabled  =  ";
	$_ads=$_ads.(getpref(BOOL,"kmeleon.plugins.adblock.disabled")? "true  (=".$off.")":"false  (=active)");
	$_ads=$_ads."\nAd2         macro for menu+button ".($_y>-1 ? $on : "missing (Adblockplugin.kmm)");
	$_ads=$_ads."\nAd2         Rules in Profile/adblock.txt  =  ";
	$_x=readfile(getfolder(ProfileFolder)."\\adblock.txt"); 
		$_x=substr($_x,0,30); $_x=gsub("\n","   ",$_x);
	$_ads=$_ads.($_x=="" ? "NOT FOUND" : "file exists (".$_x."...)");
	$_ads=$_ads."\nAd2         kmeleon.plugins.adblock.subscriptions  =  ";
	$_x=getpref(STRING,"kmeleon.plugins.adblock.subscriptions");
	$_ads=$_ads.($_x=="" ? "  ( -- )" : substr($_x,0,40)."...");
	$_ads=$_ads."\n";
	}
#------------
#   XPI-addons:  only reliable way to see if ACTIVE, check if this pref contains: ..\\em-id.xpi","e":true...
$_xpiState=getpref(STRING,"extensions.xpiState");
#
$_ads=$_ads."\nCheck active XPI-ADBLOCKERS: ABP,Latitude,Bluhell,uBlock,Silent,adguard:";
$_xpi="";
$_x=index($_xpiState,"\\{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}.xpi\",\"e\":true");
if ($_x>-1) $_xpi=$_xpi."\nADBLOCKER in about:addons  =  Adblock Plus";
else {
	# ABP included in PRO and other custom builds (Naruman74 jar) / Old ABP is jar not xpi / Or just macro?
	# ABP-Rules are in profile/adblockplus/patterns.ini + elemhide.css
	$_pref="extensions.adblockplus.enabled"; 
	getpref(BOOL,$_pref)==true ? $_xpi=$_xpi."\nAd3-ABP:  ".$_pref." = true without xpi (jar? Latitude? only macro?)":0;
	} 
$_x=index($_xpiState,"\\adblocklatitude@addons.palemoon.org.xpi\",\"e\":true");
if ($_x>-1) $_xpi=$_xpi."\nADBLOCKER in about:addons  =  Adblock Latitude (AdblockPlus-Prefs)";
#
##### Huh - plugin?? Where did I pick up that?  $_pref="kmeleon.plugins.bluhellfirewall.load"; 
$_x=index($_xpiState,"\\{6BB5760D-F97E-421B-AF5B-8457A90C3CED}.xpi\",\"e\":true");
if ($_x>-1) $_xpi=$_xpi."\nADBLOCKER in about:addons  =  Bluhell Firewall";
#
$_x=index($_xpiState,"\\uBlock0@raymondhill.net.xpi\",\"e\":true");
if ($_x>-1) $_xpi=$_xpi."\nADBLOCKER in about:addons  =  uBlock Origin";
#
$_x=index($_xpiState,"\\SilentBlock@schuzak.jp.xpi\",\"e\":true");
if ($_x>-1) $_xpi=$_xpi."\nADBLOCKER in about:addons  =  Silent Block";
#
$_x=index($_xpiState,"\\adguardadblocker@adguard.com.xpi\",\"e\":true");
if ($_x>-1) $_xpi=$_xpi."\nADBLOCKER in about:addons  =  ADGUARD";
#
$_xpi=="" ? $_ads=$_ads."  NONE" :  $_ads=$_ads.$_xpi;
}


_troubleshootprefs_getKMver{
if ((getpref(STRING,"platform.name")=="Goanna") or (index(getpref(STRING,"services.sync.syncKeyHelpURL"),"palemoon")>0)) $_eng="Goanna"; else $_eng="Gecko";
#
&_trbprfKMVER_readmeTitle;
&_trbprfKMVER_kmJs;
&_trbprfKMVER_versionIni;
&_trbprfKMVER_platformIni;
&_trbprfKMVER_applicIni;
&_trbprfKMVER_divPrefs;
#		
$_kmVer="<b>K-MELEON VERSION :</b>";
$_readme>"" ? $_kmVer=$_kmVer."\n".$_readme : 0;
$_kmVer=$_kmVer."\n".$_kmJs;
$_kmVer=$_kmVer."\n".$_vini;
# platform-prefs are new, created for KM-Goanna 
# (lock-prefs in omni.ja/goanna.js, but can be overwritten on about:config)
$_x=getpref(STRING,"platform.name")." ".getpref(STRING,"platform.version")." ".getpref(STRING,"platform.buildid");
$_x>"  " ? $_kmVer=$_kmVer."\nplatform-prefs:  ".$_x : $_kmVer=$_kmVer."   (Gecko engine?)";
$_kmVer=$_kmVer."\n".$_ptfIni;
$_appIni>"" ? $_kmVer=$_kmVer."\n".$_appIni : 0;
$_div>"" ? $_kmVer=$_kmVer."\n".$_div : 0;
#
$_kmVer=gsub("\n\n","\n",$_kmVer);
$_kmVer=gsub("\n\n","\n",$_kmVer);
$_kmVer=gsub("\n\n","\n",$_kmVer);
$_kmVer=gsub("\n\n","\n",$_kmVer);
}


_trbprfKMVER_divPrefs{
$_div="";
# old Moz prefs, obsolete since 2010, but if exist show anyway, can help (since 7X no vendors)
# KM1.8 adodupan:  no readme, and in km.js no vendors - except in override prefs. Instead this:   
# pref("general.useragent.appversion", "1.8.24");
# pref("general.useragent.buildID", "20140505182422");
#
$_x=getpref(STRING,"general.useragent.appName");
$_x>"" ? $_div=$_div."\ngeneral.useragent.appName = ".$_x : 0;
$_x=getpref(STRING,"general.useragent.appVersion");
$_x>"" ? $_div=$_div."\ngeneral.useragent.appVersion = ".$_x : 0;
$_x=getpref(STRING,"general.useragent.appversion");
$_x>"" ? $_div=$_div."\ngeneral.useragent.appversion = ".$_x : 0;
$_x=getpref(STRING,"general.useragent.buildID");
$_x>"" ? $_div=$_div."\ngeneral.useragent.buildID = ".$_x : 0;
$_x=getpref(STRING,"general.useragent.productComment");
$_x>"" ? $_div=$_div."\ngeneral.useragent.productComment = ".$_x : 0;
#
$_x=getfolder(RootFolder)."\\browser\\chrome\\browser\\content\\browser\\abouthome\\Carton.png";
$_x=readfile($_x);
$_x>"" ? $_div=$_div."\nContains file by NARUMAN (KM74x?) (KM/browser/.../abouthome/Carton.png)":0;
#
$_x=getfolder(RootFolder)."\\browser\\components\\nsKmeleonService.js";
$_x=readfile($_x);
index($_x,"adodupan")>-1 ? $_div=$_div."\nContains file by ADODUPAN (KM1.8/74x?) (name in KM/browser/.../nsKmeleonService.js)" : 0;
#
$_x=getpref(STRING,"kmeleon.display.title");
if (($_x=="K-Meleon") or ($_x=="")) 0; 
	else $_div=$_div."\nkmeleon.display.title = ".$_x;
$_div=$_div."\ngeneral.useragent.vendor + vendorSub  =  ";
	$_x=getpref(STRING,"general.useragent.vendor");
	$_x=="" ? $_x="( -- )" : 0;
	$_div=$_div.$_x." ".getpref(STRING,"general.useragent.vendorSub");
}

_trbprfKMVER_applicIni{
# Can be 1-2 pages! Looks like normal FF ini?  (in narumans 74+1; partly Fred's etc.) 
# But only the [App] part is interesting, first 5 lines enough
$_path=getfolder(RootFolder)."\\application.ini";
$_x=iniread("App","Vendor","",$_path);
$_x=="" ? $_path=getfolder(RootFolder)."\\browser\\application.ini" : 0;
$_x=iniread("App","Vendor","",$_path);
if ($_x>"") {
	$_appIni="application.ini:  ";
	$_x=="Mozilla" ? 0 : $_appIni=$_appIni." ".$_x;
	$_appIni=$_appIni." ".iniread("App","Name","",$_path);
	$_appIni=$_appIni." ".iniread("App","Version","",$_path);
	$_appIni=$_appIni." (".iniread("App","BuildID","",$_path).")";
	$_x=iniread("App","SourceRepository","",$_path);
	if ($_x>"") {
		$_appIni=$_appIni."\n.... SrcRepo=".$_x;
		$_appIni=gsub("http://","",$_appIni);
		$_appIni=gsub("https://","",$_appIni);
		}} 
else $_appIni="";
}

#	[Build]
#	BuildID=20140803202131
#	Milestone=24.7.0
#	SourceStamp=bce71a749a08
#	SourceRepository=http://hg.mozilla.org/releases/mozilla-esr24
#
#	[K-Meleon]
#	KM_Milestone=76.0RC_PRO
#	KM_Date=20170401

_trbprfKMVER_platformIni{
$_ptfIni=readfile(getfolder(RootFolder)."\\platform.ini");
$_ptfIni=="" ? $_ptfIni=readfile(getfolder(RootFolder)."\\browser\\platform.ini") : 0;
if ($_ptfIni>"") {
	&_trbprfKMVER_ptfSqueeze;
	&_trbprfKMVER_platformMS;
	$_ptfIni="platform.ini:  MS ".$_MS."   => in KM ".$_k."\n".$_ptf;
	# Was suggested, but not accepted. If existing it will show up as part of complete ptf ini.
	# $_k3=iniread("K-Meleon","KM_Milestone","", getfolder(RootFolder)."\\platform.ini");
}}		

_trbprfKMVER_ptfSqueeze{
$_ptf=$_ptfIni;
$_ptf=gsub("\n\n","\n",$_ptf);
$_ptf=gsub("\n"," / ",$_ptf);
$_ptf=gsub("] / ","] ",$_ptf);
$_ptf=gsub("[","\nplatform.ini: [",$_ptf);
$_ptf=sub("\nplatform.ini:","platform.ini:",$_ptf)."\n";
$_ptf=gsub("SourceRep","\nplatform.ini: SourceRep",$_ptf);
$_ptf=gsub("Repository","Rep",$_ptf);
$_ptf=gsub("[Build] Build","Build",$_ptf);
$_ptf=gsub("[K-Meleon] KM","KM",$_ptf);
$_ptf=gsub("Milestone=","v",$_ptf);
$_ptf=gsub("Source","Src",$_ptf);
$_ptf=gsub("SrcStamp=","src-",$_ptf);
$_ptf=gsub("http://","",$_ptf);
$_ptf=gsub("https://","",$_ptf);
$_ptf=gsub(" / \n","\n",$_ptf);
}

_trbprfKMVER_platformMS{
$_MS=iniread("Build","Milestone","", getfolder(RootFolder)."\\platform.ini");
#   example:  38.8.0esrpre
$_MS>="1.9.2.5pre" ? $_k="KM 1.7 alpha1" : 0;      
$_MS>="1.9.2.14pre" ? $_k="KM 1.7 alpha2" : 0;      
$_MS>="24" ? $_k="74 alpha" : 0;      # NO PLATFORM in zip
$_MS>="24.2" ? $_k="74 beta1" : 0;      
$_MS>="24.3" ? $_k="74 beta2" : 0; 		
$_MS>="24.6" ? $_k="74 (final1-2?)" : 0;
$_MS>="24.7" ? $_k="74 (final1-3?)" : 0;
$_MS>="25.0" ? $_k="74c+1 naru/74d+1 naru/1.8.0ado" : 0;	
$_MS>="31.0" ? $_k="74_31 (alpha)" : 0;
$_MS>="31.1" ? $_k="75.0 beta1.." : 0;
$_MS>="31.4" ? $_k="75.0 betaX" : 0;
$_MS>="31.5" ? $_k="75.0 RC2" : 0;
$_MS>="31.6" ? $_k="75.0 RC3 or final" : 0; 
$_MS>="31.8" ? $_k="75.1 RC or final" : 0;
$_MS>="38.0" ? $_k="76.0 alpha" : 0;
$_MS>="38.2" ? $_k="76.0 alpha/beta1" : 0;
$_MS>="38.3" ? $_k="76.0 beta2" : 0;
$_MS>="38.5" ? $_k="76.0 beta3" : 0;
$_MS>="38.8" ? $_k="76.0 RC or final" : 0;
$_MS>="45" ? $_k="77.x" : 0;
$_MS>="52" ? $_k="78.x" : 0;
$_MS>="59" ? $_k="79.x" : 0;
$_MS>="66" ? $_k="80.x" : 0;
substr($_MS,0,2)=="3." ? $_k="KM-Goanna" : 0;
substr($_MS,0,2)=="4." ? $_k="KM-Goanna?" : 0;
$_MS=="3.4.1" ? $_k="Goanna77 first Tests" : 0;
$_MS=="3.4.2" ? $_k="Goanna77 weekly3 (20180101) +newer" : 0;
}


#    version.ini  => convert hex to dec => add dots => usage known in... (gecko from platform.ini)
# 17104933 => 1050025 => 1.5.0025 => KM 1.5.3 + 1.5.4 RC or final +? 
# 17170436 => 1060004 => 1.6.0004 => KM ALL 1.6alphabeta + KM1.7alpha1/2
#           dto:         => KM CCFME0.097.0    same as 1.6 too!  no readme, only the vendor is CCFME but no macro plugin

# 33554436 => 2000004  => 2.0.0004  KM 74 B                             / 24.2.0.5118 / exe 2014-01-13)
#             dto:                                           KM 74 B2 (g-20140204005730 / 24.3.0 / exe 2014-02-08)
# 33554438 => 2000006 => 2.0.0006  KM 74 B3 (g-20140301194541 / 24.3.0 / exe 2014-03-08)
# 33554439 => 2000007 => 2.0.0007  KM 1.8b24 adodupan  (g-20140301194541 / 24.3.0)
#              dto:                                          KM 74.... Naruman
#              dto:                                          KM 74 B4 (g-20140529202211 / 24.6.0esrpre / exe 2014-05-01)
#              dto:                                          KM 74 b4 (g-20140612234948 / 30.0 / exe 2014-06-13)

# 33554450 => 2000012 => 2.0.0012 => KM 74 final +KM74+1 V7 naruman  (g-20140803202131 / 24.7.0)
# 33619975 => 2010007 => 2.1.0007 => KM 75.0 final  +Pro +?  (g-20150426163313 / 31.6.0) (new: Popupmenu etc ..9972 or earlier)
# 33685507 => 2020003 => 2.2.0003 => KM 75.1 alphabetaRC?
# 33685509 => 2020005 => 2.2.0005 => KM 75.1 final  +Pro +?  (g-20150815021428 / 31.8.0)
# 33751044 => 2030004 => 2.3.0004 => KM 76b3u1, 76b3u2
# 33751045 => 2030005 => 2.3.0005 => KM 76RC1 up1
# 33751046 => 2030006 => 2.3.0006 => KM 76RC1 up2  + Goanna first testbuilds
# 33751047 => 2030007 => 2.3.0007 => KM 76RC2
# 33751048 => 2030008 => 2.3.0008 => Goanna all "weeklies" since first Build 20171215, PTF 3.4.1, new prefs "platform.name+version=Goanna"+3.4.1

_trbprfKMVER_versionIni{
# $_i = iniread("Version","LastVersion","", getfolder(ProfileFolder)."\\version.ini");
$_i=$_trbprf_vini;
$_i3="???";
$_i=="17104933" ?  $_i3="1.5.3 + 1.5.4" : 0;
$_i=="17170436" ?  $_i3="1.6 + 1.7alpha1/2" : 0; 	# js all same too / sub in readme
$_i=="33554436" ?  $_i3="74 beta1/2" : 0;
$_i=="33554438" ?  $_i3="74 beta3" : 0;
$_i=="33554439" ?  $_i3="74 beta4 + Naruman + Adodupan 1.8b24" : 0;
$_i=="33554450" ?  $_i3="74 (final) + KM74+1 v7 (Naruman)" : 0;
$_i=="33619975" ?  $_i3="75.0 (final +?)" : 0;
$_i=="33685507" ?  $_i3="75.1 alpha/beta?" : 0;
$_i=="33685508" ?  $_i3="75.1 beta/RC?" : 0;
$_i=="33685509" ?  $_i3="75.1 (final)" : 0;
$_i=="33751042" ?  $_i3="76 beta1/up1/up2" : 0;	# beta2 ?
$_i=="33751044" ?  $_i3="76 beta3 up1/up2" : 0;
$_i=="33751045" ?  $_i3="76 RC1 up1" : 0;
$_i=="33751046" ?  $_i3="76 RC1 up2 + Goanna77 1st tests" : 0; 
$_i=="33751047" ?  $_i3="76 RC2" : 0;
$_i=="33751048" ?  $_i3="76 Goanna77 weekly1 (20171215) +newer" : 0;
#
# CONVERT cryptic number in version.ini to decimal, e.g. 17170436 => 1060004 => 1.6.0004
# "LastVersion" is sort of "exe-ID", contained in kmeleon.exe and writes it in profiles, checked at every startup for updates
# "The exe has to compare current version with LastVersion to update old profiles as needed and updates that number if different."
# http://kmeleonbrowser.org/forum/read.php?2,141328,142952#msg-142952
# http://kmeleonbrowser.org/forum/read.php?9,142878,142977#msg-142977
#
# "toString(16)" is hexadecimal conversion, e.g. 17170436 => 1060004
# result= take first digit as is, dot, next 2 digits without leading zero, dot, rest as is => 1.6.0004
$_trbprf_CODE_vini="var z=(".$_trbprf_vini.").toString(16); z=(z.substr(0,1)+'.'+parseInt(z.substr(1,2),0)+'.'+z.substr(3,7)); ";
#
# Macro complicated mess, because some KM-versions cannot "return" anything from injectJS:
if ($_i3=="???") {
	$_z2="var z2; x=z.substr(0,4); x < '2.0'?z2='1.X':0; ";
	$_z2=$_z2."x == '2.0.' ? z2='74':0; ";
	$_z2=$_z2."x == '2.1.' ? z2='75.0':0; ";
	$_z2=$_z2."x == '2.2.' ? z2='75.1':0; ";
	$_z2=$_z2."x == '2.3.' ? z2='76 or Goanna77-Test':0; ";
	$_z2=$_z2."x == '2.4.' ? z2='77-Goanna':0; ";
	$_z2=$_z2."x > '2.5' ? z2='77-99':0; ";
	$_z2=$_z2."z=z+'   => in KM '+z2+' +?'; ";
	$_trbprf_CODE_vini=$_trbprf_CODE_vini.$_z2;
	#
	#  $_trbprf_vini used 1x as TEXT and 1x as VAR, gets later replaced in innerHTML:
	$_vini="version.ini:  exe=".$_trbprf_vini." => $_trbprf_vini ";
}else 
	$_vini="version.ini:  exe=".$_trbprf_vini."=$_trbprf_vini   => in KM ".$_i3." +?";
}


_trbprfKMVER_readmeTitle{
# Detailed version in official KM 1.x in README.html SOURCE:   !--kmVer-->1.6.0 Beta<!--kmVer--> !</h1>
# KM1.X:  The version in readme was usually updated until KM1.7a2, incl. "Alpha" "Beta2" etc.
#       (while kmeleon.js mostly contained only numbers)
#        Except forks:  e.g. Freds have no "kmVer" in readme, only in title
# KM75-76:  EN:  <title>K-Meleon</title>   <h1>Welcome to K-Meleon !</h1>    RelNotes74, year 2014
# KM75-76:  FR:  <title>K-Meleon</title>   <h1>Bienvenue dans K-Meleon !</h1>    RelNotes74
# KM75-76:  DE:  <title>K-Meleon</title>   <!--kmVer-->75.0<!--kmVer-->    RelNotes75
# KM75-76:  ES:  <title>K-Meleon</title>   <!--kmVer-->75.0.0<!--kmVer-->    RelNotes75
# KM75-76:  RU:  <title>K-Meleon</title>   <h1>Добро пожаловать в K-Meleon 75!</h1>     Links geckoworld.ru
# KM75-76:  CN:  <title>K-Meleon</title>   <h1>???? K-Meleon ????????</h1>    RelNotes75+76
# KM74b4+1 Naruman :   <title>K-Meleon 1.8.0</title>   <!--kmVer-->1.8.0<!--kmVer-->
# KM74 / KM1.8 adodupan:  no readme file (and in km.js no vendors except in override prefs)
# Fred16:   <title>K-Meleon-16-F3628</title>     <h2>Welcome to</h2>\n<h1>K-Meleon-16-F3628 !</h1>
# Fred17:   <title>K-Meleon-F-17alpha-F3616</title>    <h2>Welcome to</h2>\n<h1>K-Meleon-17alpha-F3616 !</h1>
# CCFME:   no readme (but vendor in kmeleon.js)
#
$_readme=readfile(getfolder(RootFolder)."\\readme.html");
$_readme==""? $_readme=readfile(getfolder(RootFolder)."\\browser\\readme.html") : 0;
if ($_readme>"") {
	$_v="";
	$_readme=gsub("Welcome to ","",$_readme);
	$_x=index($_readme,"--kmVer-->");
	if ($_x>-1) {
		$_v=substr($_readme,$_x+10);
		$_v=substr($_v,0,index($_v,"<"));
		length($_v)<11 ? $_v="K-Meleon ".$_v : 0;
		}
	if ($_v=="") {
		$_x=index($_readme,"<title>");
		if ($_x>-1) {
			$_v=substr($_readme,$_x+7);
			$_v=substr($_v,0,index($_v,"<"));
			$_v=="K-Meleon" ? $_v="" : 0;
		}}
	if ($_v=="") {
		$_x=index($_readme,"<h1>");
		if ($_x>-1) {
			$_v=substr($_readme,$_x+4);
			$_v=substr($_v,0,index($_v,"<"));
			$_v=="K-Meleon" ? $_v="" : 0;
			$_v=="K-Meleon!" ? $_v="" : 0;
			$_v=="K-Meleon !" ? $_v="" : 0;
		}}
	$_v=substr($_v,0,50);
	&_trbprfKMVER_cleanName;
	$_v=="" ? $_v="  ( -- )" : 0;
	$_readme="readme.html EN:  ".$_v;
	}
else $_readme="readme.html EN:  (no file)";  
}


_trbprfKMVER_kmJs{
# Read original VENDOR prefs. Reading file instead of getpref to escape possible user changes (UA)
$_kmJs=readfile(getfolder(RootFolder)."\\defaults\\pref\\kmeleon.js");
$_kmJs==""? $_kmJs=readfile(getfolder(RootFolder)."\\browser\\defaults\\preferences\\kmeleon.js") :0;
if ($_kmJs>"") {
	$_v=""; $_vs=""; $_pro="";
	$_x=index($_kmJs,"useragent.vendor\"");
	if ($_x>-1) {
		$_v=substr($_kmJs,$_x+20);
		$_v=substr($_v,0,index($_v,"\""));
		$_x=index($_kmJs,"useragent.vendorSub");
		if ($_x>-1) {
			$_vs=substr($_kmJs,$_x+23);
			$_vs=substr($_vs,0,index($_vs,"\""));
	}}
	# KM Pro:   kmeleon.js contains "KM Pro" and "by rodocop" and window title "K-Meleon 76 Pro"
	$_x=index($_kmJs,"by rodocop");
	if ($_x>-1) { index($_kmJs,"KM Pro")>0 ? $_pro="PRO (rodocop)" : $_pro=""; }
	#
	$_kmJs=$_v.$_vs.$_pro;
	$_kmJs=="" ? 0 : $_kmJs="kmeleon.js:  ".$_v." ".$_vs." ".$_pro;
}}

_trbprfKMVER_cleanName{
$_k=sub("K-Meleon-","",$_k);
$_k=sub("K-meleon-","",$_k);
$_k=sub("K-Meleon","",$_k);
$_k=sub("K-meleon","",$_k);
$_k=sub("K-MELEON","",$_k);
$_k=sub(" !","",$_k);
}

_trbprf_getOSCPU{
$_oscpu=getpref(STRING,"general.oscpu.override");
if ($_oscpu>"") $_oscpu="oscpu.override = ".$_oscpu."  /  ";
$_oscpu=$_oscpu."navigator.oscpu = $NavOscpu ";
$_oscpu=$_oscpu."\n(OSCPU: NT 5.0=Win 2000; 5.1=XP; 5.2=XP64; 6.0=Vista; 6.1=Win7; 6.2=Win8; 6.3=Win8.1; 10=10)"; 
}

_trbprf_getLang{
$_lang1=getpref(STRING,"general.useragent.locale"); 
# ? $_lang2=getpref(STRING,"general.useragent.contentlocale"); 
$_lang3=getpref(STRING,"intl.accept_languages");
$_lang="Language: menu=".$_lang1." / pages=".$_lang3;
}

_trbprf_resetVars{
$_txt=""; $_x=""; $_v=""; $_vs=""; $_pro=""; $_MS=""; $_ua=""; $_t="";  
$_k=""; $_k2=""; $_k3=""; $_path=""; $_ads=""; $_xpiState=""; $_xpi="";
$_code=""; $_js=""; $_injJSret=""; $_injJSretxt=""; $_eng="";
$_i=""; $_i3=""; $_i4=""; $_z2=""; $_vini=""; $_appIni=""; $_ptfIni=""; 
$_src=""; $_readme=""; $_kmJs=""; $_kmVer=""; $_links="";
$_lang=""; $_lang1=""; $_lang2=""; $_oscpu=""; $_html="";
}

_troubleshootprefs_BuildMenu{
setmenu(KMDocs,macro,"&Troubleshooting INFO","troubleshootprefs","Troubleshooting");
}

#-------------------------------------------------
$OnInit=$OnInit."_troubleshootprefs_BuildMenu;";
$macroModules=$macroModules."troubleshootprefs;";

