General :  K-Meleon Forum
General discussion about K-Meleon. 
Value type for single digit number in registry
Posted by: JamesD
Date: June 16, 2012 02:22AM

I am trying to get a registry key with the either a zero (0) or a one (1) in the value. I would prefer a boolean value but I don't see that as a choice. Choices listed here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724884(v=vs.85).aspx

I tried with REG_DWORD but my value looks like this: 0x00000001 (1)

This line of macro code needs a true/false anwser.
menuchecked = readreg("HKCU\\Software\\KMELEON\\DNT_mgr\\Status");

I am looking for any suggestions on how to do this.

Options: ReplyQuote
Re: Value type for single digit number in registry
Posted by: JujuLand
Date: June 16, 2012 01:31PM

I think of a little tool which keep a parameter (path+key), and return 1 or 0.
It could be made using AutoIt, and could be called like this:

menuchecked = exec("tools\\dword.exe "."HKCU\\Software\\KMELEON\\DNT_mgr\\Status");

It ought to be easy to do, but I have now time now to do it. Next week, probably ...

A+


Mozilla/5.0 (x11; U; Linux x86_64; fr-FR; rv:24.0) Gecko/20140105 Ubuntu/12.04 K-Meleon/74.0

Web: http://jujuland.pagesperso-orange.fr/
Mail : alain [dot] aupeix [at] wanadoo [dot] fr




Options: ReplyQuote
Re: Value type for single digit number in registry
Posted by: adodupan
Date: June 16, 2012 02:26PM

If you need info what some external software writes to the registry, it's ok. But if you need a value related only to km, you should to use km prefs.

Anyway, the answer to your question:
menuchecked = readreg(HKCU,"Software\\KMELEON\\DNT_mgr\\Status") == 1;

In this example, Status is a DWORD value!!!
For text you should to use STRING value.

Regards

Options: ReplyQuote
Re: Value type for single digit number in registry
Posted by: JamesD
Date: June 16, 2012 07:12PM

Many thanks to JujuLand and adodupan. I had dropped a comma in my readreg statement.

I would prefer to use a pref but the answer also has to be read by Javascript. The proposed standard for 'do not track' is that the user can control whether to enable or disable the feature. The header for DNT is either a 1 or a 0.

Now all I have to do is get donottrack.js to read the registry item.

Options: ReplyQuote
Re: Value type for single digit number in registry
Posted by: adodupan
Date: June 17, 2012 02:40PM

JamesD, my suggestion is that you spend your time in something useful to you. There are few reasons for this suggestion. I suppose that you want play with code, but your plan is wrong and that will make your game hard.
First, javascript is a primary language of the browser, and in your game registry is absolutely unnecessary [look in chrome, all files are written in javascript, and some files use km prefs].
Also, suggestion about autoit tool, is useful as it is useful that you swim with a stone on your back [hello Alain :)].
Finally, best of all is that km does not need any donottrack.js, km already has these options. Also, my nnSurf just use these options.

Regards to all

Options: ReplyQuote
Re: Value type for single digit number in registry
Posted by: JamesD
Date: June 17, 2012 06:39PM

@ adodupan

I think you are right. I cannot discover what object to use to with the read statement when in donottrack.js.

I am seriously thinking of removing donottrack.js from my system. All the free stuff on the web is paid for by advertisers. If nobody sees their adds then they will see no value to providing the sites.

Options: ReplyQuote
Re: Value type for single digit number in registry
Posted by: adodupan
Date: June 17, 2012 07:45PM

JamesD, my suggestion is related exclusively to writing code, with the intention to spare you of your mistakes in the beginning. With your plan, fun writing would probably become a nightmare. I don't intend to change your attitude about privacy on the web.

Options: ReplyQuote
Re: Value type for single digit number in registry
Posted by: adodupan
Date: June 29, 2012 04:51PM

JamesD, i hope this example will help you to learn how to use kmprefs in javascript.
Green line is disabled code, blue is new or changed code.
root\components file donottrack.js

/*
donottrack.js
Jonathan Mayer - jmayer@stanford.edu

An XPCOM component that adds a Do Not Track header to all web requests.

v0.02 - 1/30/11
Updated header.

v0.01 - 10/26/10

Acknowledgement: Closely follows Mozilla's example XPCOM HTTP header modification component, https://developer.mozilla.org/en/Setting_HTTP_request_headers.
*/

// var DoNotTrackHeaderName = "DNT";
// var DoNotTrackHeaderValue = "1";


function DNTHTTPListener() { }

DNTHTTPListener.prototype =
{
observe: function(subject, topic, data)
{
if (topic == "http-on-modify-request")
{
var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);

var dntprefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch('navigator.');


// httpChannel.setRequestHeader(DoNotTrackHeaderName, DoNotTrackHeaderValue, false);


httpChannel.setRequestHeader("DNT", dntprefs.getIntPref("doNotTrack"), false);

return;
}

else if (topic == "app-startup" || topic == "profile-after-change")
{
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "http-on-modify-request", false);
return;
}
},

QueryInterface: function (iid)
{
if (iid.equals(Components.interfaces.nsIObserver) || iid.equals(Components.interfaces.nsISupports))
return this;
Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
return null;
},
};

var myModule =
{
registerSelf: function (componentManager, fileSpec, location, type)
{
var componentManagerI = componentManager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
componentManagerI.registerFactoryLocation(this.myCID, this.myName, this.myProgID, fileSpec, location, type);
var categoryManager = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
categoryManager.addCategoryEntry("app-startup", this.myName, this.myProgID, true, true);
},

getClassObject: function (compMgr, cid, iid)
{
return this.myFactory;
},

myCID: Components.ID("{b835ff9f-3fdd-47be-b216-d1e8c09252f5}"),

myProgID: "@donottrack.us/DNTHTTPListener;1",

myName: "Do Not Track HTTP Listener",

myFactory:
{
QueryInterface: function (aIID)
{
if (!aIID.equals(Components.interfaces.nsISupports) && !aIID.equals(Components.interfaces.nsIFactory))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
createInstance: function (outer, iid)
{
return new DNTHTTPListener();
}
},

canUnload: function(compMgr)
{
return true;
}
};

function NSGetModule(compMgr, fileSpec)
{
return myModule;
}


Macrolanguage, just for menu item.
root\macros file doNotTrack.kmm

$OnInit=$OnInit."_doNotTrack_01;";
$macroModules=$macroModules."doNotTrack;";

_doNotTrack_01{
setmenu("&Privacy",inline,_doNotTrack,_Privacy_Settings);
setmenu(_doNotTrack,macro,"I do not want to be tracked",_doNotTrack_02);
}
_doNotTrack_02{
macroinfo=_("Toggle Do Not Track");
menuchecked=getpref(INT,"navigator.doNotTrack")==1;
togglepref(INT,"navigator.doNotTrack",0,1);
}


It is necessary to create a preference INT 'navigator.doNotTrack', or in the
root\defaults\pref create a file doNotTrack.js

pref("navigator.doNotTrack",1);


Regards

Options: ReplyQuote
Re: Value type for single digit number in registry
Posted by: JamesD
Date: June 29, 2012 07:54PM

@ adodupan

I seem to not have follow instructions correctly, I guess. In any case, I am not getting a correct header.

I did as follows:
1. I made a new donottrack.js file by coping your updated code from your post. I put that in root\components folder.
2. I created donottrack.kmm file by copying your code. I put that in my user macro folder.
3. I created a donottrack.js file in root\defaults with the line to set the pref to 1.

The menu works, and my configuration file has the "navigator.doNotTrack" value as set by the last menu change. I have confirmed that the menu changes the value.

When I go here: http://browserspy.dk/donottrack.php
I get: No Do Not Track Header detected!

Did I misinterpret an instruction?

Options: ReplyQuote
Re: Value type for single digit number in registry
Posted by: adodupan
Date: June 29, 2012 08:17PM

If you already deleted two files (compreg.dat, xpti.dat) in the components directory, then everything should be fine. Test it on another website.

Options: ReplyQuote
Re: Value type for single digit number in registry
Posted by: JamesD
Date: June 30, 2012 12:57AM

@ adodupan

I stopped KM and deleted the two files. Restarted KM and observed no change. The website you suggested said my browser did not support do not track.

Options: ReplyQuote
Re: Value type for single digit number in registry
Posted by: adodupan
Date: June 30, 2012 04:04AM

Indeed, it's good to know that you are the creator of the latest km beta. Well, probably is registry better way for you :)
Maybe this package can help that you learn something. Good luck with coding.

Best regards

Options: ReplyQuote


K-Meleon forum is powered by Phorum.